From c729ddda569c077b70665892c3da8b7687b4a70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 21 Nov 2023 11:40:48 +0100 Subject: [PATCH 1/2] pep8 in various interfaces --- src/sage/interfaces/jmoldata.py | 26 +++++++++++++------------- src/sage/interfaces/latte.py | 24 ++++++++++++------------ src/sage/interfaces/lisp.py | 14 +++++++------- src/sage/interfaces/psage.py | 7 ++++--- src/sage/interfaces/scilab.py | 14 +++++++------- src/sage/interfaces/tachyon.py | 10 +++++----- 6 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/sage/interfaces/jmoldata.py b/src/sage/interfaces/jmoldata.py index a68e53e2d85..119ff1624ce 100644 --- a/src/sage/interfaces/jmoldata.py +++ b/src/sage/interfaces/jmoldata.py @@ -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 @@ -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. @@ -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: @@ -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) diff --git a/src/sage/interfaces/latte.py b/src/sage/interfaces/latte.py index 4c6d8e9f061..6923be55d53 100644 --- a/src/sage/interfaces/latte.py +++ b/src/sage/interfaces/latte.py @@ -1,15 +1,15 @@ r""" Interface to LattE integrale programs """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2017 Vincent Delecroix # # 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 @@ -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 @@ -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: @@ -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): diff --git a/src/sage/interfaces/lisp.py b/src/sage/interfaces/lisp.py index 3d6e620c4d1..fbe1481bcb6 100644 --- a/src/sage/interfaces/lisp.py +++ b/src/sage/interfaces/lisp.py @@ -50,7 +50,7 @@ # https://www.gnu.org/licenses/ # ########################################################################## - +import os import random from .expect import Expect, ExpectElement, ExpectFunction, FunctionElement, gc_disabled @@ -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) @@ -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): @@ -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) @@ -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): """ @@ -541,6 +541,7 @@ def is_LispElement(x): # An instance lisp = Lisp() + def reduce_load_Lisp(): """ EXAMPLES:: @@ -552,7 +553,6 @@ def reduce_load_Lisp(): return lisp -import os def lisp_console(): """ Spawn a new Lisp command-line session. diff --git a/src/sage/interfaces/psage.py b/src/sage/interfaces/psage.py index b64a0b15c5f..246ce1abcf7 100644 --- a/src/sage/interfaces/psage.py +++ b/src/sage/interfaces/psage.py @@ -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) @@ -136,7 +136,7 @@ def eval(self, x, strip=True, **kwds): return "<>" 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) @@ -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) @@ -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() diff --git a/src/sage/interfaces/scilab.py b/src/sage/interfaces/scilab.py index 54c28f55598..743f761ba2c 100644 --- a/src/sage/interfaces/scilab.py +++ b/src/sage/interfaces/scilab.py @@ -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. @@ -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): """ @@ -349,7 +349,7 @@ 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)) @@ -367,7 +367,7 @@ def get(self, var): """ s = self.eval('%s' % var) i = s.find('=') - return s[i+1:] + return s[i + 1:] def console(self): """ @@ -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): """ diff --git a/src/sage/interfaces/tachyon.py b/src/sage/interfaces/tachyon.py index 6053d2519e4..253253620bd 100644 --- a/src/sage/interfaces/tachyon.py +++ b/src/sage/interfaces/tachyon.py @@ -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 @@ -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) From 6c3fd7e4cfa906c249c9431e0c1f66f5573d2ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 22 Nov 2023 15:29:13 +0100 Subject: [PATCH 2/2] suggested detail --- src/sage/interfaces/scilab.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/interfaces/scilab.py b/src/sage/interfaces/scilab.py index 743f761ba2c..92017fa4a6b 100644 --- a/src/sage/interfaces/scilab.py +++ b/src/sage/interfaces/scilab.py @@ -356,7 +356,7 @@ def set(self, var, value): def get(self, var): """ - Get the value of the variable var. + Get the value of the variable ``var``. EXAMPLES:: @@ -365,9 +365,9 @@ 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:] + return s[i+1:] def console(self): """