From e43d76e2a01db22a8a9919a1f17ec09a5ed7028e Mon Sep 17 00:00:00 2001 From: Caparrini Date: Mon, 28 Oct 2024 00:12:56 +0100 Subject: [PATCH] Fix: handle difference releases alfa vs master --- .github/workflows/publish-to-pypi.yml | 9 +++++++++ VERSION | 2 +- docs/conf.py | 13 ++++++++++++- setup.py | 5 ++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 8c0f0aa..1ebc4d7 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -21,6 +21,15 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install build + + - name: Set Version Suffix Based on Branch + run: | + if [ "${GITHUB_REF_NAME}" == "master" ] || [ "${GITHUB_REF_NAME}" == "main" ]; then + echo "VERSION_SUFFIX=" >> $GITHUB_ENV + else + echo "VERSION_SUFFIX=-${GITHUB_REF_NAME}" >> $GITHUB_ENV + fi + - name: Build a binary wheel and a source tarball run: | python -m build --sdist --wheel --outdir dist/ diff --git a/VERSION b/VERSION index 899f24f..ef3d8e2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.0 \ No newline at end of file +0.9.0.0 \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 2fd0f46..8d710c6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,18 @@ # Path to the VERSION file version_file = pathlib.Path(__file__).parent.parent / "VERSION" -version = version_file.read_text().strip() +base_version = version_file.read_text().strip() +# Check if we are on Read the Docs +on_rtd = os.getenv("READTHEDOCS") == "True" +# Determine suffix based on the branch +suffix = "" +if on_rtd: + branch = os.getenv("READTHEDOCS_VERSION", "main") + if branch in ["main", "master"]: + suffix = "" + else: + suffix = f"-{branch}" +version = f'{base_version}{suffix}' sys.path.insert(0, os.path.abspath('..')) diff --git a/setup.py b/setup.py index 981bfb9..2d3d199 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,13 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages import pathlib +import os here = pathlib.Path(__file__).parent.resolve() long_description = (here / "README.md").read_text(encoding="utf-8") -version = (here / "VERSION").read_text().strip() +base_version = (here / "VERSION").read_text().strip() +suffix = os.getenv("VERSION_SUFFIX", "") +version = f"{base_version}{suffix}"