Skip to content

Commit 49dfdea

Browse files
committed
feat: migrate from setup.py/setuptools to pyproject.toml/hatch
1 parent cb4f922 commit 49dfdea

File tree

8 files changed

+93
-83
lines changed

8 files changed

+93
-83
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ jobs:
2727
with:
2828
python-version: 3.9
2929
cache: "pip"
30-
- name: Upgrade pip and setuptools
31-
# https://pypi.org/project/pip/
32-
# https://pypi.org/project/setuptools/
33-
# https://pypi.org/project/wheel/
34-
run: python -m pip install --upgrade pip setuptools==65.6.3 wheel
30+
- name: Install Hatch
31+
uses: pypa/hatch@install
3532
- name: Print info about the current python installation
3633
run: make ci-info
3734
- name: Install requirements

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
python-version: ['3.7', '3.12']
12+
python-version: ['3.9', '3.12']
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Set up Python ${{ matrix.python-version }}
@@ -21,7 +21,7 @@ jobs:
2121
- name: Install dependencies
2222
run: |
2323
if [ "${{ matrix.python-version }}" = "3.7" ]; then
24-
pip install "tutor==15.0.0" pylint black mypy types-setuptools
24+
pip install "tutor==15.0.0" pylint black mypy
2525
else
2626
pip install -U tutor
2727
fi

.hatch_build.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# https://hatch.pypa.io/latest/how-to/config/dynamic-metadata/
2+
import os
3+
import typing as t
4+
5+
from hatchling.metadata.plugin.interface import MetadataHookInterface
6+
7+
HERE = os.path.dirname(__file__)
8+
9+
10+
class MetaDataHook(MetadataHookInterface):
11+
def update(self, metadata: dict[str, t.Any]) -> None:
12+
about = load_about()
13+
metadata["version"] = about["__version__"]
14+
15+
16+
def load_about() -> dict[str, str]:
17+
about: dict[str, str] = {}
18+
with open(
19+
os.path.join(HERE, "tutorwordpress", "__about__.py"), "rt", encoding="utf-8"
20+
) as f:
21+
exec(f.read(), about) # pylint: disable=exec-used
22+
return about

MANIFEST.in

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

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ ci-info: ## Print info about environment
3434
bootstrap-dev: ## Install dev requirements
3535
pip install .[dev]
3636

37-
build-pythonpackage: ## Build Python package ready to upload to pypi
38-
python setup.py sdist
39-
for f in dist/tutor_contrib_wordpress-*.tar.gz; do mv "$$f" "dist/tutor-contrib-wordpress-$(shell make version).tar.gz"; done
37+
build-pythonpackage: ## Build the python package for upload to pypi
38+
find . -type d -name "dist" -exec rm -rf {} +
39+
hatch build
4040

4141
push-pythonpackage: ## Push python package to pypi
42-
twine check dist/tutor-contrib-wordpress-$(shell make version).tar.gz
43-
twine upload --skip-existing dist/tutor-contrib-wordpress-$(shell make version).tar.gz
42+
hatch publish
4443

4544
version: ## Print the current tutor version
4645
@python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutorwordpress", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [Improvement] Migrate packaging from setup.py/setuptools to pyproject.toml/hatch. (by @CodeWithEmad)
2+
- [Improvement] Support for tutor v19 added. (by @CodeWithEmad)

pyproject.toml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
1+
# https://packaging.python.org/en/latest/tutorials/packaging-projects/
2+
# https://hatch.pypa.io/latest/config/build/
3+
4+
[project]
5+
name = "tutor-contrib-wordpress"
6+
license = { text = "AGPL-3.0-only" }
7+
authors = [
8+
{name = "Emad Rad"}, {email = "[email protected]"},
9+
]
10+
description = "wordpress plugin for Tutor"
11+
readme = {file = "README.rst", content-type = "text/x-rst"}
12+
requires-python = ">= 3.9"
13+
classifiers = [
14+
"Development Status :: 5 - Production/Stable",
15+
"Intended Audience :: Developers",
16+
"License :: OSI Approved :: GNU Affero General Public License v3",
17+
"Operating System :: OS Independent",
18+
"Programming Language :: Python",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
]
24+
dependencies = [
25+
"tutor>=15.0.0,<20.0.0",
26+
"importlib_resources"
27+
]
28+
# these fields will be set by hatch_build.py
29+
dynamic = ["version"]
30+
31+
[project.optional-dependencies]
32+
dev = [
33+
"tutor[dev]>=15.0.0,<20.0.0",
34+
"pylint",
35+
"black"
36+
]
37+
38+
[project.entry-points."tutor.plugin.v1"]
39+
wordpress = "tutorwordpress.plugin"
40+
41+
# https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels
42+
[project.urls]
43+
Code = "https://github.com/CodeWithEmad/tutor-contrib-wordpress"
44+
Issues = "https://github.com/CodeWithEmad/tutor-contrib-wordpress/issues"
45+
Changelog = "https://github.com/CodeWithEmad/tutor-contrib-wordpress/blob/master/CHANGELOG.md"
46+
47+
# hatch-specific configuration
48+
[tool.hatch.metadata.hooks.custom]
49+
path = ".hatch_build.py"
50+
151
[build-system]
2-
requires = ["setuptools", "wheel"]
52+
requires = ["hatchling"]
53+
build-backend = "hatchling.build"
54+
55+
[tool.hatch.build.targets.sdist]
56+
# Disable strict naming, otherwise twine is not able to detect name/version
57+
strict-naming = false
58+
include = [ "/tutorwordpress"]
59+
exclude = ["tests*"]
60+
61+
[tool.hatch.build.targets.wheel]
62+
packages = ["tutorwordpress"]

setup.py

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

0 commit comments

Comments
 (0)