From 908ead2958846380343e0d43f6c5d5a2bf13bcc0 Mon Sep 17 00:00:00 2001 From: arielev Date: Sat, 9 Mar 2024 11:08:21 +0200 Subject: [PATCH 1/8] drop (official) support for python 3.6 --- .github/workflows/pythonpackage.yml | 17 ++++++++++------- Dockerfile | 2 +- setup.py | 4 ++-- src/pybump_version.py | 2 +- test/test_content_files/VERSION | 2 +- test/test_content_files/test_valid_chart.yaml | 4 ++-- test/test_content_files/test_valid_setup.py | 2 +- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index efabc2b..dc5c757 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -26,7 +26,10 @@ jobs: strategy: max-parallel: 2 matrix: - python-version: ["3.9", "3.11"] + python-version: + - "3.7" # EOL 2023-06-27 + - "3.9" + - "3.12" steps: - uses: actions/checkout@v4 @@ -38,16 +41,16 @@ jobs: - name: Lint with flake8 run: | - pip install flake8==5.0.4 + pip install flake8==7.0.0 # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=venv + flake8 . --count --show-source --statistics --exclude=venv # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=venv - name: Test with unittest (codecov) run: | pip install -r requirements.txt - pip install coverage==6.5 + pip install coverage==7.4 # discover all tests in the test directory coverage run --omit 'venv/*' -m unittest discover test -vv -t . @@ -80,7 +83,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '3.12' - name: Check distribution valid and test publish run: | pip install wheel twine @@ -106,7 +109,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '3.12' - name: Bump version using self app id: app_version_bump run: | @@ -166,7 +169,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '3.12' # currently there is no way of passing data between jobs except using artifact, # this might be an option, but just do another bump for now, # and anyway setup.py file will need to have some change since we checked out again diff --git a/Dockerfile b/Dockerfile index b68710a..ce22d8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-slim +FROM python:3.12-slim LABEL maintainer="Arie Lev " \ description="Python version bumper" diff --git a/setup.py b/setup.py index cf27ef6..4da99ef 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setuptools.setup( name="pybump", - version="1.11.6", + version="1.12.0", author="Arie Lev", author_email="levinsonarie@gmail.com", description="Python version bumper", @@ -24,12 +24,12 @@ install_requires=requirements, classifiers=[ "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", ], diff --git a/src/pybump_version.py b/src/pybump_version.py index f687c36..5b62bec 100644 --- a/src/pybump_version.py +++ b/src/pybump_version.py @@ -28,7 +28,7 @@ def validate_semantic_string(self, version): """ orig_version = version # only if passed version is non-empty string - if type(version) == str and len(version) != 0: + if isinstance(version, str) and len(version) != 0: # In case the version if of type 'v2.2.5' then save 'v' prefix and cut it for further 'semver' validation if version[0] == 'v': version = version[1:] diff --git a/test/test_content_files/VERSION b/test/test_content_files/VERSION index c11ef59..8c81cc9 100644 --- a/test/test_content_files/VERSION +++ b/test/test_content_files/VERSION @@ -1 +1 @@ -2.5.1+metadata.here \ No newline at end of file +3.0.0+metadata.here \ No newline at end of file diff --git a/test/test_content_files/test_valid_chart.yaml b/test/test_content_files/test_valid_chart.yaml index 88d36d5..3f93f68 100644 --- a/test/test_content_files/test_valid_chart.yaml +++ b/test/test_content_files/test_valid_chart.yaml @@ -1,8 +1,8 @@ # valid helm chart file # comments should stay here after YAML file handling apiVersion: v1 -appVersion: 2.0.3 -version: 0.1.0 # version key should stay here and not be sorted +appVersion: 1.0.0 +version: 1.0.0 # version key should stay here and not be sorted description: A Helm chart for Kubernetes name: test plainText: |- diff --git a/test/test_content_files/test_valid_setup.py b/test/test_content_files/test_valid_setup.py index 037d6d0..9c3e6f1 100644 --- a/test/test_content_files/test_valid_setup.py +++ b/test/test_content_files/test_valid_setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="pybump", - version="0.1.3", + version="1.0.1-aa2cfd71788ab67bc9b59e62dee2070765948e29", author="Arie Lev", author_email="levinsonarie@gmail.com", description="Python version bumper", From ab4c967da45f95780341fd70f21ff64b314f890d Mon Sep 17 00:00:00 2001 From: arielev Date: Sat, 9 Mar 2024 11:10:56 +0200 Subject: [PATCH 2/8] revert test files changes --- test/test_content_files/VERSION | 2 +- test/test_content_files/test_valid_chart.yaml | 4 ++-- test/test_content_files/test_valid_setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_content_files/VERSION b/test/test_content_files/VERSION index 8c81cc9..c11ef59 100644 --- a/test/test_content_files/VERSION +++ b/test/test_content_files/VERSION @@ -1 +1 @@ -3.0.0+metadata.here \ No newline at end of file +2.5.1+metadata.here \ No newline at end of file diff --git a/test/test_content_files/test_valid_chart.yaml b/test/test_content_files/test_valid_chart.yaml index 3f93f68..88d36d5 100644 --- a/test/test_content_files/test_valid_chart.yaml +++ b/test/test_content_files/test_valid_chart.yaml @@ -1,8 +1,8 @@ # valid helm chart file # comments should stay here after YAML file handling apiVersion: v1 -appVersion: 1.0.0 -version: 1.0.0 # version key should stay here and not be sorted +appVersion: 2.0.3 +version: 0.1.0 # version key should stay here and not be sorted description: A Helm chart for Kubernetes name: test plainText: |- diff --git a/test/test_content_files/test_valid_setup.py b/test/test_content_files/test_valid_setup.py index 9c3e6f1..037d6d0 100644 --- a/test/test_content_files/test_valid_setup.py +++ b/test/test_content_files/test_valid_setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="pybump", - version="1.0.1-aa2cfd71788ab67bc9b59e62dee2070765948e29", + version="0.1.3", author="Arie Lev", author_email="levinsonarie@gmail.com", description="Python version bumper", From 8218d0110f0bbadc0b199c8d95e7e2d7aa210166 Mon Sep 17 00:00:00 2001 From: arielev Date: Sat, 9 Mar 2024 11:13:36 +0200 Subject: [PATCH 3/8] CI minimal python version to 3.9 --- .github/workflows/pythonpackage.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index dc5c757..2cab956 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -27,8 +27,7 @@ jobs: max-parallel: 2 matrix: python-version: - - "3.7" # EOL 2023-06-27 - - "3.9" + - "3.9" # EOL 2025-10 - "3.12" steps: From d9a6ed45c3fbb34a29164e3768d9dbad6f85c5a2 Mon Sep 17 00:00:00 2001 From: arielev Date: Sat, 9 Mar 2024 14:45:46 +0200 Subject: [PATCH 4/8] deprecate pkg_resources / minimal python is 3.8 --- .github/workflows/pythonpackage.yml | 2 +- setup.py | 1 - src/pybump.py | 8 +++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 2cab956..8d096fc 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -27,7 +27,7 @@ jobs: max-parallel: 2 matrix: python-version: - - "3.9" # EOL 2025-10 + - "3.8" # EOL 2024-10 - "3.12" steps: diff --git a/setup.py b/setup.py index 4da99ef..f3a7ec4 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,6 @@ install_requires=requirements, classifiers=[ "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/src/pybump.py b/src/pybump.py index 4412f65..7b5e509 100644 --- a/src/pybump.py +++ b/src/pybump.py @@ -4,7 +4,6 @@ from sys import stderr from ruamel.yaml import YAML, YAMLError -from pkg_resources import get_distribution, DistributionNotFound try: from .pybump_version import PybumpVersion except ImportError: @@ -58,10 +57,9 @@ def get_self_version(dist_name): :param dist_name: string :return: version as string """ - try: - return get_distribution(dist_name).version - except DistributionNotFound: - return 'version not found' + # https://docs.python.org/3/library/importlib.metadata.html#distribution-versions + from importlib.metadata import version + return version(dist_name) def write_version_to_file(file_path, file_content, version, app_version): From ce5b91a9b044aa6eb6761404820079bab33e0c98 Mon Sep 17 00:00:00 2001 From: arielev Date: Sat, 9 Mar 2024 15:34:01 +0200 Subject: [PATCH 5/8] add ModuleNotFoundError exception for self version checks --- src/pybump.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pybump.py b/src/pybump.py index 7b5e509..5c65c75 100644 --- a/src/pybump.py +++ b/src/pybump.py @@ -4,6 +4,7 @@ from sys import stderr from ruamel.yaml import YAML, YAMLError + try: from .pybump_version import PybumpVersion except ImportError: @@ -57,9 +58,12 @@ def get_self_version(dist_name): :param dist_name: string :return: version as string """ - # https://docs.python.org/3/library/importlib.metadata.html#distribution-versions - from importlib.metadata import version - return version(dist_name) + try: + # https://docs.python.org/3/library/importlib.metadata.html#distribution-versions + from importlib.metadata import version + return version(dist_name) + except ModuleNotFoundError: + return 'version not found' def write_version_to_file(file_path, file_content, version, app_version): From 7fee4e3a137ac4487c3c72507ae84cae1ec13f9f Mon Sep 17 00:00:00 2001 From: arielev Date: Sat, 9 Mar 2024 15:42:58 +0200 Subject: [PATCH 6/8] make sure to explicitly install setuptools --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 8d096fc..7aadf7a 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -85,7 +85,7 @@ jobs: python-version: '3.12' - name: Check distribution valid and test publish run: | - pip install wheel twine + pip install wheel twine setuptools python setup.py bdist_wheel twine check dist/* twine upload dist/* --skip-existing From 291e63d3e56f3b1d0b863814233e4d87be142301 Mon Sep 17 00:00:00 2001 From: arielev Date: Sat, 9 Mar 2024 15:46:14 +0200 Subject: [PATCH 7/8] make sure to explicitly install setuptools --- .github/workflows/pythonpackage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 7aadf7a..70924e4 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -70,7 +70,7 @@ jobs: - name: Check distribution valid and test publish run: | - pip install wheel twine + pip install wheel twine setuptools python setup.py bdist_wheel twine check dist/* @@ -117,7 +117,7 @@ jobs: - name: Publish to global pypi run: | - pip install wheel twine + pip install wheel twine setuptools python setup.py bdist_wheel twine upload dist/* env: From 7d182729d5625509d026a4838fd6250398d9e51d Mon Sep 17 00:00:00 2001 From: arielev Date: Sat, 9 Mar 2024 16:44:06 +0200 Subject: [PATCH 8/8] add version test / exit code 0 --- test/test_simulate_pybump.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_simulate_pybump.py b/test/test_simulate_pybump.py index c138e89..66a5f78 100644 --- a/test/test_simulate_pybump.py +++ b/test/test_simulate_pybump.py @@ -325,3 +325,13 @@ def test_yaml_sort_comments_preservation(self): '- a\n' '- b\n' '- c\n') + + def test_package_version(self): + """ + Test case when user is passing the version flag + """ + # Verify valid string + completed_process_object = run(["python", "src/pybump.py", "--version"], + stdout=PIPE, stderr=PIPE) + self.assertIs(completed_process_object.returncode, 0, + msg="tested 'version' flag that should always return exist 0, even on exceptions")