Skip to content

Commit 79d8c1b

Browse files
authored
build: replace pdm-backends with setuptools and setuptools-scm (#580)
1 parent 6535f7d commit 79d8c1b

File tree

10 files changed

+30
-24
lines changed

10 files changed

+30
-24
lines changed

.devcontainer/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,22 @@ RUN groupadd --gid $USER_GID $USERNAME \
6161
# Set permission for related folders
6262
RUN chown -R $USER_UID:$USER_GID $PIPX_HOME $PIPX_BIN_DIR
6363

64+
# Set default working directory
65+
WORKDIR /workspace
66+
6467
########################################################################################
6568
# Build image is an intermediate image used for building the project.
6669
########################################################################################
6770

6871
FROM dev as build
6972

7073
# Install dependencies and project into the local packages directory.
71-
WORKDIR /workspace
72-
ARG PDM_BUILD_SCM_VERSION=0.0.0
74+
ARG SCM_VERSION
7375
RUN --mount=source=README.md,target=README.md \
7476
--mount=source=pdm.lock,target=pdm.lock \
7577
--mount=source=pyproject.toml,target=pyproject.toml \
76-
--mount=source=src,target=src \
77-
mkdir __pypackages__ && PDM_BUILD_SCM_VERSION=${PDM_BUILD_SCM_VERSION} pdm sync --prod --no-editable
78+
--mount=source=src,target=src,rw \
79+
mkdir __pypackages__ && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_SS_PYTHON=${SCM_VERSION} pdm sync --prod --no-editable
7880

7981
########################################################################################
8082
# Prod image is used for deployment and distribution.

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
--target dev
6464
- run: |
6565
docker buildx build . \
66-
--build-arg PDM_BUILD_SCM_VERSION=${{ github.ref_name }} \
66+
--build-arg SCM_VERSION=${{ github.ref_name }} \
6767
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
6868
--cache-from type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }} \
6969
--file .devcontainer/Dockerfile \

.gitlab/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ container-publish:
5959
--target dev
6060
- |
6161
docker buildx build . \
62-
--build-arg PDM_BUILD_SCM_VERSION=${CI_COMMIT_TAG} \
62+
--build-arg SCM_VERSION=${CI_COMMIT_TAG} \
6363
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
6464
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
6565
--file .devcontainer/Dockerfile \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
3636

