From 8460f2ab93eabfe5d3cf003e842a81cb332c130a Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Fri, 17 Mar 2023 11:29:48 +0900 Subject: [PATCH 1/8] fix: avoid rare commit sha issue discovered in scoville/axistool#34 --- test/test_git.py | 26 +++++++++++++------------- version_query/git_query.py | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/test_git.py b/test/test_git.py index 2865149..78a3f64 100644 --- a/test/test_git.py +++ b/test/test_git.py @@ -35,7 +35,7 @@ def test_no_tags(self): with self.assertRaises(ValueError): query_git_repo(self.repo_path) version = predict_git_repo(self.repo_path) - self.assertEqual(version.to_str(), f'0.1.0.dev{i}+{self.repo_head_hexsha}') + self.assertEqual(version.to_str(), f'0.1.0.dev{i}+git{self.repo_head_hexsha}') def test_only_nonversion_tags(self): for i in range(1, 5): @@ -44,7 +44,7 @@ def test_only_nonversion_tags(self): with self.assertRaises(ValueError): query_git_repo(self.repo_path) version = predict_git_repo(self.repo_path) - self.assertEqual(version.to_str(), f'0.1.0.dev{i}+{self.repo_head_hexsha}') + self.assertEqual(version.to_str(), f'0.1.0.dev{i}+git{self.repo_head_hexsha}') def test_inconsistent_tag_prefix(self): version = Version.from_str('1.0') @@ -70,7 +70,7 @@ def test_nonversion_tags(self): upcoming_version = predict_git_repo(self.repo_path) version.increment(VersionComponent.Patch, 1) version.increment(VersionComponent.DevPatch, 2) - version.local = (self.repo_head_hexsha,) + version.local = (f'git{self.repo_head_hexsha}',) self.assertEqual(version, upcoming_version) def test_too_long_no_tag(self): @@ -103,7 +103,7 @@ def test_nonversion_merged_branches(self): with self.assertRaises(ValueError): query_git_repo(self.repo_path) upcoming_version = predict_git_repo(self.repo_path) - self.assertEqual(upcoming_version.to_str(), f'0.1.0.dev6+{self.repo_head_hexsha}') + self.assertEqual(upcoming_version.to_str(), f'0.1.0.dev6+git{self.repo_head_hexsha}') def test_invalid_version_tags(self): for i in range(1, 3): @@ -116,7 +116,7 @@ def test_invalid_version_tags(self): self.assertEqual(current_version.to_str(), f'{i}.0.0') upcoming_version = predict_git_repo(self.repo_path) current_version.devel_increment(1) - current_version.local = (self.repo_head_hexsha,) + current_version.local = (f'git{self.repo_head_hexsha}',) self.assertEqual(current_version, upcoming_version) def test_dirty_repo(self): @@ -133,9 +133,9 @@ def test_dirty_repo(self): self.assertLess(version, upcoming_version) if new_commit: current_version.devel_increment(1) - current_version.local = (self.repo_head_hexsha,) + current_version.local = (f'git{self.repo_head_hexsha}',) self.assertTupleEqual(current_version.local, upcoming_version.local[:1]) - local_prefix = f'+{self.repo_head_hexsha}.dirty' + local_prefix = f'+git{self.repo_head_hexsha}.dirty' else: local_prefix = '+dirty' self.assertTrue(upcoming_version.local_to_str().startswith(local_prefix), @@ -157,12 +157,12 @@ def test_nonlatest_commit(self): current_version = query_git_repo(self.repo_path) self.assertEqual(current_version.to_str(), '0.1.0') upcoming_version = predict_git_repo(self.repo_path) - self.assertEqual(upcoming_version.to_str(), f'0.1.1.dev1+{self.repo_head_hexsha}') + self.assertEqual(upcoming_version.to_str(), f'0.1.1.dev1+git{self.repo_head_hexsha}') self.repo.git.checkout('devel') current_version = query_git_repo(self.repo_path) self.assertEqual(current_version.to_str(), '0.2.0') upcoming_version = predict_git_repo(self.repo_path) - self.assertEqual(upcoming_version.to_str(), f'0.2.1.dev1+{self.repo_head_hexsha}') + self.assertEqual(upcoming_version.to_str(), f'0.2.1.dev1+git{self.repo_head_hexsha}') def test_tags_on_merged_branches(self): self.git_commit_new_file() @@ -182,7 +182,7 @@ def test_tags_on_merged_branches(self): current_version = query_git_repo(self.repo_path) self.assertEqual(current_version.to_str(), '0.2.0') upcoming_version = predict_git_repo(self.repo_path) - self.assertEqual(upcoming_version.to_str(), f'0.2.1.dev5+{self.repo_head_hexsha}') + self.assertEqual(upcoming_version.to_str(), f'0.2.1.dev5+git{self.repo_head_hexsha}') def test_tag_on_merged_branch(self): self.git_commit_new_file() @@ -196,7 +196,7 @@ def test_tag_on_merged_branch(self): current_version = query_git_repo(self.repo_path) self.assertEqual(current_version.to_str(), '1.0.0') upcoming_version = predict_git_repo(self.repo_path) - self.assertEqual(upcoming_version.to_str(), f'1.0.1.dev1+{self.repo_head_hexsha}') + self.assertEqual(upcoming_version.to_str(), f'1.0.1.dev1+git{self.repo_head_hexsha}') def test_many_versions_on_one_commit(self): self.git_commit_new_file() @@ -207,7 +207,7 @@ def test_many_versions_on_one_commit(self): current_version = query_git_repo(self.repo_path) self.assertEqual(current_version.to_str(), '0.3.0') upcoming_version = predict_git_repo(self.repo_path) - self.assertEqual(upcoming_version.to_str(), f'0.3.1.dev1+{self.repo_head_hexsha}') + self.assertEqual(upcoming_version.to_str(), f'0.3.1.dev1+git{self.repo_head_hexsha}') def test_version_decreased(self): self.git_commit_new_file() @@ -218,4 +218,4 @@ def test_version_decreased(self): current_version = query_git_repo(self.repo_path) self.assertEqual(current_version.to_str(), '0.1.0') upcoming_version = predict_git_repo(self.repo_path) - self.assertEqual(upcoming_version.to_str(), f'0.1.1.dev1+{self.repo_head_hexsha}') + self.assertEqual(upcoming_version.to_str(), f'0.1.1.dev1+git{self.repo_head_hexsha}') diff --git a/version_query/git_query.py b/version_query/git_query.py index 8d76f8d..7d37375 100644 --- a/version_query/git_query.py +++ b/version_query/git_query.py @@ -145,7 +145,7 @@ def predict_git_repo(repo_path: pathlib.Path, search_parent_directories: bool = assert isinstance(version, Version), version if commit_distance > 0: version.devel_increment(commit_distance) - version.local = (repo.head.commit.hexsha[:8],) + version.local = (f'git{repo.head.commit.hexsha[:8]}',) if is_repo_dirty: dt_ = f'dirty{datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S")}' if version.has_local: From af3cee40676e70d6e5f4102a3e0e2c9ba8cea7ee Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Fri, 17 Mar 2023 11:30:01 +0900 Subject: [PATCH 2/8] chore: refresh requirements --- requirements.txt | 4 ++-- requirements_ci.txt | 14 +++++++------- requirements_test.txt | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/requirements.txt b/requirements.txt index 210435c..e731f4b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ GitPython ~= 3.1 -packaging >= 21.0 +packaging >= 23.0 semver ~= 2.13 -setuptools >= 60.4 +setuptools >= 67.4 diff --git a/requirements_ci.txt b/requirements_ci.txt index ae9cda1..866fd9c 100644 --- a/requirements_ci.txt +++ b/requirements_ci.txt @@ -1,10 +1,10 @@ build ~= 0.10 codecov ~= 2.1 -coverage ~= 6.2 -flake518 ~= 1.2 -mypy ~= 0.930 -pydocstyle ~= 6.1 -pylint ~= 2.12 -types-docutils ~= 0.17 -types-setuptools ~= 57.4 +coverage ~= 7.2 +flake518 ~= 1.5 +mypy ~= 1.1 +pydocstyle ~= 6.3 +pylint ~= 2.17 +types-docutils ~= 0.19 +types-setuptools ~= 67.4 -r requirements_test.txt diff --git a/requirements_test.txt b/requirements_test.txt index 3387323..7c94ed0 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,6 +1,6 @@ -colorlog ~= 6.6 -docutils >= 0.18 -pip >= 21.0 -Pygments >= 2.5 -wheel >= 0.37 +colorlog ~= 6.7 +docutils ~= 0.19 +pip >= 23.0 +Pygments ~= 2.14 +wheel >= 0.40 -r requirements.txt From 0cda4aeb92befb997a1f1b61997bfcdb99d7b38b Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Fri, 17 Mar 2023 12:39:12 +0900 Subject: [PATCH 3/8] chore: update copyright year --- NOTICE | 2 +- version_query/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NOTICE b/NOTICE index 0483763..dcdd4de 100644 --- a/NOTICE +++ b/NOTICE @@ -1,5 +1,5 @@ version-query -Copyright (c) 2017-2022 Mateusz Bysiek https://mbdevpl.github.io/ +Copyright (c) 2017-2023 Mateusz Bysiek https://mbdevpl.github.io/ Copyright (c) 2020 John Vandenberg https://github.com/jayvdb Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/version_query/main.py b/version_query/main.py index 81f7cad..9c0afe1 100644 --- a/version_query/main.py +++ b/version_query/main.py @@ -24,7 +24,7 @@ def main(args=None, namespace=None) -> None: prog='version_query', description='''Tool for querying current versions of Python packages. Use LOGGING_LEVEL environment variable to adjust logging level.''', - epilog='''Copyright 2017-2022 by the contributors, Apache License 2.0, + epilog='''Copyright 2017-2023 by the contributors, Apache License 2.0, https://github.com/mbdevpl/version-query''', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-i', '--increment', action='store_true', help='''output version string for From ce2f2ca24d536ed8f81c1be835095675913c0691 Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Fri, 17 Mar 2023 12:40:51 +0900 Subject: [PATCH 4/8] build: require Python 3.9+ and test on 3.11 --- .github/workflows/python.yml | 4 ++-- Dockerfile | 2 +- Jenkinsfile | 4 ++-- README.rst | 2 +- setup.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index d08d3f4..44425ac 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.8', '3.9', '3.10'] + python-version: ['3.9', '3.10', '3.11'] steps: - uses: actions/checkout@v3 @@ -45,7 +45,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11' architecture: x64 - run: pip install -r requirements_test.txt - run: python setup.py bdist_wheel sdist diff --git a/Dockerfile b/Dockerfile index eb21eb8..5c47cc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG PYTHON_VERSION="3.10" +ARG PYTHON_VERSION="3.11" FROM python:${PYTHON_VERSION} diff --git a/Jenkinsfile b/Jenkinsfile index 280d976..ce6d8ea 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { axes { axis { name 'PYTHON_VERSION' - values '3.8', '3.9', '3.10' + values '3.9', '3.10', '3.11' } } @@ -38,7 +38,7 @@ pipeline { stage('Lint') { when { - environment name: 'PYTHON_VERSION', value: '3.10' + environment name: 'PYTHON_VERSION', value: '3.11' } steps { sh """#!/usr/bin/env bash diff --git a/README.rst b/README.rst index 2ef514f..58e8854 100644 --- a/README.rst +++ b/README.rst @@ -436,7 +436,7 @@ using version-query without any issues. Requirements ============ -Python version 3.8 or later. +Python version 3.9 or later. Python libraries as specified in ``_. diff --git a/setup.py b/setup.py index bc440d8..1fef1ee 100644 --- a/setup.py +++ b/setup.py @@ -20,9 +20,9 @@ class Package(setup_boilerplate.Package): 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3 :: Only', 'Topic :: Software Development :: Version Control', 'Topic :: Software Development :: Version Control :: Git', From 0d0658c129f02c1013f5d99f28bffa1d1fb5cd8f Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Fri, 17 Mar 2023 13:52:23 +0900 Subject: [PATCH 5/8] docs: update readme --- README.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 58e8854..e236618 100644 --- a/README.rst +++ b/README.rst @@ -195,7 +195,7 @@ Examples of valid version tags: * ``v1.0`` * ``v0.16.0`` * ``v1.0.dev3`` -* ``ver0.5.1-4.0.0+a1de3012`` +* ``ver0.5.1-4.0.0+gita1de3012`` * ``42.0`` * ``3.14-15`` @@ -240,8 +240,8 @@ the current commit and the most recent version tag. Additionally, the ```` version component is incremented by ``1``. -Additionally, a plus (``+``) character and the first 8 characters of SHA of the latest commit -are appended to version identifier, e.g. ``+a3014fe0``. +Additionally, a plus (``+``) character, word ``git`` and the first 8 characters of SHA +of the latest commit are appended to version identifier, e.g. ``+gita3014fe0``. Repository index status @@ -256,16 +256,16 @@ of the repository: * Most recent version tag is ``v0.4.5``, there were 2 commits since, latest having SHA starting with ``812f12ea``. - Version identifier will be ``0.4.6.dev2+812f12ea``. + Version identifier will be ``0.4.6.dev2+git812f12ea``. * Most recent version tag is ``ver6.0``, and there was 1 commit since having SHA starting with ``e10ac365``. - Version identifier will be ``6.0.1.dev1+e10ac365``. + Version identifier will be ``6.0.1.dev1+gite10ac365``. * Most recent version tag is ``v9``, there were 40 commit since, latest having SHA starting with ``1ad22355``, the repository has uncommitted changes and version was queried at 19:52.20, 8th June 2017. - the result is ``9.0.1.dev40+1ad22355.dirty20170608195220``. + the result is ``9.0.1.dev40+git1ad22355.dirty20170608195220``. How exactly version numbers are compared From 2f1c59ad17d816fd787a94930ab0c2de914318a1 Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Fri, 17 Mar 2023 17:10:06 +0900 Subject: [PATCH 6/8] test: install package that uses metadata.json --- .github/workflows/python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 44425ac..dbb1fe9 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -29,6 +29,7 @@ jobs: - run: cd ../argunparse && pip install -r requirements_test.txt && python setup.py build && cd - - run: git clone https://github.com/python-semver/python-semver ../semver - run: cd ../semver && python -m build && cd - + - run: pip install jupyter - run: python -m coverage run --branch --source . -m unittest -v - run: python -m coverage run --append --branch --source . -m unittest -v test.test_version env: From f47bda8a2ac61796981512e9de1315ec371fc47c Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Fri, 17 Mar 2023 17:33:15 +0900 Subject: [PATCH 7/8] build(jenkins): use same Python version for codecov and linting --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ce6d8ea..dd95250 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,7 +66,7 @@ pipeline { stage('Coverage') { when { - environment name: 'PYTHON_VERSION', value: '3.10' + environment name: 'PYTHON_VERSION', value: '3.11' } steps { sh '''#!/usr/bin/env bash From 2ac02da4f2f38f25f5d66bcdf7cda4ad68e3c48a Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Fri, 17 Mar 2023 17:33:50 +0900 Subject: [PATCH 8/8] chore: mention why we install jupyter --- .github/workflows/python.yml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index dbb1fe9..bead931 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -29,7 +29,7 @@ jobs: - run: cd ../argunparse && pip install -r requirements_test.txt && python setup.py build && cd - - run: git clone https://github.com/python-semver/python-semver ../semver - run: cd ../semver && python -m build && cd - - - run: pip install jupyter + - run: pip install jupyter # example package that uses metadata.json - run: python -m coverage run --branch --source . -m unittest -v - run: python -m coverage run --append --branch --source . -m unittest -v test.test_version env: diff --git a/Dockerfile b/Dockerfile index 5c47cc3..fe66098 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,6 +71,6 @@ RUN set -Eeuxo pipefail && \ cd semver && \ python -m build && \ cd - && \ - pip install jupyter + pip install jupyter # example package that uses metadata.json WORKDIR /home/user/version-query