Skip to content

Commit 8d3fe87

Browse files
Switch versioning to be SCM-based (#715)
Co-authored-by: Abhinav Singh <[email protected]>
1 parent 523021c commit 8d3fe87

File tree

11 files changed

+54
-4
lines changed

11 files changed

+54
-4
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
**
33

44
# Except proxy
5+
!.git
56
!proxy
67
!requirements.txt
78
!pyproject.toml

.github/workflows/test-docker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
run: |
4646
python -m pip install --upgrade pip
4747
pip install -r requirements.txt
48+
pip install -r requirements-release.txt
4849
pip install -r requirements-testing.txt
4950
pip install -r requirements-tunnel.txt
5051
- name: Build

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ repos:
163163
additional_dependencies:
164164
- paramiko == 2.8.0
165165
- types-paramiko == 2.7.3
166+
- types-setuptools == 57.4.2
166167
args:
167168
# FIXME: get rid of missing imports ignore
168169
- --ignore-missing-imports

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
FROM python:3.10-alpine as base
2+
RUN apk add git
3+
24
FROM base as builder
35

6+
COPY .git /app/.git
47
COPY requirements.txt /app/
58
COPY pyproject.toml /app/
69
COPY setup.cfg /app/

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ SHELL := /bin/bash
22

33
NS ?= abhinavsingh
44
IMAGE_NAME ?= proxy.py
5-
VERSION ?= v$(shell python -m proxy --version)
5+
#VERSION ?= v$(shell bash -c "python -m setuptools_scm --version \| awk '{print$3}'")
6+
VERSION ?= v$(shell python -m setuptools_scm --version | awk '{print $$3}' | sed 's/\+/--/')
67
LATEST_TAG := $(NS)/$(IMAGE_NAME):latest
78
IMAGE_TAG := $(NS)/$(IMAGE_NAME):$(VERSION)
89

proxy/common/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Build-time setuptools-scm generated version module
2+
/_scm_version.py

proxy/common/_scm_version.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This stub file is necessary because `_scm_version.py`
2+
# autogenerated on build and absent on mypy checks time
3+
version: str

proxy/common/_version.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Version definition."""
2+
3+
try:
4+
# pylint: disable=unused-import
5+
from ._scm_version import version as __version__ # noqa: WPS433, WPS436
6+
except ImportError:
7+
from pkg_resources import get_distribution as _get_dist # noqa: WPS433
8+
__version__ = _get_dist('proxy.py').version # noqa: WPS440
9+
10+
11+
__all__ = ('__version__',)

proxy/common/version.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,24 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
VERSION = (2, 4, 0)
12-
__version__ = '.'.join(map(str, VERSION[0:3]))
11+
from typing import Tuple, Union
12+
13+
from ._version import __version__ # noqa: WPS436
14+
15+
16+
def _to_int_or_str(inp: str) -> Union[int, str]:
17+
try:
18+
return int(inp)
19+
except ValueError:
20+
return inp
21+
22+
23+
def _split_version_parts(inp: str) -> Tuple[str, ...]:
24+
public_version, _plus, local_version = inp.partition('+')
25+
return (*public_version.split('.'), local_version)
26+
27+
28+
VERSION = tuple(map(_to_int_or_str, _split_version_parts(__version__)))
29+
30+
31+
__all__ = '__version__', 'VERSION'

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22
requires = [
33
# Essentials
44
"setuptools",
5+
6+
# Plugins
7+
"setuptools-scm[toml] >= 6",
8+
"setuptools-scm-git-archive >= 1.1",
59
]
610
build-backend = "setuptools.build_meta"
11+
12+
[tool.setuptools_scm]
13+
write_to = "proxy/common/_scm_version.py"

0 commit comments

Comments
 (0)