Skip to content

Commit 697dffe

Browse files
committed
black and flake8
1 parent 54dd1e7 commit 697dffe

8 files changed

Lines changed: 77 additions & 18 deletions

File tree

.github/workflows/ci-test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222
matrix:
2323
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
2424
os: ["ubuntu-latest", "macOS-latest", "windows-latest"]
25-
backend: ["local", "db"]
25+
backend: ["local", "mongodb"]
2626
exclude:
2727
# ToDo: take if back when the connection become stable
2828
# or resolve using `InMemoryMongoClient`
29-
- { os: "macOS-latest", backend: "db" }
29+
- { os: "macOS-latest", backend: "mongodb" }
3030
env:
3131
CACHIER_TEST_HOST: "localhost"
3232
CACHIER_TEST_PORT: "27017"
@@ -53,21 +53,21 @@ jobs:
5353
run: pytest -m "not mongo" --cov=cachier --cov-report=term --cov-report=xml:cov.xml
5454

5555
- name: Setup docker (missing on MacOS)
56-
if: runner.os == 'macOS' && matrix.backend == 'db'
56+
if: runner.os == 'macOS' && matrix.backend == 'mongodb'
5757
run: |
5858
brew install docker
5959
colima start
6060
# For testcontainers to find the Colima socket
6161
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
6262
# ToDo: find a way to cache docker images
6363
#- name: Cache Container Images
64-
# if: matrix.backend == 'db'
64+
# if: matrix.backend == 'mongodb'
6565
# uses: borda/cache-container-images-action@b32a5e804cb39af3c3d134fc03ab76eac0bfcfa9
6666
# with:
6767
# prefix-key: "mongo-db"
6868
# images: mongo:latest
6969
- name: Start MongoDB in docker
70-
if: matrix.backend == 'db'
70+
if: matrix.backend == 'mongodb'
7171
run: |
7272
# start MongoDB in a container
7373
docker run -d -p ${{ env.CACHIER_TEST_PORT }}:27017 --name mongodb mongo:latest
@@ -76,7 +76,7 @@ jobs:
7676
# show running containers
7777
docker ps -a
7878
- name: Unit tests (DB)
79-
if: matrix.backend == 'db'
79+
if: matrix.backend == 'mongodb'
8080
run: pytest -m "mongo" --cov=cachier --cov-report=term --cov-report=xml:cov.xml
8181
- name: Speed eval
8282
run: python tests/speed_eval.py

