From b11187ed49adf6635853cae2fc16829aa0ce7627 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Thu, 24 Oct 2024 07:29:47 +0200 Subject: [PATCH] Packaging: Use `versioningit` for maintaining the package version The Debian package builder has been saved to bin/mkdeb.py. --- .github/workflows/test.yaml | 4 +-- DEVELOP.md | 13 +++++++++- bin/mkdeb.py | 37 +++++++++++++++++++++++++++ docs/source/conf.py | 16 ++---------- pyproject.toml | 3 +++ responder/__init__.py | 11 ++++++++ responder/__version__.py | 1 - setup.py | 51 +++---------------------------------- 8 files changed, 70 insertions(+), 66 deletions(-) create mode 100644 bin/mkdeb.py delete mode 100644 responder/__version__.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9fa46b52..c32485d6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,10 +31,10 @@ jobs: ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - uses: yezz123/setup-uv@v4 - - run: uv pip install --editable '.[graphql,develop,test]' --system + - run: pip install --editable '.[graphql,develop,test]' - run: poe check diff --git a/DEVELOP.md b/DEVELOP.md index e8e381dd..ddea528f 100644 --- a/DEVELOP.md +++ b/DEVELOP.md @@ -1,6 +1,6 @@ # Development Sandbox -Set up a development sandbox. +## Setup Acquire sources and install project in editable mode. ```shell @@ -11,6 +11,8 @@ source .venv/bin/activate pip install --editable '.[graphql,develop,release,test]' ``` +## Operations + Invoke linter and software tests. ```shell poe check @@ -20,3 +22,12 @@ Format code. ```shell poe format ``` + + +## Release + +```shell +git tag v2.1.0 +git push --tags +poe release +``` diff --git a/bin/mkdeb.py b/bin/mkdeb.py new file mode 100644 index 00000000..d81b3478 --- /dev/null +++ b/bin/mkdeb.py @@ -0,0 +1,37 @@ +# ruff: noqa: S605, S607 +""" +Build and publish a .deb package. +https://pypi.python.org/pypi/stdeb/0.8.5#quickstart-2-just-tell-me-the-fastest-way-to-make-a-deb +""" + +import os +from shutil import rmtree + +here = os.path.abspath(os.path.dirname(__file__)) + + +def get_version(): + import responder + + return responder.__version__ + + +def run(): + version = get_version() + try: + print("Removing previous builds") + rmtree(os.path.join(here, "deb_dist")) + except FileNotFoundError: + pass + print("Creating Debian package manifest") + os.system( + "python setup.py --command-packages=stdeb.command sdist_dsc " + "-z artful --package3=pipenv --depends3=python3-virtualenv-clone" + ) + print("Building .deb") + os.chdir(f"deb_dist/pipenv-{version}") + os.system("dpkg-buildpackage -rfakeroot -uc -us") + + +if __name__ == "__main__": + run() diff --git a/docs/source/conf.py b/docs/source/conf.py index b0e35afc..2e3c4927 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -20,23 +20,11 @@ # -- Project information ----------------------------------------------------- project = "responder" -copyright = "2018, A Kenneth Reitz project" +copyright = "2018-2024, A Kenneth Reitz project" author = "Kenneth Reitz" # The short X.Y version -import os - -# Path hackery to get current version number. -here = os.path.abspath(os.path.dirname(__file__)) - -about = {} -with open(os.path.join(here, "..", "..", "responder", "__version__.py")) as f: - exec(f.read(), about) - -version = about["__version__"] -# The full version, including alpha/beta/rc tags -release = about["__version__"] - +version = "" # -- General configuration --------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index d36e57c2..25733ebf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,7 @@ build-backend = "setuptools.build_meta" requires = [ "setuptools>=42", # At least v42 of setuptools required. + "versioningit<3", ] [tool.ruff] @@ -69,6 +70,8 @@ markers = [ ] xfail_strict = true +[tool.versioningit] + [tool.poe.tasks] check = [ diff --git a/responder/__init__.py b/responder/__init__.py index c573a7ae..3e497c5a 100644 --- a/responder/__init__.py +++ b/responder/__init__.py @@ -1,9 +1,20 @@ +from importlib.metadata import PackageNotFoundError, version + from . import ext from .core import API, Request, Response +__appname__ = "responder" + +try: + __version__ = version(__appname__) +except PackageNotFoundError: # pragma: no cover + __version__ = "unknown" + __all__ = [ "API", "Request", "Response", "ext", + "__appname__", + "__version__", ] diff --git a/responder/__version__.py b/responder/__version__.py deleted file mode 100644 index 962c851b..00000000 --- a/responder/__version__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "2.0.7" diff --git a/setup.py b/setup.py index 19a78bf5..c03ddca5 100644 --- a/setup.py +++ b/setup.py @@ -2,25 +2,15 @@ # -*- coding: utf-8 -*- import codecs import os -import sys -from shutil import rmtree -from setuptools import Command, find_packages, setup +from setuptools import find_packages, setup +from versioningit import get_cmdclasses here = os.path.abspath(os.path.dirname(__file__)) with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as f: long_description = "\n" + f.read() -about = {} - -with open(os.path.join(here, "responder", "__version__.py")) as f: - exec(f.read(), about) - -if sys.argv[-1] == "publish": - os.system("python setup.py sdist bdist_wheel upload") - sys.exit() - required = [ "aiofiles", "apispec>=1.0.0b1", @@ -37,43 +27,8 @@ "whitenoise", ] - -# https://pypi.python.org/pypi/stdeb/0.8.5#quickstart-2-just-tell-me-the-fastest-way-to-make-a-deb -class DebCommand(Command): - """Support for setup.py deb""" - - description = "Build and publish the .deb package." - user_options = [] - - @staticmethod - def status(s): - """Prints things in bold.""" - print("\033[1m{0}\033[0m".format(s)) - - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - try: - self.status("Removing previous builds…") - rmtree(os.path.join(here, "deb_dist")) - except FileNotFoundError: - pass - self.status("Creating debian manifest…") - os.system( - "python setup.py --command-packages=stdeb.command sdist_dsc -z artful --package3=pipenv --depends3=python3-virtualenv-clone" - ) - self.status("Building .deb…") - os.chdir("deb_dist/pipenv-{0}".format(about["__version__"])) - os.system("dpkg-buildpackage -rfakeroot -uc -us") - - setup( name="responder", - version=about["__version__"], description="A familiar HTTP Service Framework for Python.", long_description=long_description, long_description_content_type="text/markdown", @@ -108,5 +63,5 @@ def run(self): "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: WWW/HTTP", ], - cmdclass={"deb": DebCommand}, + cmdclass=get_cmdclasses(), )