From f3704fc7fa8ca50381d4b0f78e300d87c64c2449 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 23 May 2024 16:08:00 +0800 Subject: [PATCH 1/6] build: replace pdm-backends with setuptools and setuptools-scm --- README.md | 2 +- includes/sample.jinja | 2 +- pyproject.toml | 8 ++++++-- template/pyproject.toml.jinja | 8 ++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 26af18b8..e64e7ccf 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/includes/sample.jinja b/includes/sample.jinja index 37b275a9..ca62aaf8 100644 --- a/includes/sample.jinja +++ b/includes/sample.jinja @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 9c1936b9..a86b6676 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] @@ -133,6 +134,9 @@ select = [ [tool.ruff.lint.pydocstyle] convention = "google" +[tool.setuptools_scm] +fallback_version = "0.0.0" + [tool.tomlsort] all = true in_place = true diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 6e5484b0..6d2319c9 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -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] @@ -176,6 +177,9 @@ select = [ [tool.ruff.lint.pydocstyle] convention = "google" +[tool.setuptools_scm] +fallback_version = "0.0.0" + [tool.tomlsort] all = true in_place = true From b61770845d1a9372685423ea173e75d07ff3ed21 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 23 May 2024 16:29:47 +0800 Subject: [PATCH 2/6] use SCM_VERSION for pretend version --- .devcontainer/Dockerfile | 4 ++-- .github/workflows/release.yml | 2 +- .gitlab/workflows/release.yml | 2 +- template/.devcontainer/Dockerfile.jinja | 4 ++-- .../workflows/release.yml.jinja | 2 +- .../workflows/release.yml.jinja | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 75eebaed..179841d9 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -69,12 +69,12 @@ 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=0.0.0 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 + mkdir __pypackages__ && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_SS_PYTHON=${SCM_VERSION} pdm sync --prod --no-editable ######################################################################################## # Prod image is used for deployment and distribution. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f40fad5d..04e82577 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 \ diff --git a/.gitlab/workflows/release.yml b/.gitlab/workflows/release.yml index 35c599ec..4e054b03 100644 --- a/.gitlab/workflows/release.yml +++ b/.gitlab/workflows/release.yml @@ -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 \ diff --git a/template/.devcontainer/Dockerfile.jinja b/template/.devcontainer/Dockerfile.jinja index b54b6ea1..cc91dd87 100644 --- a/template/.devcontainer/Dockerfile.jinja +++ b/template/.devcontainer/Dockerfile.jinja @@ -69,12 +69,12 @@ 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=0.0.0 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 + 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. diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja index 3ea3b7ff..004b5c8a 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja @@ -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 \ diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja index b645a5d7..24465495 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja @@ -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 \ From b4c7a14bd716cf9dd028fd407fa3fee336427f20 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 23 May 2024 16:35:55 +0800 Subject: [PATCH 3/6] remove redundant settings for pdm-backend --- pyproject.toml | 3 --- template/pyproject.toml.jinja | 3 --- 2 files changed, 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a86b6676..31ce8307 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,9 +96,6 @@ test = [ "pytest", ] -[tool.pdm.version] -source = "scm" - [tool.pytest.ini_options] addopts = "-l -s --durations=0" log_cli = true diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 6d2319c9..26b1928e 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -137,9 +137,6 @@ test = [ "pytest", ] -[tool.pdm.version] -source = "scm" - [tool.pytest.ini_options] addopts = "-l -s --durations=0" log_cli = true From dd6f07d7843404823bce48932ad631405028406c Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 23 May 2024 17:43:36 +0800 Subject: [PATCH 4/6] fix src folder permission --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 179841d9..01ff0f4a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -73,7 +73,7 @@ ARG SCM_VERSION=0.0.0 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 \ + --mount=source=src,target=src,rw \ mkdir __pypackages__ && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_SS_PYTHON=${SCM_VERSION} pdm sync --prod --no-editable ######################################################################################## From 6a80b3499c233801fa1b0d693f7135accfa8a021 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 23 May 2024 17:48:44 +0800 Subject: [PATCH 5/6] update template --- template/.devcontainer/Dockerfile.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/.devcontainer/Dockerfile.jinja b/template/.devcontainer/Dockerfile.jinja index cc91dd87..2114e18d 100644 --- a/template/.devcontainer/Dockerfile.jinja +++ b/template/.devcontainer/Dockerfile.jinja @@ -73,7 +73,7 @@ ARG SCM_VERSION=0.0.0 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 \ + --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 ######################################################################################## From 6ed628aa52b6848390277c587b02578be81c6c72 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 23 May 2024 18:03:16 +0800 Subject: [PATCH 6/6] minor changes to dockerfile --- .devcontainer/Dockerfile | 6 ++++-- template/.devcontainer/Dockerfile.jinja | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 01ff0f4a..50ed9bd3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -61,6 +61,9 @@ 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. ######################################################################################## @@ -68,8 +71,7 @@ RUN chown -R $USER_UID:$USER_GID $PIPX_HOME $PIPX_BIN_DIR FROM dev as build # Install dependencies and project into the local packages directory. -WORKDIR /workspace -ARG 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 \ diff --git a/template/.devcontainer/Dockerfile.jinja b/template/.devcontainer/Dockerfile.jinja index 2114e18d..95034b22 100644 --- a/template/.devcontainer/Dockerfile.jinja +++ b/template/.devcontainer/Dockerfile.jinja @@ -61,6 +61,9 @@ 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. ######################################################################################## @@ -68,8 +71,7 @@ RUN chown -R $USER_UID:$USER_GID $PIPX_HOME $PIPX_BIN_DIR FROM dev as build # Install dependencies and project into the local packages directory. -WORKDIR /workspace -ARG 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 \