pyproject.toml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# === Metadata & Build System ===
2+
13
[build-system]
24
requires = [
35
"setuptools",
@@ -43,12 +45,13 @@ dynamic = [
4345
]
4446
dependencies = [
4547
"portalocker>=2.3.2",
46-
"sqlalchemy>=2",
4748
"watchdog>=2.3.1",
4849
]
4950
urls.Source = "https://github.com/python-cachier/cachier"
5051
scripts.cachier = "cachier.__main__:cli"
5152

53+
# --- setuptools ---
54+
5255
[tool.setuptools]
5356
include-package-data = true
5457

@@ -64,6 +67,13 @@ include = [
6467
] # package names should match these glob patterns (["*"] by default)
6568
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
6669

70+
71+
# === Linting & Formatting ===
72+
73+
[tool.black]
74+
line-length = 79
75+
76+
# --- ruff ---
6777
[tool.ruff]
6878
target-version = "py38"
6979
line-length = 79
@@ -128,13 +138,55 @@ lint.unfixable = [
128138
# Unlike Flake8, default to a complexity level of 10.
129139
lint.mccabe.max-complexity = 10
130140

141+
# --- pylint ---
142+
[tool.pylint.'MAIN']
143+
ignore = ["CVS"]
144+
load-plugins = ["pylint.extensions.docparams"]
145+
146+
[tool.pylint.'FORMAT']
147+
good-names = ["x", "y", "X", "inter_X", "inter_y", "post_X", "post_y"]
148+
149+
[tool.pylint.'DESIGN']
150+
exclude-too-few-public-methods = [".+"]
151+
152+
[tool.pylint.'MESSAGES CONTROL']
153+
disable = ["R0911", "R0913", "R0903"]
154+
155+
# --- flake8 ---
156+
[tool.flake8]
157+
ignore = ["C901", "E203", "W503"]
158+
exclude = [
159+
".git",
160+
".github",
161+
".pytest_cache",
162+
".venv",
163+
".vim",
164+
".eggs",
165+
"__pycache__",
166+
"docs",
167+
"apidoc",
168+
"notebooks",
169+
"build",
170+
"dist",
171+
"versioneer.py",
172+
"pdpipe/_version.py",
173+
"*/_version.py",
174+
]
175+
max-complexity = 10
176+
max-line-length = 100
177+
178+
# --- docformatter ---
131179
[tool.docformatter]
132180
recursive = true
133181
# some docstring start with r"""
134182
wrap-summaries = 79
135183
wrap-descriptions = 79
136184
blank = true
137185

186+
187+
# === Testing ===
188+
189+
# --- pytest ---
138190
[tool.pytest.ini_options]
139191
testpaths = [
140192
"cachier",
@@ -158,6 +210,7 @@ markers = [
158210
"sql: test the SQL core",
159211
]
160212

213+
# --- coverage ---
161214
[tool.coverage.run]
162215
branch = true
163216
# dynamic_context = "test_function"

src/cachier/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ._version import * # noqa: F403
1+
from ._version import __version__
22
from .config import (
33
disable_caching,
44
enable_caching,
@@ -17,4 +17,5 @@
1717
"get_global_params",
1818
"enable_caching",
1919
"disable_caching",
20+
"__version__",
2021
]

src/cachier/_version.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
def _get_git_sha() -> str:
1919
from subprocess import DEVNULL, check_output
2020

21-
out = check_output(["git", "rev-parse", "--short", "HEAD"], stderr=DEVNULL) # noqa: S603, S607
21+
out = check_output(
22+
["git", "rev-parse", "--short", "HEAD"], stderr=DEVNULL
23+
) # noqa: S603, S607
2224
return out.decode("utf-8").strip()
2325

2426

src/cachier/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def cachier(
144144
object with writing permissions. If unset a local pickle cache is used
145145
instead.
146146
sql_engine : str, Engine, or callable, optional
147-
SQLAlchemy connection string, Engine, or callable returning an Engine. Used for the SQL backend.
147+
SQLAlchemy connection string, Engine, or callable returning an Engine.
148+
Used for the SQL backend.
148149
stale_after : datetime.timedelta, optional
149150
The time delta after which a cached result is considered stale. Calls
150151
made after the result goes stale will trigger a recalculation of the

src/cachier/cores/mongo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def get_entry_by_key(self, key: str) -> Tuple[str, Optional[CacheEntry]]:
7575
)
7676
if not res:
7777
return key, None
78-
val = pickle.loads(res["value"]) if "value" in res else None # noqa: S301
78+
val = (
79+
pickle.loads(res["value"]) if "value" in res else None
80+
) # noqa: S301
7981
entry = CacheEntry(
8082
value=val,
8183
time=res.get("time", None),

src/cachier/cores/sql.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
update,
2121
)
2222
from sqlalchemy.engine import Engine
23-
from sqlalchemy.exc import OperationalError
24-
from sqlalchemy.orm import Session, declarative_base, sessionmaker
23+
from sqlalchemy.orm import declarative_base, sessionmaker
2524

2625
from .._types import HashFunc
2726
from ..config import CacheEntry
@@ -71,7 +70,8 @@ def _resolve_engine(self, sql_engine):
7170
if callable(sql_engine):
7271
return sql_engine()
7372
raise ValueError(
74-
"sql_engine must be a SQLAlchemy Engine, connection string, or callable returning an Engine."
73+
"sql_engine must be a SQLAlchemy Engine, connection string, "
74+
"or callable returning an Engine."
7575
)
7676

7777
def set_func(self, func):
@@ -265,7 +265,7 @@ def clear_being_calculated(self) -> None:
265265
.where(
266266
and_(
267267
CacheTable.function_id == self._func_str,
268-
CacheTable.processing == True,
268+
CacheTable.processing,
269269
)
270270
)
271271
.values(processing=False)

tests/test_general.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ def fn_minus(a, b=2):
485485
assert cachier_(dummy_)(1) == expected, f"for {fn.__name__} wrapped"
486486

487487
dummy_ = functools.partial(fn, b=2)
488-
assert cachier_(dummy_)(1, b=2) == expected, (
489-
f"for {fn.__name__} wrapped"
490-
)
488+
assert (
489+
cachier_(dummy_)(1, b=2) == expected
490+
), f"for {fn.__name__} wrapped"
491491

492492
assert cachier_(fn)(1, 2) == expected, f"for {fn.__name__} inline"
493493
assert cachier_(fn)(a=1, b=2) == expected, f"for {fn.__name__} inline"

0 commit comments

Comments
 (0)