Repository: abhinavsingh/proxy.py
Pull request #715 (2021-11-09 10:52:27)

Switch versioning to be SCM-based

webknjaz: This depends on the presence of Git tags.
webknjaz: @abhinavsingh as a reminder — tag the appropriate commit for the last release you've done on `develop` and then re-run the workflows here to see the version updated.
codecov[bot]: # [Codecov](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh) Report
> Merging [#715](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh) (21ce532) into [develop](https://codecov.io/gh/abhinavsingh/proxy.py/commit/094e30d31f305524f5ec1ee122eaa0e02dcd234b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh) (094e30d) will **decrease** coverage by `0.20%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/graphs/tree.svg?width=650&height=150&src=pr&token=Zh9J7b4la2&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh)](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh)

```diff
@@             Coverage Diff             @@
##           develop     #715      +/-   ##
===========================================
- Coverage    87.13%   86.92%   -0.21%     
===========================================
  Files          117      118       +1     
  Lines         5285     5300      +15     
  Branches       421      421              
===========================================
+ Hits          4605     4607       +2     
- Misses         596      600       +4     
- Partials        84       93       +9     
```

| Flag | Coverage Δ | |
|---|---|---|
| pytest | `86.92% <100.00%> (-0.06%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh) | Coverage Δ | |
|---|---|---|
| [proxy/common/\_version.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-cHJveHkvY29tbW9uL192ZXJzaW9uLnB5) | `100.00% <100.00%> (ø)` | |
| [proxy/common/version.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-cHJveHkvY29tbW9uL3ZlcnNpb24ucHk=) | `100.00% <100.00%> (ø)` | |
| [proxy/common/types.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-cHJveHkvY29tbW9uL3R5cGVzLnB5) | `86.66% <0.00%> (-13.34%)` | :arrow_down: |
| [tests/test\_set\_open\_file\_limit.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-dGVzdHMvdGVzdF9zZXRfb3Blbl9maWxlX2xpbWl0LnB5) | `96.29% <0.00%> (-3.71%)` | :arrow_down: |
| [tests/testing/test\_embed.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-dGVzdHMvdGVzdGluZy90ZXN0X2VtYmVkLnB5) | `91.17% <0.00%> (-2.95%)` | :arrow_down: |
| [proxy/common/constants.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-cHJveHkvY29tbW9uL2NvbnN0YW50cy5weQ==) | `97.72% <0.00%> (-2.28%)` | :arrow_down: |
| [proxy/testing/test\_case.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-cHJveHkvdGVzdGluZy90ZXN0X2Nhc2UucHk=) | `98.00% <0.00%> (-2.00%)` | :arrow_down: |
| [proxy/common/utils.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-cHJveHkvY29tbW9uL3V0aWxzLnB5) | `91.86% <0.00%> (-1.63%)` | :arrow_down: |
| [proxy/common/flag.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-cHJveHkvY29tbW9uL2ZsYWcucHk=) | `92.00% <0.00%> (-1.60%)` | :arrow_down: |
| [tests/common/test\_flags.py](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh#diff-dGVzdHMvY29tbW9uL3Rlc3RfZmxhZ3MucHk=) | `98.63% <0.00%> (-1.37%)` | :arrow_down: |
| ... and [3 more](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh). Last update [094e30d...21ce532](https://codecov.io/gh/abhinavsingh/proxy.py/pull/715?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Abhinav+Singh).

webknjaz: > I am yet to check the follow-up PR. You may have addressed this already there.

That PR focuses on adding a trigger for cutting releases from GH UI and connecting that to jobs that would perform actual publishing to PyPI. It's incomplete IIRC. I'll undraft it once this one is merged.

> But another question that comes to mind, how do we remove `.dev*` suffix for stable releases, so that `PyPi` release is `vX.Y.Z` instead of `vX.Y.Z.dev`

That suffix is only added to non-tagged commits. If you tag the current commit, that tag will be used exactly as it is.

Patch:
diff --git a/.dockerignore b/.dockerignore
index d1ad0ba..3483deb 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -2,6 +2,7 @@
 **
 
 # Except proxy
+!.git
 !proxy
 !requirements.txt
 !pyproject.toml
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 1770e66..fc00d93 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 4c176f8..0f37fda 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 2c17910..f99e5fd 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 0000000..7d536ec
--- /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 0000000..deb2e36
--- /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 0000000..b1e36e6
--- /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 5635e7a..c6191df 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 62b4b84..6ac5005 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 0c4fc95..ae95ad7 100644
--- a/requirements-release.txt
+++ b/requirements-release.txt
@@ -1,1 +1,2 @@
-twine==3.5.0
\ No newline at end of file
+setuptools-scm == 6.3.2
+twine==3.5.0


Test patch:
diff --git a/.github/workflows/test-docker.yml b/.github/workflows/test-docker.yml
index ee30eaa..e55de49 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