From 38481d20ad9f3d29f6378c1f6ab09b79c7d0a921 Mon Sep 17 00:00:00 2001 From: qdelamea Date: Fri, 15 Nov 2024 16:24:39 +0100 Subject: [PATCH] fix: publication to PyPiTest --- .github/workflows/publish.yaml | 3 ++- mypy.ini | 7 +++++++ pyproject.toml | 7 +------ setup.py | 38 ++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 setup.py diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 62a5314..322337e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,6 +15,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + with: + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v4 @@ -24,7 +26,6 @@ jobs: - name: Install dependencies run: | python -m pip install uv - python -m uv pip install . python -m uv pip install build - name: Build the CLI diff --git a/mypy.ini b/mypy.ini index b70adf7..4fc7824 100644 --- a/mypy.ini +++ b/mypy.ini @@ -13,3 +13,10 @@ ignore_missing_imports = True [mypy-grpc] ignore_missing_imports = True + + +[mypy-setuptools] +ignore_missing_imports = True + +[mypy-setuptools_scm] +ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml index 492fad9..1384d23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = ["setuptools>=64", - "setuptools-scm>=8", + "setuptools-scm[toml]>=8", "wheel"] build-backend = "setuptools.build_meta" @@ -58,8 +58,3 @@ dev = [ [project.scripts] armonik = "armonik_cli.cli:cli" - -[tool.setuptools_scm] -version_scheme = "post-release" -local_scheme = "no-local-version" -version_file = "src/armonik_cli/_version.py" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..9ff205d --- /dev/null +++ b/setup.py @@ -0,0 +1,38 @@ +# WARNING: This setup.py script is only for customizing the local version scheme with setuptools-scm. +# All other project configuration must be provided in pyproject.toml. Use this script cautiously and +# refer to the documentation for more details: https://setuptools-scm.readthedocs.io/en/latest/customizing/. + +from os import environ +from setuptools import setup +from setuptools_scm import ScmVersion + + +def get_local_schema(version: ScmVersion) -> str: + """ + Generate a custom local version scheme for setuptools-scm. + + Generates a local version string based on environment variables. If RELEASE is unset, + appends .dev for development builds; otherwise, returns an empty string. The + value of is retrieved from the GITHUB_RUN_ID environment variable if it exists, + otherwise the default value used is 0. + + Args: + version: The ScmVersion object passed by setuptools-scm. + + Returns: + The custom local version string. + """ + run_id = environ.get("GITHUB_RUN_ID", "0") + release = environ.get("RELEASE", "") + if not release: + return f".dev{run_id}" + return "" + + +setup( + use_scm_version={ + "version_scheme": "post-release", + "local_scheme": get_local_schema, + "version_file": "src/armonik_cli/_version.py", + } +)