Skip to content

Commit 897c4cc

Browse files
authored
Merge pull request #10 from mbdevpl/feature/support-packaging-with-numeric-git-hash
Support packaging with numeric-only git hash
2 parents 590d003 + 2ac02da commit 897c4cc

File tree

12 files changed

+46
-45
lines changed

12 files changed

+46
-45
lines changed

.github/workflows/python.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest, macos-latest, windows-latest]
15-
python-version: ['3.8', '3.9', '3.10']
15+
python-version: ['3.9', '3.10', '3.11']
1616

1717
steps:
1818
- uses: actions/checkout@v3
@@ -29,6 +29,7 @@ jobs:
2929
- run: cd ../argunparse && pip install -r requirements_test.txt && python setup.py build && cd -
3030
- run: git clone https://github.com/python-semver/python-semver ../semver
3131
- run: cd ../semver && python -m build && cd -
32+
- run: pip install jupyter # example package that uses metadata.json
3233
- run: python -m coverage run --branch --source . -m unittest -v
3334
- run: python -m coverage run --append --branch --source . -m unittest -v test.test_version
3435
env:
@@ -45,7 +46,7 @@ jobs:
4546
fetch-depth: 0
4647
- uses: actions/setup-python@v4
4748
with:
48-
python-version: '3.10'
49+
python-version: '3.11'
4950
architecture: x64
5051
- run: pip install -r requirements_test.txt
5152
- run: python setup.py bdist_wheel sdist

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG PYTHON_VERSION="3.10"
1+
ARG PYTHON_VERSION="3.11"
22

33
FROM python:${PYTHON_VERSION}
44

@@ -71,6 +71,6 @@ RUN set -Eeuxo pipefail && \
7171
cd semver && \
7272
python -m build && \
7373
cd - && \
74-
pip install jupyter
74+
pip install jupyter # example package that uses metadata.json
7575

