diff --git a/cachier/__init__.py b/cachier/__init__.py index 1297cd7f..9b3a1549 100644 --- a/cachier/__init__.py +++ b/cachier/__init__.py @@ -1,13 +1,12 @@ +from ._version import * # noqa: F403 from .core import ( cachier, - set_default_params, - get_default_params, - enable_caching, disable_caching, + enable_caching, + get_default_params, + set_default_params, ) -from ._version import * # noqa: F403 - __all__ = [ "cachier", "set_default_params", diff --git a/cachier/_version.py b/cachier/_version.py index 34e0013f..7302258e 100644 --- a/cachier/_version.py +++ b/cachier/_version.py @@ -16,7 +16,7 @@ def _get_git_sha() -> str: - from subprocess import check_output, DEVNULL + from subprocess import DEVNULL, check_output out = check_output(["git", "rev-parse", "--short", "HEAD"], stderr=DEVNULL) # noqa: S603, S607 return out.decode("utf-8").strip() diff --git a/cachier/cores/mongo.py b/cachier/cores/mongo.py index dff393dd..d639e7b8 100644 --- a/cachier/cores/mongo.py +++ b/cachier/cores/mongo.py @@ -7,20 +7,19 @@ # http://www.opensource.org/licenses/MIT-license # Copyright (c) 2016, Shay Palachy -import sys # to make sure that pymongo was imported import pickle # for serialization of python objects -from contextlib import suppress -from datetime import datetime +import sys # to make sure that pymongo was imported import time # to sleep when waiting on Mongo cache\ import warnings # to warn if pymongo is missing +from contextlib import suppress +from datetime import datetime with suppress(ImportError): - from pymongo import IndexModel, ASCENDING - from pymongo.errors import OperationFailure from bson.binary import Binary # to save binary data to mongodb + from pymongo import ASCENDING, IndexModel + from pymongo.errors import OperationFailure -from .base import _BaseCore, RecalculationNeeded - +from .base import RecalculationNeeded, _BaseCore MONGO_SLEEP_DURATION_IN_SEC = 1 diff --git a/cachier/cores/pickle.py b/cachier/cores/pickle.py index 1339fb69..7d7385c7 100644 --- a/cachier/cores/pickle.py +++ b/cachier/cores/pickle.py @@ -8,16 +8,15 @@ # Copyright (c) 2016, Shay Palachy import os import pickle # for local caching +import threading from contextlib import suppress from datetime import datetime -import threading import portalocker # to lock on pickle cache IO -from watchdog.observers import Observer from watchdog.events import PatternMatchingEventHandler +from watchdog.observers import Observer # Alternative: https://github.com/WoLpH/portalocker - from .base import _BaseCore diff --git a/pyproject.toml b/pyproject.toml index 626127a2..82ade930 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ lint.select = [ "E", "W", # see: https://pypi.org/project/pycodestyle "F", # see: https://pypi.org/project/pyflakes -# "I", #see: https://pypi.org/project/isort/ + "I", #see: https://pypi.org/project/isort/ # "D", # see: https://pypi.org/project/pydocstyle # "N", # see: https://pypi.org/project/pep8-naming "S", # see: https://pypi.org/project/flake8-bandit diff --git a/setup.py b/setup.py index f86247da..21c65c6d 100644 --- a/setup.py +++ b/setup.py @@ -9,9 +9,10 @@ # Copyright (c) 2024, Jirka Borovec <***@gmail.com> import os.path -from importlib.util import spec_from_file_location, module_from_spec -from setuptools import setup, find_packages +from importlib.util import module_from_spec, spec_from_file_location + from pkg_resources import parse_requirements +from setuptools import find_packages, setup _PATH_HERE = os.path.dirname(__file__) diff --git a/tests/standalone_script.py b/tests/standalone_script.py index 17fbfa51..c413bfa3 100644 --- a/tests/standalone_script.py +++ b/tests/standalone_script.py @@ -1,6 +1,7 @@ -import cachier import time +import cachier + @cachier.cachier() def _takes_3_seconds(label, value): diff --git a/tests/test_memory_core.py b/tests/test_memory_core.py index cbbe9780..ad3995ac 100644 --- a/tests/test_memory_core.py +++ b/tests/test_memory_core.py @@ -7,8 +7,8 @@ from random import random from time import sleep, time -import pytest import pandas as pd +import pytest from cachier import cachier diff --git a/tests/test_mongo_core.py b/tests/test_mongo_core.py index 65b2339f..9c9bb69f 100644 --- a/tests/test_mongo_core.py +++ b/tests/test_mongo_core.py @@ -11,10 +11,10 @@ from time import sleep from urllib.parse import quote_plus -from birch import Birch # type: ignore[import-not-found] import pandas as pd import pymongo import pytest +from birch import Birch # type: ignore[import-not-found] from pymongo.errors import OperationFailure from pymongo.mongo_client import MongoClient from pymongo_inmemory import MongoClient as InMemoryMongoClient @@ -23,7 +23,6 @@ from cachier.cores.base import RecalculationNeeded from cachier.cores.mongo import _MongoCore - # === Enables testing vs a real MongoDB instance ===