diff --git a/codepy/cuda.py b/codepy/cuda.py index 82a6889..ca2806e 100644 --- a/codepy/cuda.py +++ b/codepy/cuda.py @@ -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) diff --git a/codepy/jit.py b/codepy/jit.py index 9370b60..7b4cc32 100644 --- a/codepy/jit.py +++ b/codepy/jit.py @@ -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 @@ -402,8 +396,10 @@ 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( @@ -411,9 +407,6 @@ def check_source(source_path: list[str]) -> bool: "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) @@ -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 diff --git a/codepy/libraries.py b/codepy/libraries.py index 2eef51f..d9bdc30 100644 --- a/codepy/libraries.py +++ b/codepy/libraries.py @@ -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__": @@ -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: diff --git a/pyproject.toml b/pyproject.toml index f3fdf0c..a415242 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"