From b858f5352f39fc122272be95c7a1654f64d3b55a Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 9 Nov 2021 11:50:52 +0100 Subject: [PATCH] Switch versioning to be SCM-based --- .dockerignore | 1 + .github/workflows/test-docker.yml | 1 + .pre-commit-config.yaml | 1 + Dockerfile | 3 +++ Makefile | 3 ++- proxy/common/.gitignore | 2 ++ proxy/common/_scm_version.pyi | 3 +++ proxy/common/_version.py | 11 +++++++++++ proxy/common/version.py | 23 +++++++++++++++++++++-- pyproject.toml | 7 +++++++ requirements-release.txt | 3 ++- 11 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 proxy/common/.gitignore create mode 100644 proxy/common/_scm_version.pyi create mode 100644 proxy/common/_version.py diff --git a/.dockerignore b/.dockerignore index d1ad0ba8e0..3483deb2b5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ ** # Except proxy +!.git !proxy !requirements.txt !pyproject.toml diff --git a/.github/workflows/test-docker.yml b/.github/workflows/test-docker.yml index ee30eaa244..e55de49ead 100644 --- a/.github/workflows/test-docker.yml +++ b/.github/workflows/test-docker.yml @@ -45,6 +45,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt + pip install -r requirements-release.txt pip install -r requirements-testing.txt pip install -r requirements-tunnel.txt - name: Build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1770e6656b..fc00d93e1e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -163,6 +163,7 @@ repos: additional_dependencies: - paramiko == 2.8.0 - types-paramiko == 2.7.3 + - types-setuptools == 57.4.2 args: # FIXME: get rid of missing imports ignore - --ignore-missing-imports diff --git a/Dockerfile b/Dockerfile index 4c176f8c0d..0f37fda244 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ FROM python:3.10-alpine as base +RUN apk add git + FROM base as builder +COPY .git /app/.git COPY requirements.txt /app/ COPY pyproject.toml /app/ COPY setup.cfg /app/ diff --git a/Makefile b/Makefile index 2c17910b37..f99e5fd594 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ SHELL := /bin/bash NS ?= abhinavsingh IMAGE_NAME ?= proxy.py -VERSION ?= v$(shell python -m proxy --version) +#VERSION ?= v$(shell bash -c "python -m setuptools_scm --version \| awk '{print$3}'") +VERSION ?= v$(shell python -m setuptools_scm --version | awk '{print $$3}' | sed 's/\+/--/') LATEST_TAG := $(NS)/$(IMAGE_NAME):latest IMAGE_TAG := $(NS)/$(IMAGE_NAME):$(VERSION) diff --git a/proxy/common/.gitignore b/proxy/common/.gitignore new file mode 100644 index 0000000000..7d536eca4b --- /dev/null +++ b/proxy/common/.gitignore @@ -0,0 +1,2 @@ +# Build-time setuptools-scm generated version module +/_scm_version.py diff --git a/proxy/common/_scm_version.pyi b/proxy/common/_scm_version.pyi new file mode 100644 index 0000000000..deb2e36a30 --- /dev/null +++ b/proxy/common/_scm_version.pyi @@ -0,0 +1,3 @@ +# This stub file is necessary because `_scm_version.py` +# autogenerated on build and absent on mypy checks time +version: str diff --git a/proxy/common/_version.py b/proxy/common/_version.py new file mode 100644 index 0000000000..b1e36e6c57 --- /dev/null +++ b/proxy/common/_version.py @@ -0,0 +1,11 @@ +"""Version definition.""" + +try: + # pylint: disable=unused-import + from ._scm_version import version as __version__ # noqa: WPS433, WPS436 +except ImportError: + from pkg_resources import get_distribution as _get_dist # noqa: WPS433 + __version__ = _get_dist('proxy.py').version # noqa: WPS440 + + +__all__ = ('__version__',) diff --git a/proxy/common/version.py b/proxy/common/version.py index 5635e7a793..c6191dfb4c 100644 --- a/proxy/common/version.py +++ b/proxy/common/version.py @@ -8,5 +8,24 @@ :copyright: (c) 2013-present by Abhinav Singh and contributors. :license: BSD, see LICENSE for more details. """ -VERSION = (2, 4, 0) -__version__ = '.'.join(map(str, VERSION[0:3])) +from typing import Tuple, Union + +from ._version import __version__ # noqa: WPS436 + + +def _to_int_or_str(inp: str) -> Union[int, str]: + try: + return int(inp) + except ValueError: + return inp + + +def _split_version_parts(inp: str) -> Tuple[str, ...]: + public_version, _plus, local_version = inp.partition('+') + return (*public_version.split('.'), local_version) + + +VERSION = tuple(map(_to_int_or_str, _split_version_parts(__version__))) + + +__all__ = '__version__', 'VERSION' diff --git a/pyproject.toml b/pyproject.toml index 62b4b846b0..6ac5005a09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,5 +2,12 @@ requires = [ # Essentials "setuptools", + + # Plugins + "setuptools-scm[toml] >= 6", + "setuptools-scm-git-archive >= 1.1", ] build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "proxy/common/_scm_version.py" diff --git a/requirements-release.txt b/requirements-release.txt index 0c4fc95219..ae95ad7991 100644 --- a/requirements-release.txt +++ b/requirements-release.txt @@ -1 +1,2 @@ -twine==3.5.0 \ No newline at end of file +setuptools-scm == 6.3.2 +twine==3.5.0