Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pep8 in various interfaces #36746

Merged
merged 2 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/sage/interfaces/jmoldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
- Jonathan Gutow (2012-03-21): initial version
"""

#*******************************************************************************
# ******************************************************************************
# Copyright (C) 2012 Jonathan Gutow (gutow@uwosh.edu)
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*******************************************************************************
# https://www.gnu.org/licenses/
# ******************************************************************************

from sage.structure.sage_object import SageObject

Expand Down Expand Up @@ -72,12 +72,12 @@ def is_jvm_available(self):
return java_version_number >= 7

def export_image(self,
targetfile,
datafile, #name (path) of data file Jmol can read or script file telling it what to read or load
datafile_cmd='script', #"script" or "load"
image_type='PNG', #PNG, JPG, GIF
figsize=5,
**kwds):
targetfile,
datafile, # name (path) of data file Jmol can read or script file telling it what to read or load
datafile_cmd='script', # "script" or "load"
image_type='PNG', # PNG, JPG, GIF
figsize=5,
**kwds):
r"""
This executes JmolData.jar to make an image file.

Expand Down Expand Up @@ -170,7 +170,7 @@ def export_image(self,
launchscript = launchscript + datafile

imagescript = 'write {} {!r}\n'.format(image_type, target_native)
size_arg = "%sx%s" % (figsize*100,figsize*100)
size_arg = "%sx%s" % (figsize * 100, figsize * 100)
# Scratch file for Jmol errors
scratchout = tmp_filename(ext=".txt")
with open(scratchout, 'w') as jout:
Expand All @@ -179,9 +179,9 @@ def export_image(self,
env['LC_ALL'] = 'C'
env['LANG'] = 'C'
subprocess.call(["java", "-Xmx512m", "-Djava.awt.headless=true",
"-jar", jmolpath, "-iox", "-g", size_arg,
"-J", launchscript, "-j", imagescript],
stdout=jout, stderr=jout, env=env)
"-jar", jmolpath, "-iox", "-g", size_arg,
"-J", launchscript, "-j", imagescript],
stdout=jout, stderr=jout, env=env)
if not os.path.isfile(targetfile):
raise RuntimeError(f"Jmol failed to create file {targetfile}: {Path(scratchout).read_text()}")
os.unlink(scratchout)
24 changes: 12 additions & 12 deletions src/sage/interfaces/latte.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
r"""
Interface to LattE integrale programs
"""
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2017 Vincent Delecroix <vincent.delecroix@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************