7676
WORKDIR /home/user/version-query

Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pipeline {
2121
axes {
2222
axis {
2323
name 'PYTHON_VERSION'
24-
values '3.8', '3.9', '3.10'
24+
values '3.9', '3.10', '3.11'
2525
}
2626
}
2727

@@ -38,7 +38,7 @@ pipeline {
3838

3939
stage('Lint') {
4040
when {
41-
environment name: 'PYTHON_VERSION', value: '3.10'
41+
environment name: 'PYTHON_VERSION', value: '3.11'
4242
}
4343
steps {
4444
sh """#!/usr/bin/env bash
@@ -66,7 +66,7 @@ pipeline {
6666

6767
stage('Coverage') {
6868
when {
69-
environment name: 'PYTHON_VERSION', value: '3.10'
69+
environment name: 'PYTHON_VERSION', value: '3.11'
7070
}
7171
steps {
7272
sh '''#!/usr/bin/env bash

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version-query
2-
Copyright (c) 2017-2022 Mateusz Bysiek https://mbdevpl.github.io/
2+
Copyright (c) 2017-2023 Mateusz Bysiek https://mbdevpl.github.io/
33
Copyright (c) 2020 John Vandenberg https://github.com/jayvdb
44

55
Licensed under the Apache License, Version 2.0 (the "License");

README.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Examples of valid version tags:
195195
* ``v1.0``
196196
* ``v0.16.0``
197197
* ``v1.0.dev3``
198-
* ``ver0.5.1-4.0.0+a1de3012``
198+
* ``ver0.5.1-4.0.0+gita1de3012``
199199
* ``42.0``
200200
* ``3.14-15``
201201

@@ -240,8 +240,8 @@ the current commit and the most recent version tag.
240240

241241
Additionally, the ``<patch>`` version component is incremented by ``1``.
242242

243-
Additionally, a plus (``+``) character and the first 8 characters of SHA of the latest commit
244-
are appended to version identifier, e.g. ``+a3014fe0``.
243+
Additionally, a plus (``+``) character, word ``git`` and the first 8 characters of SHA
244+
of the latest commit are appended to version identifier, e.g. ``+gita3014fe0``.
245245

246246

247247
Repository index status
@@ -256,16 +256,16 @@ of the repository:
256256

257257
* Most recent version tag is ``v0.4.5``, there were 2 commits since,
258258
latest having SHA starting with ``812f12ea``.
259-
Version identifier will be ``0.4.6.dev2+812f12ea``.
259+
Version identifier will be ``0.4.6.dev2+git812f12ea``.
260260

261261
* Most recent version tag is ``ver6.0``, and there was 1 commit since
262262
having SHA starting with ``e10ac365``.
263-
Version identifier will be ``6.0.1.dev1+e10ac365``.
263+
Version identifier will be ``6.0.1.dev1+gite10ac365``.
264264

265265
* Most recent version tag is ``v9``, there were 40 commit since,
266266
latest having SHA starting with ``1ad22355``, the repository has uncommitted changes and
267267
version was queried at 19:52.20, 8th June 2017.
268-
the result is ``9.0.1.dev40+1ad22355.dirty20170608195220``.
268+
the result is ``9.0.1.dev40+git1ad22355.dirty20170608195220``.
269269

270270

271271
How exactly version numbers are compared
@@ -436,7 +436,7 @@ using version-query without any issues.
436436
Requirements
437437
============
438438

439-
Python version 3.8 or later.
439+
Python version 3.9 or later.
440440

441441
Python libraries as specified in `<requirements.txt>`_.
442442

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
GitPython ~= 3.1
2-
packaging >= 21.0
2+
packaging >= 23.0
33
semver ~= 2.13
4-
setuptools >= 60.4
4+
setuptools >= 67.4

requirements_ci.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
build ~= 0.10
22
codecov ~= 2.1
3-
coverage ~= 6.2
4-
flake518 ~= 1.2
5-
mypy ~= 0.930
6-
pydocstyle ~= 6.1
7-
pylint ~= 2.12
8-
types-docutils ~= 0.17
9-
types-setuptools ~= 57.4
3+
coverage ~= 7.2
4+
flake518 ~= 1.5
5+
mypy ~= 1.1
6+
pydocstyle ~= 6.3
7+
pylint ~= 2.17
8+
types-docutils ~= 0.19
9+
types-setuptools ~= 67.4
1010
-r requirements_test.txt

requirements_test.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
colorlog ~= 6.6
2-
docutils >= 0.18
3-
pip >= 21.0
4-
Pygments >= 2.5
5-
wheel >= 0.37
1+
colorlog ~= 6.7
2+
docutils ~= 0.19
3+
pip >= 23.0
4+
Pygments ~= 2.14
5+
wheel >= 0.40
66
-r requirements.txt

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class Package(setup_boilerplate.Package):
2020
'Operating System :: MacOS :: MacOS X',
2121
'Operating System :: Microsoft :: Windows',
2222
'Operating System :: POSIX :: Linux',
23-
'Programming Language :: Python :: 3.8',
2423
'Programming Language :: Python :: 3.9',
2524
'Programming Language :: Python :: 3.10',
25+
'Programming Language :: Python :: 3.11',
2626
'Programming Language :: Python :: 3 :: Only',
2727
'Topic :: Software Development :: Version Control',
2828
'Topic :: Software Development :: Version Control :: Git',

test/test_git.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_no_tags(self):
3535
with self.assertRaises(ValueError):
3636
query_git_repo(self.repo_path)
3737
version = predict_git_repo(self.repo_path)
38-
self.assertEqual(version.to_str(), f'0.1.0.dev{i}+{self.repo_head_hexsha}')
38+
self.assertEqual(version.to_str(), f'0.1.0.dev{i}+git{self.repo_head_hexsha}')
3939

4040
def test_only_nonversion_tags(self):
4141
for i in range(1, 5):
@@ -44,7 +44,7 @@ def test_only_nonversion_tags(self):
4444
with self.assertRaises(ValueError):
4545
query_git_repo(self.repo_path)
4646
version = predict_git_repo(self.repo_path)
47-
self.assertEqual(version.to_str(), f'0.1.0.dev{i}+{self.repo_head_hexsha}')
47+
self.assertEqual(version.to_str(), f'0.1.0.dev{i}+git{self.repo_head_hexsha}')
4848

4949
def test_inconsistent_tag_prefix(self):
5050
version = Version.from_str('1.0')
@@ -70,7 +70,7 @@ def test_nonversion_tags(self):
7070
upcoming_version = predict_git_repo(self.repo_path)
7171
version.increment(VersionComponent.Patch, 1)
7272
version.increment(VersionComponent.DevPatch, 2)
73-
version.local = (self.repo_head_hexsha,)
73+
version.local = (f'git{self.repo_head_hexsha}',)
7474
self.assertEqual(version, upcoming_version)
7575

7676
def test_too_long_no_tag(self):
@@ -103,7 +103,7 @@ def test_nonversion_merged_branches(self):
103103
with self.assertRaises(ValueError):
104104
query_git_repo(self.repo_path)
105105
upcoming_version = predict_git_repo(self.repo_path)
106-
self.assertEqual(upcoming_version.to_str(), f'0.1.0.dev6+{self.repo_head_hexsha}')
106+
self.assertEqual(upcoming_version.to_str(), f'0.1.0.dev6+git{self.repo_head_hexsha}')
107107

108108
def test_invalid_version_tags(self):
109109
for i in range(1, 3):
@@ -116,7 +116,7 @@ def test_invalid_version_tags(self):
116116
self.assertEqual(current_version.to_str(), f'{i}.0.0')
117117
upcoming_version = predict_git_repo(self.repo_path)
118118
current_version.devel_increment(1)
119-
current_version.local = (self.repo_head_hexsha,)
119+
current_version.local = (f'git{self.repo_head_hexsha}',)
120120
self.assertEqual(current_version, upcoming_version)
121121

122122
def test_dirty_repo(self):
@@ -133,9 +133,9 @@ def test_dirty_repo(self):
133133
self.assertLess(version, upcoming_version)
134134
if new_commit:
135135
current_version.devel_increment(1)
136-
current_version.local = (self.repo_head_hexsha,)
136+
current_version.local = (f'git{self.repo_head_hexsha}',)
137137
self.assertTupleEqual(current_version.local, upcoming_version.local[:1])
138-
local_prefix = f'+{self.repo_head_hexsha}.dirty'
138+
local_prefix = f'+git{self.repo_head_hexsha}.dirty'
139139
else:
140140
local_prefix = '+dirty'
141141
self.assertTrue(upcoming_version.local_to_str().startswith(local_prefix),
@@ -157,12 +157,12 @@ def test_nonlatest_commit(self):
157157
current_version = query_git_repo(self.repo_path)
158158
self.assertEqual(current_version.to_str(), '0.1.0')
159159
upcoming_version = predict_git_repo(self.repo_path)
160-
self.assertEqual(upcoming_version.to_str(), f'0.1.1.dev1+{self.repo_head_hexsha}')
160+
self.assertEqual(upcoming_version.to_str(), f'0.1.1.dev1+git{self.repo_head_hexsha}')
161161
self.repo.git.checkout('devel')
162162
current_version = query_git_repo(self.repo_path)
163163
self.assertEqual(current_version.to_str(), '0.2.0')
164164
upcoming_version = predict_git_repo(self.repo_path)
165-
self.assertEqual(upcoming_version.to_str(), f'0.2.1.dev1+{self.repo_head_hexsha}')
165+
self.assertEqual(upcoming_version.to_str(), f'0.2.1.dev1+git{self.repo_head_hexsha}')
166166

167167
def test_tags_on_merged_branches(self):
168168
self.git_commit_new_file()
@@ -182,7 +182,7 @@ def test_tags_on_merged_branches(self):
182182
current_version = query_git_repo(self.repo_path)
183183
self.assertEqual(current_version.to_str(), '0.2.0')
184184
upcoming_version = predict_git_repo(self.repo_path)
185-
self.assertEqual(upcoming_version.to_str(), f'0.2.1.dev5+{self.repo_head_hexsha}')
185+
self.assertEqual(upcoming_version.to_str(), f'0.2.1.dev5+git{self.repo_head_hexsha}')
186186

187187
def test_tag_on_merged_branch(self):
188188
self.git_commit_new_file()
@@ -196,7 +196,7 @@ def test_tag_on_merged_branch(self):
196196
current_version = query_git_repo(self.repo_path)
197197
self.assertEqual(current_version.to_str(), '1.0.0')
198198
upcoming_version = predict_git_repo(self.repo_path)
199-
self.assertEqual(upcoming_version.to_str(), f'1.0.1.dev1+{self.repo_head_hexsha}')
199+
self.assertEqual(upcoming_version.to_str(), f'1.0.1.dev1+git{self.repo_head_hexsha}')
200200

201201
def test_many_versions_on_one_commit(self):
202202
self.git_commit_new_file()
@@ -207,7 +207,7 @@ def test_many_versions_on_one_commit(self):
207207
current_version = query_git_repo(self.repo_path)
208208
self.assertEqual(current_version.to_str(), '0.3.0')
209209
upcoming_version = predict_git_repo(self.repo_path)
210-
self.assertEqual(upcoming_version.to_str(), f'0.3.1.dev1+{self.repo_head_hexsha}')
210+
self.assertEqual(upcoming_version.to_str(), f'0.3.1.dev1+git{self.repo_head_hexsha}')
211211

212212
def test_version_decreased(self):
213213
self.git_commit_new_file()
@@ -218,4 +218,4 @@ def test_version_decreased(self):
218218
current_version = query_git_repo(self.repo_path)
219219
self.assertEqual(current_version.to_str(), '0.1.0')
220220
upcoming_version = predict_git_repo(self.repo_path)
221-
self.assertEqual(upcoming_version.to_str(), f'0.1.1.dev1+{self.repo_head_hexsha}')
221+
self.assertEqual(upcoming_version.to_str(), f'0.1.1.dev1+git{self.repo_head_hexsha}')

0 commit comments

Comments
 (0)