3737
- Project setup and template update with [copier](https://copier.readthedocs.io/).
3838
- Manage dependencies and virtual environments with [pdm](https://pdm-project.org/).
39-
- Build with [pdm-backend](https://backend.pdm-project.org/) and versioned with [SCM tag](https://backend.pdm-project.org/metadata/#read-from-scm-tag-supporting-git-and-hg).
39+
- Build with [setuptools](https://github.com/pypa/setuptools) and versioned with [setuptools-scm](https://github.com/pypa/setuptools_scm/).
4040
- Lint with [pre-commit](https://pre-commit.com), [mypy](http://www.mypy-lang.org/), [ruff](https://github.com/charliermarsh/ruff), [toml-sort](https://github.com/pappasam/toml-sort) and [commitlint](https://commitlint.js.org/).
4141
- Test with [pytest](https://pytest.org/) and [coverage](https://coverage.readthedocs.io) for threshold and reports.
4242
- Documentation with [sphinx](https://www.sphinx-doc.org/), the [furo](https://pradyunsg.me/furo) theme and [MyST parser](https://myst-parser.readthedocs.io/) for markdown.

includes/sample.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
1414

1515
- Project setup and template update with [copier](https://copier.readthedocs.io/).
1616
- Manage dependencies and virtual environments with [pdm](https://pdm-project.org/).
17-
- Build with [pdm-backend](https://backend.pdm-project.org/) and versioned with [SCM tag](https://backend.pdm-project.org/metadata/#read-from-scm-tag-supporting-git-and-hg).
17+
- Build with [setuptools](https://github.com/pypa/setuptools) and versioned with [setuptools-scm](https://github.com/pypa/setuptools_scm/).
1818
- Lint with [pre-commit](https://pre-commit.com), [mypy](http://www.mypy-lang.org/), [ruff](https://github.com/charliermarsh/ruff), [toml-sort](https://github.com/pappasam/toml-sort) and [commitlint](https://commitlint.js.org/).
1919
- Test with [pytest](https://pytest.org/) and [coverage](https://coverage.readthedocs.io) for threshold and reports.
2020
- Documentation with [sphinx](https://www.sphinx-doc.org/), the [furo](https://pradyunsg.me/furo) theme and [MyST parser](https://myst-parser.readthedocs.io/) for markdown.

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[build-system]
2-
build-backend = "pdm.backend"
2+
build-backend = "setuptools.build_meta"
33
requires = [
4-
"pdm-backend==2.3.0",
4+
"setuptools-scm==8.1.0",
5+
"setuptools==70.0.0",
56
]
67

78
[project]
@@ -95,9 +96,6 @@ test = [
9596
"pytest",
9697
]
9798

98-
[tool.pdm.version]
99-
source = "scm"
100-
10199
[tool.pytest.ini_options]
102100
addopts = "-l -s --durations=0"
103101
log_cli = true
@@ -133,6 +131,9 @@ select = [
133131
[tool.ruff.lint.pydocstyle]
134132
convention = "google"
135133

134+
[tool.setuptools_scm]
135+
fallback_version = "0.0.0"
136+
136137
[tool.tomlsort]
137138
all = true
138139
in_place = true

template/.devcontainer/Dockerfile.jinja

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,22 @@ RUN groupadd --gid $USER_GID $USERNAME \
6161
# Set permission for related folders
6262
RUN chown -R $USER_UID:$USER_GID $PIPX_HOME $PIPX_BIN_DIR
6363

64+
# Set default working directory
65+
WORKDIR /workspace
66+
6467
########################################################################################
6568
# Build image is an intermediate image used for building the project.
6669
########################################################################################
6770

6871
FROM dev as build
6972

7073
# Install dependencies and project into the local packages directory.
71-
WORKDIR /workspace
72-
ARG PDM_BUILD_SCM_VERSION=0.0.0
74+
ARG SCM_VERSION
7375
RUN --mount=source=README.md,target=README.md \
7476
--mount=source=pdm.lock,target=pdm.lock \
7577
--mount=source=pyproject.toml,target=pyproject.toml \
76-
--mount=source=src,target=src \
77-
mkdir __pypackages__ && PDM_BUILD_SCM_VERSION=${PDM_BUILD_SCM_VERSION} pdm sync --prod --no-editable
78+
--mount=source=src,target=src,rw \
79+
mkdir __pypackages__ && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_{{ package_name|upper|replace(".", "_")|replace("-", "_") }}=${SCM_VERSION} pdm sync --prod --no-editable
7880

7981
########################################################################################
8082
# Prod image is used for deployment and distribution.

template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
--target dev
6565
- run: |
6666
docker buildx build . \
67-
--build-arg PDM_BUILD_SCM_VERSION={{ '${{ github.ref_name }}' }} \
67+
--build-arg SCM_VERSION={{ '${{ github.ref_name }}' }} \
6868
--build-arg PYTHON_VERSION={{ '${{ matrix.python-version }}' }} \
6969
--cache-from type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }} \
7070
--file .devcontainer/Dockerfile \

template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ container-publish:
7070
--target dev
7171
- |
7272
docker buildx build . \
73-
--build-arg PDM_BUILD_SCM_VERSION=${CI_COMMIT_TAG} \
73+
--build-arg SCM_VERSION=${CI_COMMIT_TAG} \
7474
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
7575
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
7676
--file .devcontainer/Dockerfile \

template/pyproject.toml.jinja

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
[% from pathjoin("includes", "variable.jinja") import repo_url with context -%]
33
[% from pathjoin("includes", "version_compare.jinja") import version_between -%]
44
[build-system]
5-
build-backend = "pdm.backend"
5+
build-backend = "setuptools.build_meta"
66
requires = [
7-
"pdm-backend==2.3.0",
7+
"setuptools-scm==8.1.0",
8+
"setuptools==70.0.0",
89
]
910

1011
[project]
@@ -136,9 +137,6 @@ test = [
136137
"pytest",
137138
]
138139

139-
[tool.pdm.version]
140-
source = "scm"
141-
142140
[tool.pytest.ini_options]
143141
addopts = "-l -s --durations=0"
144142
log_cli = true
@@ -176,6 +174,9 @@ select = [
176174
[tool.ruff.lint.pydocstyle]
177175
convention = "google"
178176

177+
[tool.setuptools_scm]
178+
fallback_version = "0.0.0"
179+
179180
[tool.tomlsort]
180181
all = true
181182
in_place = true

0 commit comments

Comments
 (0)