Skip to content

Commit fef00f6

Browse files
committed
Migrated setup.py -> pyproject.toml with Hatchling
Most of the changes to `pyproject.toml` were made by running `hatch new --init` (see https://hatch.pypa.io/latest/intro/#existing-project). Most of the changes to the other files were based on the changes made in django-commons/django-debug-toolbar#1690. ### `release.yml`: * `hatch version` is run instead of `hatchling version` (as is done in the PR mentioned above), as the latter crashes with the error: ``` hatchling.plugin.exceptions.UnknownPluginError: Unknown version source: vcs ``` Installing `hatch` takes considerably longer than just `hatchling`, but I think it's still acceptable. * Updated the `pypa/gh-action-pypi-publish` action from the sunset `master` branch to `release/v1`; see warning at https://github.com/jazzband/django-simple-history/actions/runs/9246937361. Also replaced the deprecated `repository_url` with `repository-url`; see https://github.com/pypa/gh-action-pypi-publish/blob/v1.8.14/action.yml#L15 ### `.pre-commit-config.yaml`: * Added some pre-commit hooks for formatting and validating `pyproject.toml` ### `MANIFEST.in`: * Removed `MANIFEST.in`, as the default `[tool.hatch.build.targets.sdist]` configuration (in `pyproject.toml`) includes all files not ignored through our `.gitignore`; see https://hatch.pypa.io/latest/plugins/builder/sdist/#default-file-selection ### `pyproject.toml`: * Didn't include the `license` field, as the docs recommend using a `License ::` classifier instead - see https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license * The classifier "Programming Language :: Python :: 3" was changed to "Programming Language :: Python :: 3 :: Only" by the `pyproject-fmt` pre-commit hook * Set `core-metadata-version = "2.2"` (copied from django-commons/django-debug-toolbar#1916) due to jazzband/help#360 * Didn't include the last 3 packages from the `packages` kwarg in `setup.py` when configuring `[tool.hatch.build.targets.wheel]`, since they don't make any difference in the generated wheel, as having just `simple_history` will include all its subpackages * As part of porting long_description's file concatenation from `setup.py`, `hatch-fancy-pypi-readme` was added to `requires` and configured to concatenate the same files - except with the first title of `README.rst` and the "Unreleased" section of `CHANGES.rst` removed (facilitated by the added "Start of PyPI readme" comments in those two files)
1 parent cf6848c commit fef00f6

File tree

9 files changed

+113
-72
lines changed

9 files changed

+113
-72
lines changed

.github/workflows/release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ jobs:
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install -U pip
27-
python -m pip install -U setuptools twine wheel
27+
python -m pip install -U hatch build twine
2828
2929
- name: Build package
3030
run: |
31-
python setup.py --version
32-
python setup.py sdist --format=gztar bdist_wheel
31+
hatch version
32+
python -m build
3333
twine check dist/*
3434
3535
- name: Upload packages to Jazzband
3636
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
37-
uses: pypa/gh-action-pypi-publish@master
37+
uses: pypa/gh-action-pypi-publish@release/v1
3838
with:
3939
user: jazzband
4040
password: ${{ secrets.JAZZBAND_RELEASE_KEY }}
41-
repository_url: https://jazzband.co/projects/django-simple-history/upload
41+
repository-url: https://jazzband.co/projects/django-simple-history/upload

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
python-version: ${{ matrix.python-version }}
6666
cache: 'pip'
6767
cache-dependency-path: |
68-
setup.py
68+
pyproject.toml
6969
tox.ini
7070
requirements/*.txt
7171

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,19 @@ repos:
3535
- id: check-docstring-first
3636
- id: check-executables-have-shebangs
3737
- id: check-merge-conflict
38+
- id: check-toml
3839
- id: debug-statements
3940
- id: detect-private-key
4041

42+
- repo: https://github.com/tox-dev/pyproject-fmt
43+
rev: 2.1.3
44+
hooks:
45+
- id: pyproject-fmt
46+
- repo: https://github.com/abravalheri/validate-pyproject
47+
rev: v0.18
48+
hooks:
49+
- id: validate-pyproject
50+
4151
- repo: https://github.com/adrienverge/yamllint
4252
rev: v1.35.1
4353
hooks:

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Unreleased
77
- Dropped support for Django 3.2, which reached end-of-life on 2024-04-01 (gh-1344)
88
- Removed the temporary requirement on ``asgiref>=3.6`` added in 3.5.0,
99
now that the minimum required Django version is 4.2 (gh-1344)
10+
- Migrated package building from using the deprecated ``setup.py`` to using
11+
``pyproject.toml`` (with Hatchling as build backend);
12+
``setup.py`` has consequently been removed (gh-1348)
13+
14+
.. Start of PyPI readme
1015
1116
3.6.0 (2024-05-26)
1217
------------------

MANIFEST.in

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

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
django-simple-history |pypi-version|
22
====================================
33

4+
.. Start of PyPI readme
5+
46
|jazzband| |build-status| |docs| |coverage| |maintainability| |code-style| |downloads|
57

68
.. |pypi-version| image:: https://img.shields.io/pypi/v/django-simple-history.svg

pyproject.toml

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,83 @@
1+
[build-system]
2+
build-backend = "hatchling.build"
3+
requires = [
4+
"hatch-fancy-pypi-readme",
5+
"hatch-vcs",
6+
"hatchling",
7+
]
8+
9+
[project]
10+
name = "django-simple-history"
11+
description = "Store model history and view/revert changes from admin site."
12+
maintainers = [
13+
{ name = "Trey Hunner" },
14+
]
15+
authors = [
16+
{ name = "Corey Bertram", email = "[email protected]" },
17+
]
18+
requires-python = ">=3.8"
19+
classifiers = [
20+
"Development Status :: 5 - Production/Stable",
21+
"Environment :: Web Environment",
22+
"Framework :: Django",
23+
"Framework :: Django :: 4.2",
24+
"Framework :: Django :: 5.0",
25+
"Intended Audience :: Developers",
26+
"License :: OSI Approved :: BSD License",
27+
"Programming Language :: Python",
28+
"Programming Language :: Python :: 3 :: Only",
29+
"Programming Language :: Python :: 3.8",
30+
"Programming Language :: Python :: 3.9",
31+
"Programming Language :: Python :: 3.10",
32+
"Programming Language :: Python :: 3.11",
33+
"Programming Language :: Python :: 3.12",
34+
# DEV: uncomment this when the `pyproject-fmt` pre-commit hook stops removing it
35+
#"Programming Language :: Python :: 3.13",
36+
]
37+
dynamic = [
38+
"readme",
39+
"version",
40+
]
41+
dependencies = [
42+
]
43+
urls.Changelog = "https://github.com/jazzband/django-simple-history/blob/master/CHANGES.rst"
44+
urls.Documentation = "https://django-simple-history.readthedocs.io/en/stable/"
45+
urls.Homepage = "https://github.com/jazzband/django-simple-history"
46+
urls.Source = "https://github.com/jazzband/django-simple-history"
47+
urls.Tracker = "https://github.com/jazzband/django-simple-history/issues"
48+
49+
[tool.hatch.version]
50+
source = "vcs"
51+
fallback-version = "0.0.0"
52+
53+
[tool.hatch.version.raw-options]
54+
version_scheme = "no-guess-dev"
55+
local_scheme = "node-and-date"
56+
57+
[tool.hatch.build.targets.wheel]
58+
# Jazzband's release process is limited to 2.2 metadata
59+
core-metadata-version = "2.2"
60+
packages = [
61+
"simple_history",
62+
]
63+
64+
[tool.hatch.build.targets.sdist]
65+
# Jazzband's release process is limited to 2.2 metadata
66+
core-metadata-version = "2.2"
67+
68+
[tool.hatch.metadata.hooks.fancy-pypi-readme]
69+
content-type = "text/x-rst"
70+
fragments = [
71+
{ path = "README.rst", start-after = ".. Start of PyPI readme\n\n" },
72+
{ text = "\n====\n\nChangelog\n=========\n\n" },
73+
{ path = "CHANGES.rst", start-after = ".. Start of PyPI readme\n\n" },
74+
]
75+
176
[tool.black]
277
line-length = 88
3-
target-version = ["py38"]
78+
target-version = [
79+
"py38",
80+
]
481

582
[tool.isort]
683
profile = "black"
@@ -9,12 +86,19 @@ py_version = "38"
986
[tool.coverage.run]
1087
parallel = true
1188
branch = true
12-
source = ["simple_history"]
89+
source = [
90+
"simple_history",
91+
]
1392

1493
[tool.coverage.paths]
15-
source = ["simple_history", ".tox/*/site-packages"]
94+
source = [
95+
"simple_history",
96+
".tox/*/site-packages",
97+
]
1698

1799
[tool.coverage.report]
18100
show_missing = true
19101
skip_covered = true
20-
omit = ["requirements/*"]
102+
omit = [
103+
"requirements/*",
104+
]

setup.py

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

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ commands =
5050
[testenv:format]
5151
deps = -rrequirements/lint.txt
5252
commands =
53-
isort docs simple_history runtests.py setup.py
54-
black docs simple_history runtests.py setup.py
53+
isort docs simple_history runtests.py
54+
black docs simple_history runtests.py
5555
flake8 simple_history
5656

5757
[testenv:lint]

0 commit comments

Comments
 (0)