diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6f23a2ee..32c5d849 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,7 +31,7 @@ repos: exclude: versioneer.py - repo: https://github.com/crate-ci/typos - rev: v1.16.26 + rev: typos-v0.10.21 hooks: - id: typos # empty to do not write fixes @@ -56,8 +56,15 @@ repos: # hooks: # - id: mypy + - repo: https://github.com/asottile/yesqa + rev: v1.5.0 + hooks: + - id: yesqa + additional_dependencies: + - flake8-bandit + - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.9 + rev: v0.2.1 hooks: # use black formatting - id: ruff-format diff --git a/cachier/_version.py b/cachier/_version.py index 3789cf10..f80ba2c5 100644 --- a/cachier/_version.py +++ b/cachier/_version.py @@ -21,8 +21,8 @@ def _get_git_sha() -> str: if not os.path.isdir(os.path.join(_PATH_ROOT, ".git")): return "" - out = subprocess.check_output( - ["git", "rev-parse", "HEAD"], # noqa: S603 S607 + out = subprocess.check_output( # noqa: S603, S607 + ["git", "rev-parse", "HEAD"], stderr=DEVNULL, ) sha = out.decode("utf-8").strip() diff --git a/cachier/core.py b/cachier/core.py index ae4f9b3e..f8600f85 100644 --- a/cachier/core.py +++ b/cachier/core.py @@ -275,7 +275,7 @@ def func_wrapper(*args, **kwds): func, _is_method=core.func_is_method, args=args, kwds=kwds ) - _print = lambda x: None # skipcq: FLK-E731 # noqa: E731 + _print = lambda x: None # noqa: E731 if verbose_cache: _print = print if ignore_cache or not _default_params["caching_enabled"]: @@ -291,7 +291,7 @@ def func_wrapper(*args, **kwds): _print("Cached result found.") local_stale_after = ( stale_after or _default_params["stale_after"] - ) # noqa: E501 + ) local_next_time = next_time or _default_params["next_time"] # noqa: E501 now = datetime.datetime.now() if now - entry["time"] <= local_stale_after: diff --git a/cachier/cores/pickle.py b/cachier/cores/pickle.py index 43867d8a..1339fb69 100644 --- a/cachier/cores/pickle.py +++ b/cachier/cores/pickle.py @@ -69,11 +69,11 @@ def _check_calculation(self): self.value = None self.observer.stop() - def on_created(self, event): # skipcq: PYL-W0613 + def on_created(self, event): """A Watchdog Event Handler method.""" self._check_calculation() # pragma: no cover - def on_modified(self, event): # skipcq: PYL-W0613 + def on_modified(self, event): """A Watchdog Event Handler method.""" self._check_calculation() @@ -97,7 +97,7 @@ def __init__( else: self.cache_dir = os.path.expanduser( self.default_params["cache_dir"] - ) # noqa: E501 + ) if separate_files is not None: self.separate_files = separate_files else: diff --git a/tests/test_mongo_core.py b/tests/test_mongo_core.py index 665c43be..65b2339f 100644 --- a/tests/test_mongo_core.py +++ b/tests/test_mongo_core.py @@ -221,13 +221,13 @@ def __init__(self, mongetter): self.create_indexes = self.collection.create_indexes self.find_one = self.collection.find_one - def delete_many(self, *args, **kwargs): # skipcq: PYL-R0201, PYL-W0613 + def delete_many(self, *args, **kwargs): pass - def update_many(self, *args, **kwargs): # skipcq: PYL-R0201, PYL-W0613 + def update_many(self, *args, **kwargs): pass - def update_one(self, *args, **kwargs): # skipcq: PYL-R0201, PYL-W0613 + def update_one(self, *args, **kwargs): raise OperationFailure(Exception()) @@ -277,12 +277,10 @@ def _stalled_func(): @pytest.mark.mongo def test_stalled_mong_db_core(monkeypatch): - def mock_get_entry( - self, args, kwargs - ): # skipcq: PYL-R0201, PYL-W0613 # noqa: E501 + def mock_get_entry(self, args, kwargs): return "key", {"being_calculated": True} - def mock_get_entry_by_key(self, key): # skipcq: PYL-R0201, PYL-W0613 + def mock_get_entry_by_key(self, key): return "key", None monkeypatch.setattr( @@ -300,7 +298,7 @@ def _stalled_func(): res = _stalled_func() assert res == 1 - def mock_get_entry_2(self, args, kwargs): # skipcq: PYL-W0613 + def mock_get_entry_2(self, args, kwargs): entry = { "being_calculated": True, "value": 1, diff --git a/tests/test_pickle_core.py b/tests/test_pickle_core.py index d480e018..75bde192 100644 --- a/tests/test_pickle_core.py +++ b/tests/test_pickle_core.py @@ -348,7 +348,7 @@ def _calls_bad_cache(bad_cache_func, res_queue, trash_cache, separate_files): cache_file.seek(0) cache_file.truncate() res_queue.put(res) - except Exception as exc: # skipcq: PYL-W0703 + except Exception as exc: res_queue.put(exc) @@ -440,7 +440,7 @@ def _calls_delete_cache(del_cache_func, res_queue, del_cache, separate_files): os.remove(_DEL_CACHE_FPATHS[separate_files]) # print(os.path.isfile(_DEL_CACHE_FPATH)) res_queue.put(res) - except Exception as exc: # skipcq: PYL-W0703 + except Exception as exc: # print('found') res_queue.put(exc)