From d32ca043263c04bdd78b64fa912185a61169a683 Mon Sep 17 00:00:00 2001 From: Catherine Date: Sun, 3 Sep 2023 02:40:16 +0000 Subject: [PATCH] pyproject: migrate to PDM build backend. `.git_archival.txt` and the functionality of deriving SCM version from a GitHub generated archive is removed pending implementation of pdm-project/pdm-backend#194. --- .git_archival.txt | 4 ---- .gitattributes | 1 - pdm_build.py | 13 +++++++++++++ pyproject.toml | 22 ++++++++++++++-------- setup.py | 25 ------------------------- 5 files changed, 27 insertions(+), 38 deletions(-) delete mode 100644 .git_archival.txt create mode 100644 pdm_build.py delete mode 100644 setup.py diff --git a/.git_archival.txt b/.git_archival.txt deleted file mode 100644 index 8fb235d..0000000 --- a/.git_archival.txt +++ /dev/null @@ -1,4 +0,0 @@ -node: $Format:%H$ -node-date: $Format:%cI$ -describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ -ref-names: $Format:%D$ diff --git a/.gitattributes b/.gitattributes index 5f2f45f..208af66 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -.git_archival.txt export-subst /amaranth/vendor/* -linguist-vendored diff --git a/pdm_build.py b/pdm_build.py new file mode 100644 index 0000000..bd0a54b --- /dev/null +++ b/pdm_build.py @@ -0,0 +1,13 @@ +from pdm.backend._vendor.packaging.version import Version + + +# This is done in a PDM build hook without specifying `dynamic = [..., "version"]` to put all +# of the static metadata into pyproject.toml. Tools other than PDM will not execute this script +# and will use the generic version of the documentation URL (which redirects to /latest). +def pdm_build_initialize(context): + version = Version(context.config.metadata["version"]) + if version.is_prerelease: + url_version = "latest" + else: + url_version = f"v{version}" + context.config.metadata["urls"]["Documentation"] += url_version diff --git a/pyproject.toml b/pyproject.toml index 45c8041..8e07f7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,10 @@ # Project metadata +[tool.pdm.version] +source = "scm" + [project] -dynamic = ["version", "urls"] +dynamic = ["version"] name = "amaranth" description = "Amaranth hardware definition language" @@ -23,21 +26,24 @@ remote-build = ["paramiko~=2.7"] [project.scripts] amaranth-rpc = "amaranth.rpc:main" +[project.urls] +"Homepage" = "https://amaranth-lang.org/" +"Documentation" = "https://amaranth-lang.org/docs/amaranth/" # modified in pdm_build.py +"Source Code" = "https://github.com/amaranth-lang/amaranth" +"Bug Tracker" = "https://github.com/amaranth-lang/amaranth/issues" + # Build system configuration [build-system] -requires = ["wheel", "setuptools>=67.0", "setuptools_scm[toml]>=6.2"] -build-backend = "setuptools.build_meta" +requires = ["pdm-backend"] +build-backend = "pdm.backend" -[tool.setuptools] +[tool.pdm.build] # If amaranth 0.3 is checked out with git (e.g. as a part of a persistent editable install or # a git worktree cached by tools like poetry), it can have an empty `nmigen` directory left over, # which causes a hard error because setuptools cannot determine the top-level package. # Add a workaround to improve experience for people upgrading from old checkouts. -packages = ["amaranth"] - -[tool.setuptools_scm] -local_scheme = "node-and-timestamp" +includes = ["amaranth/"] # Development workflow configuration diff --git a/setup.py b/setup.py deleted file mode 100644 index eb91960..0000000 --- a/setup.py +++ /dev/null @@ -1,25 +0,0 @@ -from setuptools import setup - - -def doc_version(): - try: - from setuptools_scm.git import parse as parse_git - git = parse_git(".") - if git.exact: - return git.format_with("v{tag}") - else: - return "latest" - except ImportError: - # PEP 517 compliant build tools will never reach this code path. - # Poetry reaches this code path. - return "" - - -setup( - project_urls={ - "Homepage": "https://amaranth-lang.org/", - "Documentation": "https://amaranth-lang.org/docs/amaranth/{}".format(doc_version()), - "Source Code": "https://github.com/amaranth-lang/amaranth", - "Bug Tracker": "https://github.com/amaranth-lang/amaranth/issues", - }, -)