Skip to content

Commit

Permalink
Packaging: Use versioningit for maintaining the package version
Browse files Browse the repository at this point in the history
The Debian package builder has been saved to bin/mkdeb.py.
  • Loading branch information
amotl committed Oct 24, 2024
1 parent 4c82049 commit b11187e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion DEVELOP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Development Sandbox

Set up a development sandbox.
## Setup

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

## Operations

Invoke linter and software tests.
```shell
poe check
Expand All @@ -20,3 +22,12 @@ Format code.
```shell
poe format
```


## Release

```shell
git tag v2.1.0
git push --tags
poe release
```
37 changes: 37 additions & 0 deletions bin/mkdeb.py
Original file line number Diff line number Diff line change
@@ -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()
16 changes: 2 additions & 14 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=42", # At least v42 of setuptools required.
"versioningit<3",
]

[tool.ruff]
Expand Down Expand Up @@ -69,6 +70,8 @@ markers = [
]
xfail_strict = true

[tool.versioningit]

[tool.poe.tasks]

check = [
Expand Down
11 changes: 11 additions & 0 deletions responder/__init__.py
Original file line number Diff line number Diff line change
@@ -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__",
]
1 change: 0 additions & 1 deletion responder/__version__.py

This file was deleted.

51 changes: 3 additions & 48 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -108,5 +63,5 @@ def run(self):
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Internet :: WWW/HTTP",
],
cmdclass={"deb": DebCommand},
cmdclass=get_cmdclasses(),
)

0 comments on commit b11187e

Please sign in to comment.