Skip to content

Commit

Permalink
gh-36746: pep8 in various interfaces
Browse files Browse the repository at this point in the history
pep8 clean in several files in `interfaces`

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.

URL: #36746
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
  • Loading branch information
Release Manager committed Dec 9, 2023
2 parents ca0624a + 6c3fd7e commit f66d283
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 51 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=cba1a107f45084e1884ca8a873504c70eec9c16c
md5=b61e77023581c8994c73313e867a6c26
cksum=615928275
sha1=8690edbf631421d19b51fa0383185e5b77e64cdc
md5=2e5ce85812f7884700bdacdd5f6ff76e
cksum=3867469893
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9b1e18ffc022a8ed0e7451ccf190a009ceb2d81c
4ae6301b8a3eef9d003f2275a186ebe64c44b257
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 ([email protected])
#
# 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 <[email protected]>
#
# 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
12 changes: 6 additions & 6 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 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 @@ -217,7 +217,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 @@ -324,8 +324,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 @@ -358,14 +358,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 @@ -374,7 +374,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 @@ -416,9 +416,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

0 comments on commit f66d283

Please sign in to comment.