Skip to content

Commit f66d283

Browse files
author
Release Manager
committed
gh-36746: pep8 in various interfaces
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
2 parents ca0624a + 6c3fd7e commit f66d283

File tree

8 files changed

+52
-51
lines changed

8 files changed

+52
-51
lines changed

build/pkgs/configure/checksums.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tarball=configure-VERSION.tar.gz
2-
sha1=cba1a107f45084e1884ca8a873504c70eec9c16c
3-
md5=b61e77023581c8994c73313e867a6c26
4-
cksum=615928275
2+
sha1=8690edbf631421d19b51fa0383185e5b77e64cdc
3+
md5=2e5ce85812f7884700bdacdd5f6ff76e
4+
cksum=3867469893
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9b1e18ffc022a8ed0e7451ccf190a009ceb2d81c
1+
4ae6301b8a3eef9d003f2275a186ebe64c44b257

src/sage/interfaces/jmoldata.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
- Jonathan Gutow (2012-03-21): initial version
1111
"""
1212

13-
#*******************************************************************************
13+
# ******************************************************************************
1414
# Copyright (C) 2012 Jonathan Gutow ([email protected])
1515
#
1616
# Distributed under the terms of the GNU General Public License (GPL)
1717
# as published by the Free Software Foundation; either version 2 of
1818
# the License, or (at your option) any later version.
19-
# http://www.gnu.org/licenses/
20-
#*******************************************************************************
19+
# https://www.gnu.org/licenses/
20+
# ******************************************************************************
2121

2222
from sage.structure.sage_object import SageObject
2323

@@ -72,12 +72,12 @@ def is_jvm_available(self):
7272
return java_version_number >= 7
7373

7474
def export_image(self,
75-
targetfile,
76-
datafile, #name (path) of data file Jmol can read or script file telling it what to read or load
77-
datafile_cmd='script', #"script" or "load"
78-
image_type='PNG', #PNG, JPG, GIF
79-
figsize=5,
80-
**kwds):
75+
targetfile,
76+
datafile, # name (path) of data file Jmol can read or script file telling it what to read or load
77+
datafile_cmd='script', # "script" or "load"
78+
image_type='PNG', # PNG, JPG, GIF
79+
figsize=5,
80+
**kwds):
8181
r"""
8282
This executes JmolData.jar to make an image file.
8383
@@ -170,7 +170,7 @@ def export_image(self,
170170
launchscript = launchscript + datafile
171171

172172
imagescript = 'write {} {!r}\n'.format(image_type, target_native)
173-
size_arg = "%sx%s" % (figsize*100,figsize*100)
173+
size_arg = "%sx%s" % (figsize * 100, figsize * 100)
174174
# Scratch file for Jmol errors
175175
scratchout = tmp_filename(ext=".txt")
176176
with open(scratchout, 'w') as jout:
@@ -179,9 +179,9 @@ def export_image(self,
179179
env['LC_ALL'] = 'C'
180180
env['LANG'] = 'C'
181181
subprocess.call(["java", "-Xmx512m", "-Djava.awt.headless=true",
182-
"-jar", jmolpath, "-iox", "-g", size_arg,
183-
"-J", launchscript, "-j", imagescript],
184-
stdout=jout, stderr=jout, env=env)
182+
"-jar", jmolpath, "-iox", "-g", size_arg,
183+
"-J", launchscript, "-j", imagescript],
184+
stdout=jout, stderr=jout, env=env)
185185
if not os.path.isfile(targetfile):
186186
raise RuntimeError(f"Jmol failed to create file {targetfile}: {Path(scratchout).read_text()}")
187187
os.unlink(scratchout)

src/sage/interfaces/latte.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
r"""
22
Interface to LattE integrale programs
33
"""
4-
#*****************************************************************************
4+
# ****************************************************************************
55
# Copyright (C) 2017 Vincent Delecroix <[email protected]>
66
#
77
# This program is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
99
# the Free Software Foundation, either version 2 of the License, or
1010
# (at your option) any later version.
11-
# http://www.gnu.org/licenses/
12-
#*****************************************************************************
11+
# https://www.gnu.org/licenses/
12+
# ****************************************************************************
1313

1414

1515
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,
134134
if 'redundancy_check' not in kwds:
135135
args.append('--redundancy-check=none')
136136

137-
for key,value in kwds.items():
137+
for key, value in kwds.items():
138138
if value is None or value is False:
139139
continue
140140

141-
key = key.replace('_','-')
141+
key = key.replace('_', '-')
142142
if value is True:
143-
args.append('--{}'.format(key))
143+
args.append(f'--{key}')
144144
else:
145-
args.append('--{}={}'.format(key, value))
145+
args.append(f'--{key}={value}')
146146

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

