Skip to content

Commit b38d957

Browse files
alexfiklinducer
authored andcommitted
fix: update to pass ruff 0.15.2
1 parent 14c8cbc commit b38d957

4 files changed

Lines changed: 19 additions & 23 deletions

File tree

codepy/cuda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def compile(self,
123123

124124
try:
125125
return load_dynamic(mod_name, module_path)
126-
except Exception:
126+
except Exception: # noqa: BLE001
127127
return link_extension(host_toolchain,
128128
[host_object, device_object],
129129
mod_name, **kwargs)

codepy/jit.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -367,33 +367,27 @@ def load_info(info_path: str) -> Any:
367367
import pickle
368368

369369
try:
370-
info_file = open(info_path, "rb")
371-
except OSError as exc:
370+
with open(info_path, "rb") as info_file:
371+
return pickle.load(info_file)
372+
except (OSError, EOFError) as exc:
372373
raise _InvalidInfoFileError() from exc
373374

374-
try:
375-
return pickle.load(info_file)
376-
except EOFError as exc:
377-
raise _InvalidInfoFileError() from exc
378-
finally:
379-
info_file.close()
380-
381375
def check_deps(deps: list[_Dependency]) -> bool:
382-
for name, date, md5sum in deps:
376+
for dep_name, date, md5sum in deps:
383377
try:
384-
possibly_updated = os.stat(name).st_mtime != date
378+
possibly_updated = os.stat(dep_name).st_mtime != date
385379
except OSError as e:
386380
if debug_recompile:
387381
logger.info(
388382
"recompiling because dependency %s is "
389-
"inaccessible (%s).", name, e)
383+
"inaccessible (%s).", dep_name, e)
390384
return False
391385
else:
392-
if possibly_updated and md5sum != get_file_md5sum(name):
386+
if possibly_updated and md5sum != get_file_md5sum(dep_name):
393387
if debug_recompile:
394388
logger.info(
395389
"recompiling because dependency %s was "
396-
"updated.", name)
390+
"updated.", dep_name)
397391
return False
398392

399393
return True
@@ -402,18 +396,17 @@ def check_source(source_path: list[str]) -> bool:
402396
valid = True
403397
for i, path in enumerate(source_path):
404398
source = source_string[i]
399+
405400
try:
406-
src_f = open(path, "r" if not source_is_binary else "rb")
401+
with open(path, "r" if not source_is_binary else "rb") as src_f:
402+
valid = valid and src_f.read() == source
407403
except OSError:
408404
if debug_recompile:
409405
logger.info(
410406
"recompiling because cache directory does "
411407
"not contain source file '%s'.", path)
412408
return False
413409

414-
valid = valid and src_f.read() == source
415-
src_f.close()
416-
417410
if not valid:
418411
from warnings import warn
419412
warn("hash collision in compiler cache", stacklevel=2)
@@ -473,7 +466,7 @@ def check_source(source_path: list[str]) -> bool:
473466
dependencies=get_dep_structure(source_paths),
474467
source_name=source_name), info_file)
475468

476-
return hex_checksum, mod_name, ext_file, True
469+
return hex_checksum, mod_name, ext_file, True # noqa: TRY300
477470
except Exception:
478471
cleanup_m.error_clean_up()
479472
raise

codepy/libraries.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def update_config(fname: str) -> None:
100100

101101
with open(fname) as cf_file:
102102
file_contents = cf_file.read()
103-
exec(compile(file_contents, fname, "exec"), filevars)
103+
exec(compile(file_contents, fname, "exec"), filevars) # noqa: S102
104104

105105
for key, value in filevars.items():
106106
if key != "__builtins__":
@@ -129,9 +129,8 @@ def get_boost_libname(basename: str, aksetup: Config) -> list[str]:
129129
import sys
130130
version = sys.version_info[:2]
131131
default = "boost_python{}{}".format(*version)
132-
libs = getlist(aksetup, varname, [default])
133132

134-
return libs
133+
return getlist(aksetup, varname, [default])
135134

136135

137136
def add_boost_python(toolchain: Toolchain) -> None:

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ extend-ignore = [
7272
"RUF067", # no code in __init__ *shrug*
7373
]
7474

75+
[tool.ruff.lint.per-file-ignores]
76+
"test/test_*.py" = ["S102"]
77+
"doc/conf.py" = ["S102", "DTZ002"]
78+
7579
[tool.ruff.lint.flake8-quotes]
7680
docstring-quotes = "double"
7781
inline-quotes = "double"

0 commit comments

Comments
 (0)