Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: replace pdm-backends with setuptools and setuptools-scm #580

Merged
merged 6 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,22 @@ RUN groupadd --gid $USER_GID $USERNAME \
# Set permission for related folders
RUN chown -R $USER_UID:$USER_GID $PIPX_HOME $PIPX_BIN_DIR

# Set default working directory
WORKDIR /workspace

########################################################################################
# Build image is an intermediate image used for building the project.
########################################################################################

FROM dev as build

# Install dependencies and project into the local packages directory.
WORKDIR /workspace
ARG PDM_BUILD_SCM_VERSION=0.0.0
ARG SCM_VERSION
RUN --mount=source=README.md,target=README.md \
--mount=source=pdm.lock,target=pdm.lock \
--mount=source=pyproject.toml,target=pyproject.toml \
--mount=source=src,target=src \
mkdir __pypackages__ && PDM_BUILD_SCM_VERSION=${PDM_BUILD_SCM_VERSION} pdm sync --prod --no-editable
--mount=source=src,target=src,rw \
mkdir __pypackages__ && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_SS_PYTHON=${SCM_VERSION} pdm sync --prod --no-editable

########################################################################################
# Prod image is used for deployment and distribution.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
--target dev
- run: |
docker buildx build . \
--build-arg PDM_BUILD_SCM_VERSION=${{ github.ref_name }} \
--build-arg SCM_VERSION=${{ github.ref_name }} \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--cache-from type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }} \
--file .devcontainer/Dockerfile \
Expand Down
2 changes: 1 addition & 1 deletion .gitlab/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ container-publish:
--target dev
- |
docker buildx build . \
--build-arg PDM_BUILD_SCM_VERSION=${CI_COMMIT_TAG} \
--build-arg SCM_VERSION=${CI_COMMIT_TAG} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--file .devcontainer/Dockerfile \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons

- Project setup and template update with [copier](https://copier.readthedocs.io/).
- Manage dependencies and virtual environments with [pdm](https://pdm-project.org/).
- 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).
- Build with [setuptools](https://github.com/pypa/setuptools) and versioned with [setuptools-scm](https://github.com/pypa/setuptools_scm/).
- 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/).
- Test with [pytest](https://pytest.org/) and [coverage](https://coverage.readthedocs.io) for threshold and reports.
- 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.
Expand Down
2 changes: 1 addition & 1 deletion includes/sample.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons

- Project setup and template update with [copier](https://copier.readthedocs.io/).
- Manage dependencies and virtual environments with [pdm](https://pdm-project.org/).
- 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).
- Build with [setuptools](https://github.com/pypa/setuptools) and versioned with [setuptools-scm](https://github.com/pypa/setuptools_scm/).
- 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/).
- Test with [pytest](https://pytest.org/) and [coverage](https://coverage.readthedocs.io) for threshold and reports.
- 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.
Expand Down
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[build-system]
build-backend = "pdm.backend"
build-backend = "setuptools.build_meta"
requires = [
"pdm-backend==2.3.0",
"setuptools-scm==8.1.0",
"setuptools==70.0.0",
]

[project]
Expand Down Expand Up @@ -95,9 +96,6 @@ test = [
"pytest",
]

[tool.pdm.version]
source = "scm"

[tool.pytest.ini_options]
addopts = "-l -s --durations=0"
log_cli = true
Expand Down Expand Up @@ -133,6 +131,9 @@ select = [
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.setuptools_scm]
fallback_version = "0.0.0"

[tool.tomlsort]
all = true
in_place = true
Expand Down
10 changes: 6 additions & 4 deletions template/.devcontainer/Dockerfile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,22 @@ RUN groupadd --gid $USER_GID $USERNAME \
# Set permission for related folders
RUN chown -R $USER_UID:$USER_GID $PIPX_HOME $PIPX_BIN_DIR

# Set default working directory
WORKDIR /workspace

########################################################################################
# Build image is an intermediate image used for building the project.
########################################################################################

FROM dev as build

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

########################################################################################
# Prod image is used for deployment and distribution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
--target dev
- run: |
docker buildx build . \
--build-arg PDM_BUILD_SCM_VERSION={{ '${{ github.ref_name }}' }} \
--build-arg SCM_VERSION={{ '${{ github.ref_name }}' }} \
--build-arg PYTHON_VERSION={{ '${{ matrix.python-version }}' }} \
--cache-from type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }} \
--file .devcontainer/Dockerfile \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ container-publish:
--target dev
- |
docker buildx build . \
--build-arg PDM_BUILD_SCM_VERSION=${CI_COMMIT_TAG} \
--build-arg SCM_VERSION=${CI_COMMIT_TAG} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--file .devcontainer/Dockerfile \
Expand Down
11 changes: 6 additions & 5 deletions template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
[% from pathjoin("includes", "variable.jinja") import repo_url with context -%]
[% from pathjoin("includes", "version_compare.jinja") import version_between -%]
[build-system]
build-backend = "pdm.backend"
build-backend = "setuptools.build_meta"
requires = [
"pdm-backend==2.3.0",
"setuptools-scm==8.1.0",
"setuptools==70.0.0",
]

[project]
Expand Down Expand Up @@ -136,9 +137,6 @@ test = [
"pytest",
]

[tool.pdm.version]
source = "scm"

[tool.pytest.ini_options]
addopts = "-l -s --durations=0"
log_cli = true
Expand Down Expand Up @@ -176,6 +174,9 @@ select = [
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.setuptools_scm]
fallback_version = "0.0.0"

[tool.tomlsort]
all = true
in_place = true
Expand Down