211211
if raw_output:
@@ -363,11 +363,11 @@ def integrate(arg, polynomial=None, algorithm='triangulate', raw_output=False, v
363363
if value is None or value is False:
364364
continue
365365

366-
key = key.replace('_','-')
366+
key = key.replace('_', '-')
367367
if value is True:
368-
args.append('--{}'.format(key))
368+
args.append(f'--{key}')
369369
else:
370-
args.append('--{}={}'.format(key, value))
370+
args.append(f'--{key}={value}')
371371

372372
if got_polynomial:
373373
if not isinstance(polynomial, str):

src/sage/interfaces/lisp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# https://www.gnu.org/licenses/
5151
#
5252
##########################################################################
53-
53+
import os
5454
import random
5555

5656
from .expect import Expect, ExpectElement, ExpectFunction, FunctionElement, gc_disabled
@@ -124,10 +124,10 @@ def eval(self, code, strip=True, **kwds):
124124
self._synchronize()
125125
code = str(code)
126126
code = code.strip()
127-
code = code.replace('\n',' ')
127+
code = code.replace('\n', ' ')
128128
x = []
129129
for L in code.split('\n'):
130-
if L != '':
130+
if L:
131131
try:
132132
s = self.__in_seq + 1
133133
M = self._eval_line(L, wait_for_prompt=self._prompt)
@@ -201,7 +201,7 @@ def _synchronize(self):
201201
self._start()
202202
E = self._expect
203203
r = random.randrange(2147483647)
204-
s = str(r+1)
204+
s = str(r + 1)
205205
cmd = "(+ 1 %s)" % r
206206
E.sendline(cmd)
207207
E.expect(s)
@@ -354,7 +354,7 @@ def _equality_symbol(self):
354354
NotImplementedError: ...
355355
"""
356356
raise NotImplementedError("We should never reach here in the Lisp interface. " +
357-
"Please report this as a bug.")
357+
"Please report this as a bug.")
358358

359359
def help(self, command):
360360
"""
@@ -541,6 +541,7 @@ def is_LispElement(x):
541541
# An instance
542542
lisp = Lisp()
543543

544+
544545
def reduce_load_Lisp():
545546
"""
546547
EXAMPLES::
@@ -552,7 +553,6 @@ def reduce_load_Lisp():
552553
return lisp
553554

554555

555-
import os
556556
def lisp_console():
557557
"""
558558
Spawn a new Lisp command-line session.

src/sage/interfaces/psage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151

5252
class PSage(Sage):
53-
def __init__(self, **kwds):
53+
def __init__(self, **kwds):
5454
if 'server' in kwds:
5555
raise NotImplementedError("PSage doesn't work on remote server yet.")
5656
Sage.__init__(self, **kwds)
@@ -136,7 +136,7 @@ def eval(self, x, strip=True, **kwds):
136136
return "<<currently executing code>>"
137137
if self._locked:
138138
self._locked = False
139-
#self._expect.expect('__unlocked__')
139+
# self._expect.expect('__unlocked__')
140140
self.expect().send('\n')
141141
self.expect().expect(self._prompt)
142142
self.expect().expect(self._prompt)
@@ -158,7 +158,7 @@ def set(self, var, value):
158158
"""
159159
Set the variable var to the given value.
160160
"""
161-
cmd = '%s=%s' % (var,value)
161+
cmd = '%s=%s' % (var, value)
162162
self._send_nowait(cmd)
163163
time.sleep(0.02)
164164

@@ -182,6 +182,7 @@ def _send_nowait(self, x):
182182
def _object_class(self):
183183
return PSageElement
184184

185+
185186
class PSageElement(SageElement):
186187
def is_locked(self):
187188
return self.parent().is_locked()

src/sage/interfaces/scilab.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class Scilab(Expect):
217217
505.
218218
"""
219219
def __init__(self, maxread=None, script_subdirectory=None,
220-
logfile=None, server=None,server_tmpdir=None,
220+
logfile=None, server=None, server_tmpdir=None,
221221
seed=None):
222222
"""
223223
Initializes the Scilab class.
@@ -324,8 +324,8 @@ def eval(self, command, *args, **kwds):
324324
sage: scilab.eval("d=44") # optional - scilab
325325
'd =\n \n 44.'
326326
"""
327-
s = Expect.eval(self, command, **kwds).replace("\x1b[?1l\x1b>","").strip()
328-
return s
327+
s = Expect.eval(self, command, **kwds)
328+
return s.replace("\x1b[?1l\x1b>", "").strip()
329329

330330
def whos(self, name=None, typ=None):
331331
"""
@@ -358,14 +358,14 @@ def set(self, var, value):
358358
sage: scilab.get('a') # optional - scilab
359359
'\n \n 123.'
360360
"""
361-
cmd = '%s=%s;' % (var,value)
361+
cmd = '%s=%s;' % (var, value)
362362
out = self.eval(cmd)
363363
if out.find("error") != -1:
364364
raise TypeError("Error executing code in Scilab\nCODE:\n\t%s\nScilab ERROR:\n\t%s" % (cmd, out))
365365

366366
def get(self, var):
367367
"""
368-
Get the value of the variable var.
368+
Get the value of the variable ``var``.
369369
370370
EXAMPLES::
371371
@@ -374,7 +374,7 @@ def get(self, var):
374374
sage: scilab.get('b') # optional - scilab
375375
'\n \n 124.'
376376
"""
377-
s = self.eval('%s' % var)
377+
s = self.eval(f'{var}')
378378
i = s.find('=')
379379
return s[i+1:]
380380

@@ -416,9 +416,9 @@ def sage2scilab_matrix_string(self, A):
416416
sage: A = M33([1,2,3,4,5,6,7,8,0]) # optional - scilab
417417
sage: scilab.sage2scilab_matrix_string(A) # optional - scilab
418418
'[1, 2, 3; 4, 5, 6; 7, 8, 0]'
419-
420419
"""
421-
return str(A.rows()).replace('), (', '; ').replace('(', '').replace(')','')
420+
s = str(A.rows())
421+
return s.replace('), (', '; ').replace('(', '').replace(')', '')
422422

423423
def _object_class(self):
424424
"""

src/sage/interfaces/tachyon.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,14 @@
673673
properly.
674674
"""
675675

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

685685
import os
686686
import re
@@ -804,8 +804,8 @@ def __call__(self, model, outfile='sage.png', verbose=1, extra_opts=''):
804804
if self.version() >= '0.99.2':
805805
# this keyword was changed in 0.99.2
806806
model = model.replace(
807-
" focallength ",
808-
" focaldist ")
807+
" focallength ",
808+
" focaldist ")
809809
modelfile = tmp_filename(ext='.dat')
810810
with open(modelfile, 'w') as file:
811811
file.write(model)

0 commit comments

Comments
 (0)