Skip to content

Commit 48ea638

Browse files
committed
a few fixes for ruff and pycodestyle warnings
1 parent be0e410 commit 48ea638

File tree

5 files changed

+64
-40
lines changed

5 files changed

+64
-40
lines changed

bin/bump_version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"src/flint/test/test_all.py",
88
]
99

10+
1011
def main(version2=None, *filenames):
1112
"""Bump version number in files.
1213
@@ -40,6 +41,7 @@ def main(version2=None, *filenames):
4041
with open(filename, "w") as f:
4142
f.write(text.replace(version1, version2))
4243

44+
4345
if __name__ == "__main__":
4446
import sys
4547
main(*sys.argv[1:])

bin/rst_to_pxd.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@
4040
# recognize a function definition in rst
4141
is_func = re.compile(r"\.\.( )+(c:)?function( )*::")
4242
# rename types to avoid python -- c name collisions
43-
rename_types = [(re.compile(r"\bfmpz\b"),"fmpz_struct"),(re.compile(r"\bfmpq\b"), "fmpq_struct")]
43+
rename_types = [(re.compile(r"\bfmpz\b"), "fmpz_struct"), (re.compile(r"\bfmpq\b"), "fmpq_struct")]
4444
# comment out functions which use these types
4545
comment_types = re.compile(r"(\bFILE\b)|(\bmpz_t\b)|(\bmpq_t\b)")
4646
comment_set = set(["FILE", "mpz_t", "mpq_t"])
4747
c_types = set(["char", "short", "long", "int", "float", "double"])
4848
type_modifers = re.compile(r"\*|(\bconst\b)|(\bunsigned\b)|(\bsigned\b)")
4949
import_dict = {}
5050

51+
5152
def get_cython_struct_types(file):
5253
"""
5354
Extract cython types from a pxd file.
@@ -63,6 +64,7 @@ def get_cython_struct_types(file):
6364
ret.append(l.split()[-1])
6465
return ret
6566

67+
6668
def fill_import_dict(pyflintlibdir):
6769
"""
6870
Get a map from cython structs to the pxd that defines them
@@ -74,6 +76,7 @@ def fill_import_dict(pyflintlibdir):
7476
for t in get_cython_struct_types(pxd):
7577
import_dict[t] = f.name.split('.')[0]
7678

79+
7780
def undecorate(str):
7881
"""
7982
remove variable name, const, ``*``, etc. to just get types
@@ -83,16 +86,19 @@ def undecorate(str):
8386
ret = re.sub(type_modifers, '', ret)
8487
return ret.strip()
8588

89+
8690
def get_parameter_types(str):
8791
params = str[str.find("(") + 1 : str.rfind(")")].split(",")
8892
return [undecorate(s) for s in params]
8993

94+
9095
def clean_types(function):
9196
ret = function.strip()
9297
for old, new in rename_types:
9398
ret = re.sub(old, new, ret)
9499
return ret
95100

101+
96102
def get_functions(file):
97103
"""
98104
Get a list of functions from an rst file
@@ -102,7 +108,7 @@ def get_functions(file):
102108
for line in file:
103109
m = is_func.match(line)
104110
if m:
105-
ret.append( clean_types(line[m.end():]))
111+
ret.append(clean_types(line[m.end():]))
106112
in_list = True
107113
else:
108114
if in_list:
@@ -112,13 +118,15 @@ def get_functions(file):
112118
ret.append(clean_types(line))
113119
return ret
114120

121+
115122
def get_all_types(function_list):
116123
ret = set()
117124
for f in function_list:
118125
for t in get_parameter_types(f):
119126
ret.add(t)
120127
return ret
121128

129+
122130
def gen_imports(function_list):
123131
"""
124132
Generate import statements for known functions.
@@ -132,26 +140,27 @@ def gen_imports(function_list):
132140
imports[import_dict[t]].append(t)
133141
else:
134142
ret.add(t)
135-
for k,v in imports.items():
143+
for k, v in imports.items():
136144
types = ", ".join(v)
137145
print("from flint.flintlib." + k + " cimport " + types)
138146
return ret
139147

148+
140149
def generate_pxd_file(h_name, opts):
141150
fill_import_dict(opts.flint_lib_dir)
142-
l=[]
151+
l = []
143152
docdir = opts.arb_doc_dir
144-
name = h_name
153+
name = h_name
145154
if name[:6] == "flint/":
146155
docdir = opts.flint_doc_dir
147156
name = name[6:]
148157
with open(os.path.join(docdir, name + ".rst")) as f:
149158
l = get_functions(f)
150159
s = gen_imports(l)
151160
print()
152-
print ("\n# unimported types ", s - comment_set)
161+
print("\n# unimported types ", s - comment_set)
153162
print()
154-
print(r'cdef extern from "' + h_name +r'.h":')
163+
print(r'cdef extern from "' + h_name + r'.h":')
155164
for f in l:
156165
if comment_types.search(f):
157166
print(" # " + f)
@@ -181,4 +190,3 @@ def main(*args):
181190

182191
if __name__ == "__main__":
183192
main(*sys.argv[1:])
184-

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
compiler_directives['linetrace'] = True
6464

6565

66-
packages=[
66+
packages = [
6767
'flint',
6868
'flint.flintlib',
6969
'flint.flint_base',

0 commit comments

Comments
 (0)