Skip to content

Commit f64a7ba

Browse files
committed
Packaging: Use versioningit for maintaining the package version
The Debian package builder has been saved to bin/mkdeb.py.
1 parent 985d72e commit f64a7ba

File tree

8 files changed

+71
-66
lines changed

8 files changed

+71
-66
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ jobs:
3131
]
3232

3333
steps:
34-
- uses: actions/checkout@v3
34+
- uses: actions/checkout@v4
3535
- uses: actions/setup-python@v5
3636
with:
3737
python-version: ${{ matrix.python-version }}
3838
- uses: yezz123/setup-uv@v4
39-
- run: uv pip install --editable '.[graphql,develop,test]' --system
39+
- run: pip install --editable '.[graphql,develop,test]'
4040
- run: poe check

DEVELOP.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Development Sandbox
22

3-
Set up a development sandbox.
3+
## Setup
44

55
Acquire sources and install project in editable mode.
66
```shell
@@ -11,6 +11,8 @@ source .venv/bin/activate
1111
pip install --editable '.[graphql,develop,release,test]'
1212
```
1313

14+
## Operations
15+
1416
Invoke linter and software tests.
1517
```shell
1618
poe check
@@ -20,3 +22,12 @@ Format code.
2022
```shell
2123
poe format
2224
```
25+
26+
27+
## Release
28+
29+
```shell
30+
git tag v2.1.0
31+
git push --tags
32+
poe release
33+
```

bin/mkdeb.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ruff: noqa: S605, S607
2+
"""
3+
Build and publish a .deb package.
4+
https://pypi.python.org/pypi/stdeb/0.8.5#quickstart-2-just-tell-me-the-fastest-way-to-make-a-deb
5+
"""
6+
7+
import os
8+
from shutil import rmtree
9+
10+
here = os.path.abspath(os.path.dirname(__file__))
11+
12+
13+
def get_version():
14+
import responder
15+
16+
return responder.__version__
17+
18+
19+
def run():
20+
version = get_version()
21+
try:
22+
print("Removing previous builds")
23+
rmtree(os.path.join(here, "deb_dist"))
24+
except FileNotFoundError:
25+
pass
26+
print("Creating Debian package manifest")
27+
os.system(
28+
"python setup.py --command-packages=stdeb.command sdist_dsc "
29+
"-z artful --package3=pipenv --depends3=python3-virtualenv-clone"
30+
)
31+
print("Building .deb")
32+
os.chdir(f"deb_dist/pipenv-{version}")
33+
os.system("dpkg-buildpackage -rfakeroot -uc -us")
34+
35+
36+
if __name__ == "__main__":
37+
run()

docs/source/conf.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,11 @@
2020
# -- Project information -----------------------------------------------------
2121

2222
project = "responder"
23-
copyright = "2018, A Kenneth Reitz project"
23+
copyright = "2018-2024, A Kenneth Reitz project"
2424
author = "Kenneth Reitz"
2525

2626
# The short X.Y version
27-
import os
28-
29-
# Path hackery to get current version number.
30-
here = os.path.abspath(os.path.dirname(__file__))
31-
32-
about = {}
33-
with open(os.path.join(here, "..", "..", "responder", "__version__.py")) as f:
34-
exec(f.read(), about)
35-
36-
version = about["__version__"]
37-
# The full version, including alpha/beta/rc tags
38-
release = about["__version__"]
39-
27+
version = ""
4028

4129
# -- General configuration ---------------------------------------------------
4230

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
build-backend = "setuptools.build_meta"
33
requires = [
44
"setuptools>=42", # At least v42 of setuptools required.
5+
"versioningit",
56
]
67

78
[tool.ruff]
89
line-length = 90
910

1011
extend-exclude = [
12+
"bin/mkdeb.py",
1113
"docs/source/conf.py",
1214
"setup.py",
1315
]
@@ -69,6 +71,8 @@ markers = [
6971
]
7072
xfail_strict = true
7173

74+
[tool.versioningit]
75+
7276
[tool.poe.tasks]
7377

7478
check = [

responder/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
from importlib.metadata import PackageNotFoundError, version
2+
13
from . import ext
24
from .core import API, Request, Response
35

6+
__appname__ = "responder"
7+
8+
try:
9+
__version__ = version(__appname__)
10+
except PackageNotFoundError: # pragma: no cover
11+
__version__ = "unknown"
12+
413
__all__ = [
514
"API",
615
"Request",
716
"Response",
817
"ext",
18+
"__appname__",
19+
"__version__",
920
]

responder/__version__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

setup.py

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,15 @@
22
# -*- coding: utf-8 -*-
33
import codecs
44
import os
5-
import sys
6-
from shutil import rmtree
75

8-
from setuptools import Command, find_packages, setup
6+
from setuptools import find_packages, setup
7+
from versioningit import get_cmdclasses
98

109
here = os.path.abspath(os.path.dirname(__file__))
1110

1211
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
1312
long_description = "\n" + f.read()
1413

15-
about = {}
16-
17-
with open(os.path.join(here, "responder", "__version__.py")) as f:
18-
exec(f.read(), about)
19-
20-
if sys.argv[-1] == "publish":
21-
os.system("python setup.py sdist bdist_wheel upload")
22-
sys.exit()
23-
2414
required = [
2515
"aiofiles",
2616
"apispec>=1.0.0b1",
@@ -37,43 +27,8 @@
3727
"whitenoise",
3828
]
3929

40-
41-
# https://pypi.python.org/pypi/stdeb/0.8.5#quickstart-2-just-tell-me-the-fastest-way-to-make-a-deb
42-
class DebCommand(Command):
43-
"""Support for setup.py deb"""
44-
45-
description = "Build and publish the .deb package."
46-
user_options = []
47-
48-
@staticmethod
49-
def status(s):
50-
"""Prints things in bold."""
51-
print("\033[1m{0}\033[0m".format(s))
52-
53-
def initialize_options(self):
54-
pass
55-
56-
def finalize_options(self):
57-
pass
58-
59-
def run(self):
60-
try:
61-
self.status("Removing previous builds…")
62-
rmtree(os.path.join(here, "deb_dist"))
63-
except FileNotFoundError:
64-
pass
65-
self.status("Creating debian manifest…")
66-
os.system(
67-
"python setup.py --command-packages=stdeb.command sdist_dsc -z artful --package3=pipenv --depends3=python3-virtualenv-clone"
68-
)
69-
self.status("Building .deb…")
70-
os.chdir("deb_dist/pipenv-{0}".format(about["__version__"]))
71-
os.system("dpkg-buildpackage -rfakeroot -uc -us")
72-
73-
7430
setup(
7531
name="responder",
76-
version=about["__version__"],
7732
description="A familiar HTTP Service Framework for Python.",
7833
long_description=long_description,
7934
long_description_content_type="text/markdown",
@@ -108,5 +63,5 @@ def run(self):
10863
"Programming Language :: Python :: Implementation :: PyPy",
10964
"Topic :: Internet :: WWW/HTTP",
11065
],
111-
cmdclass={"deb": DebCommand},
66+
cmdclass=get_cmdclasses(),
11267
)

0 commit comments

Comments
 (0)