Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codepy/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def compile(self,

try:
return load_dynamic(mod_name, module_path)
except Exception:
except Exception: # noqa: BLE001
return link_extension(host_toolchain,
[host_object, device_object],
mod_name, **kwargs)
31 changes: 12 additions & 19 deletions codepy/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,33 +367,27 @@ def load_info(info_path: str) -> Any:
import pickle

try:
info_file = open(info_path, "rb")
except OSError as exc:
with open(info_path, "rb") as info_file:
return pickle.load(info_file)
except (OSError, EOFError) as exc:
raise _InvalidInfoFileError() from exc

try:
return pickle.load(info_file)
except EOFError as exc:
raise _InvalidInfoFileError() from exc
finally:
info_file.close()

def check_deps(deps: list[_Dependency]) -> bool:
for name, date, md5sum in deps:
for dep_name, date, md5sum in deps:
try:
possibly_updated = os.stat(name).st_mtime != date
possibly_updated = os.stat(dep_name).st_mtime != date
except OSError as e:
if debug_recompile:
logger.info(
"recompiling because dependency %s is "
"inaccessible (%s).", name, e)
"inaccessible (%s).", dep_name, e)
return False
else:
if possibly_updated and md5sum != get_file_md5sum(name):
if possibly_updated and md5sum != get_file_md5sum(dep_name):
if debug_recompile:
logger.info(
"recompiling because dependency %s was "
"updated.", name)
"updated.", dep_name)
return False

return True
Expand All @@ -402,18 +396,17 @@ def check_source(source_path: list[str]) -> bool:
valid = True
for i, path in enumerate(source_path):
source = source_string[i]

try:
src_f = open(path, "r" if not source_is_binary else "rb")
with open(path, "r" if not source_is_binary else "rb") as src_f:
valid = valid and src_f.read() == source
except OSError:
if debug_recompile:
logger.info(
"recompiling because cache directory does "
"not contain source file '%s'.", path)
return False

valid = valid and src_f.read() == source
src_f.close()

if not valid:
from warnings import warn
warn("hash collision in compiler cache", stacklevel=2)
Expand Down Expand Up @@ -473,7 +466,7 @@ def check_source(source_path: list[str]) -> bool:
dependencies=get_dep_structure(source_paths),
source_name=source_name), info_file)

return hex_checksum, mod_name, ext_file, True
return hex_checksum, mod_name, ext_file, True # noqa: TRY300
except Exception:
cleanup_m.error_clean_up()
raise
Expand Down
5 changes: 2 additions & 3 deletions codepy/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def update_config(fname: str) -> None:

with open(fname) as cf_file:
file_contents = cf_file.read()
exec(compile(file_contents, fname, "exec"), filevars)
exec(compile(file_contents, fname, "exec"), filevars) # noqa: S102

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

return libs
return getlist(aksetup, varname, [default])


def add_boost_python(toolchain: Toolchain) -> None:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ extend-ignore = [
"RUF067", # no code in __init__ *shrug*
]

[tool.ruff.lint.per-file-ignores]
"test/test_*.py" = ["S102"]
"doc/conf.py" = ["S102", "DTZ002"]

[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"
inline-quotes = "double"
Expand Down
Loading