Switch versioning to be SCM-based (#715)

Co-authored-by: Abhinav Singh <mailsforabhinav@gmail.com>
This commit is contained in:
Sviatoslav Sydorenko 2021-11-13 22:16:07 +01:00 committed by GitHub
parent 523021c9b5
commit 8d3fe87155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 54 additions and 4 deletions

View File

@ -2,6 +2,7 @@
**
# Except proxy
!.git
!proxy
!requirements.txt
!pyproject.toml

View File

@ -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

View File

@ -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

View File

@ -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/

View File

@ -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)

2
proxy/common/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Build-time setuptools-scm generated version module
/_scm_version.py

View File

@ -0,0 +1,3 @@
# This stub file is necessary because `_scm_version.py`
# autogenerated on build and absent on mypy checks time
version: str

11
proxy/common/_version.py Normal file
View File

@ -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__',)

View File

@ -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'

View File

@ -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"

View File

@ -1 +1,2 @@
twine==3.5.0
setuptools-scm == 6.3.2
twine==3.5.0