Skip to content

Commit 7e40978

Browse files
committed
Modernize Python tooling
Move all configs into `pyproject.toml`, switch test/packaging to use Hatch, and do all the linting with Ruff. Fix issues that Ruff turned up, and annotate/ignore the pieces that it got wrong. Fixes: Issue #33
1 parent 7d9d430 commit 7e40978

File tree

22 files changed

+140
-136
lines changed

22 files changed

+140
-136
lines changed

.coveragerc

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/python-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
- name: Install dependencies
1919
run: |
2020
python -m pip install --upgrade pip
21-
pip install setuptools wheel twine
21+
pip install hatch twine
2222
- name: Build and publish
2323
env:
2424
TWINE_USERNAME: __token__
2525
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
2626
run: |
27-
python setup.py sdist bdist_wheel
27+
hatch build
2828
twine upload dist/*

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ jobs:
2828
- name: Install dependencies
2929
run: |
3030
python -m pip install --upgrade pip
31-
pip install -e .[tests]
31+
pip install hatch
3232
3333
- name: Lint
3434
run: |
35-
pycodestyle --ignore=E252,W503,W504 spinach tests
35+
hatch run pep8
3636
3737
- name: Test with pytest
3838
run: |
39-
pytest -v --cov=spinach tests/
39+
hatch run ci
4040
4141
- name: Coveralls
4242
uses: AndreMiras/coveralls-python-action@develop

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# _version is generated by setuptools_scm and requests not to be under a VCS
2+
spinach/_version.py
3+
4+
.hatch
15
.pyc
26
__pycache__
37

doc/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
sys.path.insert(0, os.path.abspath('..'))
2323

2424
import spinach
25+
from spinach import _version as spinach_version
2526

2627
# -- General configuration ------------------------------------------------
2728

@@ -66,9 +67,9 @@
6667
# built documents.
6768
#
6869
# The short X.Y version.
69-
version = spinach.__version__
70+
version = spinach_version.__version__
7071
# The full version, including alpha/beta/rc tags.
71-
release = spinach.__version__
72+
release = spinach_version.__version__
7273

7374
# The language for content autogenerated by Sphinx. Refer to documentation
7475
# for a list of supported languages.

pyproject.toml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
[build-system]
2+
requires = ["hatchling", "hatch-vcs"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "spinach"
7+
dynamic = ["version"]
8+
description = "Modern Redis task queue for Python 3"
9+
readme = "README.rst"
10+
license-files = { paths = ["LICENSE"] }
11+
requires-python = ">=3.8.0,<4.0.0"
12+
authors = [
13+
{ name = "Nicolas Le Manchet", email = "nicolas@lemanchet.fr" },
14+
]
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Developers",
18+
"Topic :: Software Development :: Libraries",
19+
"Topic :: System :: Distributed Computing",
20+
"License :: OSI Approved :: BSD License",
21+
"Natural Language :: English",
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3 :: Only",
24+
"Programming Language :: Python :: 3.8",
25+
"Programming Language :: Python :: 3.9",
26+
"Programming Language :: Python :: 3.10",
27+
"Programming Language :: Python :: 3.11",
28+
"Programming Language :: Python :: 3.12",
29+
]
30+
keywords = ["task", "queue", "jobs", "redis"]
31+
urls.Source = "https://github.com/NicolasLM/spinach"
32+
33+
dependencies = [
34+
"redis",
35+
"blinker"
36+
]
37+
38+
[project.optional-dependencies]
39+
tests = [
40+
"pytest",
41+
"pytest-cov",
42+
"pytest-threadleak",
43+
"ruff",
44+
"flask",
45+
"django"
46+
]
47+
48+
[tool.hatch.version]
49+
source = "vcs"
50+
51+
[tool.hatch.build.hooks.vcs]
52+
version-file = "spinach/_version.py"
53+
54+
[tool.hatch.build.targets.sdist]
55+
ignore-vcs = true
56+
include = ["/spinach", "/tests"]
57+
58+
[tool.hatch.build.targets.wheel]
59+
packages = ["spinach"]
60+
61+
[tool.hatch.build.targets.wheel.package-data]
62+
"spinach.brokers.redis_scripts" = [
63+
"deregister.lua",
64+
"enqueue_job.lua",
65+
"enqueue_jobs_from_dead_broker.lua",
66+
"flush.lua",
67+
"get_jobs_from_queue.lua",
68+
"move_future_jobs.lua",
69+
"register_periodic_tasks.lua",
70+
"remove_job_from_running.lua",
71+
"set_concurrency_keys.lua",
72+
]
73+
74+
[tool.hatch.envs.default]
75+
path = ".hatch"
76+
features = ["tests"]
77+
78+
scripts.pep8 = ["ruff spinach tests"]
79+
80+
scripts.py3 = [
81+
"docker-compose -f tests/docker-compose.yml up -d",
82+
"pytest tests {args}",
83+
"docker-compose -f tests/docker-compose.yml down",
84+
]
85+
86+
# A minimalist pytest runner for Github to use
87+
scripts.ci = ["pytest -v --cov=spinach tests {args}"]
88+
89+
[tool.ruff.lint]
90+
select = ["B", "C9", "D", "E", "F", "S", "W"]
91+
ignore = [
92+
"B018", # Useless expression (seems to have false-positive bugs)
93+
"S101", # Use of `assert` detected (conflicts with pytest)
94+
"D10", # Missing docstring in public function / module / etc.
95+
"D203", # 1 blank line required before class docstring
96+
"D205", # 1 blank line required between summary line and description
97+
"D213", # Multi-line docstring summary should start at the second line
98+
"D40", # First line of docstring complaints
99+
"D415", # First line should end with a period, question mark, or exclamation point
100+
]
101+
mccabe.max-complexity = 13
102+
103+
[tool.ruff.lint.per-file-ignores]
104+
# Aggregating symbols into a convenient location for import is good practice
105+
# for libraries, we don't care if they look unused
106+
"__init__.py" = ["F401"]
107+
108+
[tool.coverage.run]
109+
relative_files = true
110+
include = ["spinach/*"]
111+
omit = ["spinach/_version.py"]
112+
113+
[tool.pytest.ini_options]
114+
threadleak = true

pytest.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

spinach/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
from .brokers.memory import MemoryBroker
22
from .brokers.redis import RedisBroker
3-
from .const import VERSION
43
from .engine import Engine
54
from .task import Tasks, Batch, RetryException, AbortException
65
from .worker import ThreadWorkers, AsyncioWorkers
7-
8-
__version__ = VERSION

spinach/brokers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def wait_for_event(self):
5050
if self._something_happened.wait(timeout=timeout):
5151
self._something_happened.clear()
5252

53-
def start(self):
53+
def start(self): # noqa: B027
5454
"""Start the broker.
5555
5656
Only needed by arbiter.

0 commit comments

Comments
 (0)