From 2f752be6eb6a442ec7943e3f9594a57045cb286b Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Wed, 29 Nov 2023 10:11:00 +0100 Subject: [PATCH] WIP --- pyproject.toml | 2 +- src/datastation/common/version_info.py | 12 ++++++++---- src/tests/test_version_info.py | 20 ++++++++++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 118708f..eba00ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dans-datastation-tools" -version = "0.35.0" +version = "0.36.0" description = "Command line utilities for Data Station application management" authors = ["DANS-KNAW"] packages = [ diff --git a/src/datastation/common/version_info.py b/src/datastation/common/version_info.py index e64ff70..303df53 100644 --- a/src/datastation/common/version_info.py +++ b/src/datastation/common/version_info.py @@ -1,3 +1,4 @@ +import logging import os from re import match @@ -6,7 +7,7 @@ def rpm_qa(): return os.popen('rpm -qa') -evr_pattern = r'(?P.*?)-(?P\d+\.\d+\.\d+)-(?P\d+)' +evr_pattern = r'(?P.*?)-(?P\d+\.\d+\.\d+)-(?P[^\.]+)\.(?P.+)' payara_version_pattern = r'Thank you for downloading Payara Server (.*).' @@ -15,10 +16,15 @@ def get_rpm_versions(prefix): rpm_versions = {} for line in rpm_qa(): if line.startswith(prefix): + logging.debug(f'Found RPM matching prefix {prefix}: {line}') evr = match(evr_pattern, line) version = evr.group('version') module = evr.group('name') - rpm_versions[module] = version + release = evr.group('release') + # Adding the release part of the EVR is not very informative for DANS modules, + # because it is always 1 for releases, except for SNAPSHOTs, in which case it is + # important to know the exact SNAPSHOT version. + rpm_versions[module] = f'{version}-{release}' if release != '1' else f'{version}' return rpm_versions @@ -40,8 +46,6 @@ def get_dataverse_build_number(dataverse_application_path): def get_payara_version(payara_application_path): with open(os.path.join(payara_application_path, 'README.txt'), 'r') as f: - # Find first line that matches pattern line = next((line for line in f if match(payara_version_pattern, line)), None) - # get subgroup 1 of the match payara_version = match(payara_version_pattern, line).group(1) return payara_version diff --git a/src/tests/test_version_info.py b/src/tests/test_version_info.py index e46594b..64d4775 100644 --- a/src/tests/test_version_info.py +++ b/src/tests/test_version_info.py @@ -3,7 +3,7 @@ from datastation.common.version_info import get_rpm_versions, get_dataverse_version, get_payara_version -def test_some_modules_with_matching_prefix_found(): +def test_get_rpm_modules_should_filter_out_packages_with_no_matching_prefix(): with patch('datastation.common.version_info.rpm_qa') as mock_qa: mock_qa.return_value = ['dans.knaw.nl-dd-vault-metadata-2.2.0-1.noarch', 'dans.knaw.nl-dans-schema-0.10.0-1.noarch', @@ -18,13 +18,29 @@ def test_some_modules_with_matching_prefix_found(): } -def test_no_matching_modules_found(): +def test_get_rpm_modules_should_return_empty_dictionary_if_no_packages_matched_prefix(): with patch('datastation.common.version_info.rpm_qa') as mock_qa: mock_qa.return_value = ['python3-rpm-generators-5-8.el8.noarch'] versions = get_rpm_versions('dans.knaw.nl-') assert versions == {} +def test_get_rpm_modules_should_accept_non_digits_in_release_part_of_evr(): + with patch('datastation.common.version_info.rpm_qa') as mock_qa: + mock_qa.return_value = ['dans.knaw.nl-dd-vault-metadata-2.2.0-1.noarch', + 'dans.knaw.nl-dans-schema-0.10.0-SNAPSHOT20231005095642.noarch', + 'python3-rpm-generators-5-8.el8.noarch', + 'dans.knaw.nl-dd-verify-dataset-0.10.0-1.noarch', + 'dans.knaw.nl-dd-verify-dataset-0.10.0-1.1.noarch', + ] + versions = get_rpm_versions('dans.knaw.nl-') + assert versions == { + 'dans.knaw.nl-dd-vault-metadata': '2.2.0', + 'dans.knaw.nl-dans-schema': '0.10.0-SNAPSHOT20231005095642', + 'dans.knaw.nl-dd-verify-dataset': '0.10.0' + } + + def test_get_dataverse_version(): with patch('builtins.open') as mock_open: mock_open.return_value.__enter__.return_value = ['dataverse.version=5.0.1\n']