Skip to content

Commit

Permalink
chore: Modernize packaging
Browse files Browse the repository at this point in the history
Switch to modern packaging backed by setuptools and setuptools-scm,
including a VCS-backed versioning scheme, as well as trusted publishing
configuration for PyPI.
  • Loading branch information
antonagestam committed Sep 15, 2024
1 parent 3b920ec commit 5a5fba4
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 59 deletions.
43 changes: 40 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ on:

jobs:
build-and-publish:
uses: less-action/reusables/.github/workflows/python-publish.yaml@main
secrets:
pypi_api_token: ${{ secrets.PYPI_API_TOKEN }}
name: Build and publish
runs-on: ubuntu-latest
permissions:
# permission required for trusted publishing
id-token: write
environment:
name: pypi
url: https://pypi.org/p/immoney
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
cache-dependency-path: pyproject.toml
check-latest: true
- name: Install dependencies
run: python3 -m pip install --upgrade build pkginfo
- name: Build
run: python3 -m build --sdist --wheel .
- name: Inspect built wheel version
id: inspect-wheel-version
run: |
python3 << 'EOF' >> $GITHUB_OUTPUT
from pathlib import Path
from pkginfo import Wheel
[wheel_path] = Path("dist").glob("*.whl")
wheel = Wheel(wheel_path)
print(f"version={wheel.version}")
EOF
- name: Fail on version mismatch
if: ${{ steps.inspect-wheel-version.outputs.version != github.event.release.tag_name }}
run: |
echo "💥 The version of the built wheel does not match the release tag."
echo
echo "Release tag: '${{ github.event.release.tag_name }}'"
echo "Packaged version: '${{ steps.inspect-wheel-version.outputs.version }}'"
exit 1
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ dmypy.json

# pytype static type analyzer
.pytype/

# Dynamic version file
src/phantom/_version.py
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ exclude *.yaml
exclude *.yml
include README.md
include LICENSE
exclude .gitignore
exclude setup.cfg
78 changes: 77 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,83 @@
[build-system]
requires = ["setuptools>=67.4.0", "wheel"]
requires = [
"setuptools==74.1.2",
"setuptools-scm==8.1.0",
"wheel==0.44.0",
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_file = "src/phantom/_version.py"

[tool.setuptools]
include-package-data = true

[tool.setuptools.dynamic]
readme = {file = "README.md", content-type = "text/markdown; charset=UTF-8"}

[tool.setuptools.packages.find]
where = ["src"]
namespaces = false


[project]
name = "phantom-type"
description = "Phantom types for Python"
requires-python = ">=3.9"
authors = [
{ name="Anton Agestam", email="[email protected]" },
]
license = {text = "BSD-3-Clause"}
classifiers = [
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Development Status :: 5 - Production/Stable",
]
dynamic = ["version", "readme"]
dependencies = [
# typeguard 4.3.0 breaks "intersection" protocols, see linked issue. I didn't figure
# out a way to work around this at the moment, so it needs to be pinned.
# https://github.com/antonagestam/phantom-types/issues/299
"typeguard>=4,<4.3.0",
"typing_extensions>=4.3.0",
"numerary>=0.4.3",
]

[project.optional-dependencies]
phonenumbers = ["phonenumbers>=8.12.41"]
pydantic = ["pydantic>=1.9.0,<2"]
dateutil = ["python-dateutil>=2.8.2"]
hypothesis = ["hypothesis[zoneinfo]>=6.68.0"]
all = [
"phantom-types[phonenumbers]",
"phantom-types[pydantic]",
"phantom-types[dateutil]",
"phantom-types[hypothesis]",
]
test = [
"mypy>=0.991",
"pytest",
"pytest-mypy-plugins>=1.9.3",
"coverage",
]

[project.urls]
"Source Repository" = "https://github.com/antonagestam/phantom-types/"
"Documentation" = "https://phantom-types.readthedocs.io/en/stable/"


[tool.check-manifest]
ignore = ["src/phantom/_version.py"]


[tool.black]
target-version = ["py39"]

Expand Down
51 changes: 0 additions & 51 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,69 +1,18 @@
[metadata]
name = phantom-types
version = attr: phantom.__version__
description = Phantom types for Python
long_description = file: README.md
long_description_content_type = text/markdown; charset=UTF-8
license = BSD 3-Clause License
license_file = LICENSE
classifiers =
Intended Audience :: Developers
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Development Status :: 5 - Production/Stable
author = Anton Agestam
author_email = [email protected]
url = https://github.com/antonagestam/phantom-types/
project_urls =
Source Repository = https://github.com/antonagestam/phantom-types/
Documentation = https://phantom-types.readthedocs.io/en/stable/

[options]
include_package_data = True
package_dir =
=src
packages = find:
python_requires = >=3.9
install_requires =
# typeguard 4.3.0 breaks "intersection" protocols, see linked issue. I didn't figure
# out a way to work around this at the moment, so it needs to be pinned.
# https://github.com/antonagestam/phantom-types/issues/299
typeguard>=4,<4.3.0
typing_extensions>=4.3.0
numerary>=0.4.3

[options.packages.find]
where = src

[options.package_data]
phantom = py.typed

[options.extras_require]
phonenumbers =
phonenumbers>=8.12.41
pydantic =
pydantic>=1.9.0,<2
dateutil =
python-dateutil>=2.8.2
hypothesis =
hypothesis[zoneinfo]>=6.68.0
all =
phantom-types[phonenumbers]
phantom-types[pydantic]
phantom-types[dateutil]
phantom-types[hypothesis]
test =
mypy>=0.991
pytest
pytest-mypy-plugins>=1.9.3
coverage

[mypy]
python_version = 3.9
Expand Down
3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

5 changes: 4 additions & 1 deletion src/phantom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ class Big(int, Phantom, predicate=is_big):
from .bounds import get_bound_parser
from .errors import BoundError
from .predicates import Predicate
from ._version import __version__
from ._version import __version_tuple__

__version__ = "2.1.1"
__all__ = (
"__version__",
"__version_tuple__",
"BoundError",
"Phantom",
"PhantomBase",
Expand Down

0 comments on commit 5a5fba4

Please sign in to comment.