from sage.cpython.string import str_to_bytes, bytes_to_str
Expand Down Expand Up @@ -134,15 +134,15 @@ def count(arg, ehrhart_polynomial=False, multivariate_generating_function=False,
if 'redundancy_check' not in kwds:
args.append('--redundancy-check=none')

for key,value in kwds.items():
for key, value in kwds.items():
if value is None or value is False:
continue

key = key.replace('_','-')
key = key.replace('_', '-')
if value is True:
args.append('--{}'.format(key))
args.append(f'--{key}')
else:
args.append('--{}={}'.format(key, value))
args.append(f'--{key}={value}')

if multivariate_generating_function:
from sage.misc.temporary_file import tmp_filename
Expand Down Expand Up @@ -200,12 +200,12 @@ def count(arg, ehrhart_polynomial=False, multivariate_generating_function=False,
else:
raise NotImplementedError("there is no Sage object to handle multivariate series from LattE, use raw_output=True")
else:
if ans: # Sometimes (when LattE's preproc does the work), no output appears on stdout.
if ans: # Sometimes (when LattE's preproc does the work), no output appears on stdout.
ans = ans.splitlines()[-1]
if not ans:
# opening a file is slow (30e-6s), so we read the file
# numOfLatticePoints only in case of a IndexError above
with open(tempd.name+'/numOfLatticePoints', 'r') as f:
with open(tempd.name + '/numOfLatticePoints', 'r') as f:
ans = f.read()

if raw_output:
Expand Down Expand Up @@ -363,11 +363,11 @@ def integrate(arg, polynomial=None, algorithm='triangulate', raw_output=False, v
if value is None or value is False:
continue

key = key.replace('_','-')
key = key.replace('_', '-')
if value is True:
args.append('--{}'.format(key))
args.append(f'--{key}')
else:
args.append('--{}={}'.format(key, value))
args.append(f'--{key}={value}')

if got_polynomial:
if not isinstance(polynomial, str):
Expand Down
14 changes: 7 additions & 7 deletions src/sage/interfaces/lisp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# https://www.gnu.org/licenses/
#
##########################################################################

import os
import random

from .expect import Expect, ExpectElement, ExpectFunction, FunctionElement, gc_disabled
Expand Down Expand Up @@ -124,10 +124,10 @@ def eval(self, code, strip=True, **kwds):
self._synchronize()
code = str(code)
code = code.strip()
code = code.replace('\n',' ')
code = code.replace('\n', ' ')
x = []
for L in code.split('\n'):
if L != '':
if L:
try:
s = self.__in_seq + 1
M = self._eval_line(L, wait_for_prompt=self._prompt)
Expand All @@ -136,7 +136,7 @@ def eval(self, code, strip=True, **kwds):
x.append(M.strip())
self.__in_seq = s
except TypeError as s:
return 'error evaluating "%s":\n%s' % (code,s)
return 'error evaluating "%s":\n%s' % (code, s)
return '\n'.join(x)

def _an_element_impl(self):
Expand Down Expand Up @@ -201,7 +201,7 @@ def _synchronize(self):
self._start()
E = self._expect
r = random.randrange(2147483647)
s = str(r+1)
s = str(r + 1)
cmd = "(+ 1 %s)" % r
E.sendline(cmd)
E.expect(s)
Expand Down Expand Up @@ -354,7 +354,7 @@ def _equality_symbol(self):
NotImplementedError: ...
"""
raise NotImplementedError("We should never reach here in the Lisp interface. " +
"Please report this as a bug.")
"Please report this as a bug.")

def help(self, command):
"""
Expand Down Expand Up @@ -541,6 +541,7 @@ def is_LispElement(x):
# An instance
lisp = Lisp()


def reduce_load_Lisp():
"""
EXAMPLES::
Expand All @@ -552,7 +553,6 @@ def reduce_load_Lisp():
return lisp


import os
def lisp_console():
"""
Spawn a new Lisp command-line session.
Expand Down
7 changes: 4 additions & 3 deletions src/sage/interfaces/psage.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@


class PSage(Sage):
def __init__(self, **kwds):
def __init__(self, **kwds):
if 'server' in kwds:
raise NotImplementedError("PSage doesn't work on remote server yet.")
Sage.__init__(self, **kwds)
Expand Down Expand Up @@ -136,7 +136,7 @@ def eval(self, x, strip=True, **kwds):
return "<<currently executing code>>"
if self._locked:
self._locked = False
#self._expect.expect('__unlocked__')
# self._expect.expect('__unlocked__')
self.expect().send('\n')
self.expect().expect(self._prompt)
self.expect().expect(self._prompt)
Expand All @@ -158,7 +158,7 @@ def set(self, var, value):
"""
Set the variable var to the given value.
"""
cmd = '%s=%s' % (var,value)
cmd = '%s=%s' % (var, value)
self._send_nowait(cmd)
time.sleep(0.02)

Expand All @@ -182,6 +182,7 @@ def _send_nowait(self, x):
def _object_class(self):
return PSageElement


class PSageElement(SageElement):
def is_locked(self):
return self.parent().is_locked()
16 changes: 8 additions & 8 deletions src/sage/interfaces/scilab.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Scilab(Expect):
505.
"""
def __init__(self, maxread=None, script_subdirectory=None,
logfile=None, server=None,server_tmpdir=None,
logfile=None, server=None, server_tmpdir=None,
seed=None):
"""
Initializes the Scilab class.
Expand Down Expand Up @@ -315,8 +315,8 @@ def eval(self, command, *args, **kwds):
sage: scilab.eval("d=44") # optional - scilab
'd =\n \n 44.'
"""
s = Expect.eval(self, command, **kwds).replace("\x1b[?1l\x1b>","").strip()
return s
s = Expect.eval(self, command, **kwds)
return s.replace("\x1b[?1l\x1b>", "").strip()

def whos(self, name=None, typ=None):
"""
Expand Down Expand Up @@ -349,14 +349,14 @@ def set(self, var, value):
sage: scilab.get('a') # optional - scilab
'\n \n 123.'
"""
cmd = '%s=%s;' % (var,value)
cmd = '%s=%s;' % (var, value)
out = self.eval(cmd)
if out.find("error") != -1:
raise TypeError("Error executing code in Scilab\nCODE:\n\t%s\nScilab ERROR:\n\t%s" % (cmd, out))

def get(self, var):
"""
Get the value of the variable var.
Get the value of the variable ``var``.

EXAMPLES::

Expand All @@ -365,7 +365,7 @@ def get(self, var):
sage: scilab.get('b') # optional - scilab
'\n \n 124.'
"""
s = self.eval('%s' % var)
s = self.eval(f'{var}')
i = s.find('=')
return s[i+1:]

Expand Down Expand Up @@ -407,9 +407,9 @@ def sage2scilab_matrix_string(self, A):
sage: A = M33([1,2,3,4,5,6,7,8,0]) # optional - scilab
sage: scilab.sage2scilab_matrix_string(A) # optional - scilab
'[1, 2, 3; 4, 5, 6; 7, 8, 0]'

"""
return str(A.rows()).replace('), (', '; ').replace('(', '').replace(')','')
s = str(A.rows())
return s.replace('), (', '; ').replace('(', '').replace(')', '')

def _object_class(self):
"""
Expand Down
10 changes: 5 additions & 5 deletions src/sage/interfaces/tachyon.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,14 @@
properly.
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2006 John E. Stone
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

import os
import re
Expand Down Expand Up @@ -804,8 +804,8 @@ def __call__(self, model, outfile='sage.png', verbose=1, extra_opts=''):
if self.version() >= '0.99.2':
# this keyword was changed in 0.99.2
model = model.replace(
" focallength ",
" focaldist ")
" focallength ",
" focaldist ")
modelfile = tmp_filename(ext='.dat')
with open(modelfile, 'w') as file:
file.write(model)
Expand Down
Loading