From ca811dbf35c1447694253a6c462efe9542d90056 Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Jan 01 2020 22:21:46 +0000 Subject: Sync with upstream RPM - Handle version ending with ".*" - Handle compatible-release operator "~=" - Use rich deps for semantically versioned dependencies - Match Python version if minor has multiple digits (e.g. 3.10) - Only add setuptools requirement for egg-info packages https://github.com/rpm-software-management/rpm/pull/951 https://github.com/rpm-software-management/rpm/pull/973 https://github.com/rpm-software-management/rpm/pull/982 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1758141 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1777382 --- diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index eaeda0f..acc9d06 100644 --- a/python-rpm-generators.spec +++ b/python-rpm-generators.spec @@ -4,8 +4,8 @@ Name: python-rpm-generators Summary: Dependency generators for Python RPMs -Version: 9 -Release: 2%{?dist} +Version: 10 +Release: 1%{?dist} # Originally all those files were part of RPM, so license is kept here License: GPLv2+ @@ -49,6 +49,13 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} pythondeps.sh pythondistdeps.py %{_rpmconfigdir}/pythondistdeps.py %changelog +* Wed Jan 01 2020 Miro Hrončok - 10-1 +- Handle version ending with ".*" (#1758141) +- Handle compatible-release operator "~=" (#1758141) +- Use rich deps for semantically versioned dependencies +- Match Python version if minor has multiple digits (e.g. 3.10, #1777382) +- Only add setuptools requirement for egg-info packages + * Fri Jul 26 2019 Fedora Release Engineering - 9-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild diff --git a/pythondistdeps.py b/pythondistdeps.py index 1d3535b..2572ac2 100755 --- a/pythondistdeps.py +++ b/pythondistdeps.py @@ -102,7 +102,7 @@ for f in files: lower.endswith('.egg-info') or \ lower.endswith('.dist-info'): # This import is very slow, so only do it if needed - from pkg_resources import Distribution, FileMetadata, PathMetadata, Requirement + from pkg_resources import Distribution, FileMetadata, PathMetadata, Requirement, parse_version dist_name = basename(f) if isdir(f): path_item = dirname(f) @@ -116,7 +116,7 @@ for f in files: # Try to parse the Python version from the path the metadata # resides at (e.g. /usr/lib/pythonX.Y/site-packages/...) import re - res = re.search(r"/python(?P\d+\.\d)/", path_item) + res = re.search(r"/python(?P\d+\.\d+)/", path_item) if res: dist.py_version = res.group('pyver') else: @@ -184,8 +184,10 @@ for f in files: depsextras.remove(dep) deps = depsextras # console_scripts/gui_scripts entry points need pkg_resources from setuptools - if (dist.get_entry_map('console_scripts') or - dist.get_entry_map('gui_scripts')): + if ((dist.get_entry_map('console_scripts') or + dist.get_entry_map('gui_scripts')) and + (lower.endswith('.egg') or + lower.endswith('.egg-info'))): # stick them first so any more specific requirement overrides it deps.insert(0, Requirement.parse('setuptools')) # add requires/recommends based on egg/dist metadata @@ -248,11 +250,35 @@ names.sort() for name in names: if py_deps[name]: # Print out versioned provides, requires, recommends, conflicts + spec_list = [] for spec in py_deps[name]: if spec[0] == '!=': - print('({n} < {v} or {n} >= {v}.0)'.format(n=name, v=spec[1])) + spec_list.append('{n} < {v} or {n} >= {v}.0'.format(n=name, v=spec[1])) + elif spec[0] == '~=': + # Parse the current version + next_ver = parse_version(spec[1]).base_version.split('.') + # Drop the micro version + next_ver = next_ver[0:-1] + # Increment the minor version + next_ver[-1] = str(int(next_ver[-1]) + 1) + next_ver = '.'.join(next_ver) + spec_list.append('{n} >= {v} with {n} < {vnext}'.format(n=name, v=spec[1], vnext=next_ver)) + elif spec[0] == '==' and spec[1].endswith('.*'): + # Parse the current version + next_ver = parse_version(spec[1]).base_version.split('.') + # Drop the micro version from both the version in spec and next_ver + next_ver = next_ver[0:-1] + spec = (spec[0], '.'.join(next_ver)) + # Increment the minor version + next_ver[-1] = str(int(next_ver[-1]) + 1) + next_ver = '.'.join(next_ver) + spec_list.append('{n} >= {v} with {n} < {vnext}'.format(n=name, v=spec[1], vnext=next_ver)) else: - print('{} {} {}'.format(name, spec[0], spec[1])) + spec_list.append('{} {} {}'.format(name, spec[0], spec[1])) + if len(spec_list) == 1: + print(spec_list[0]) + else: + print('({})'.format(' with '.join(spec_list))) else: # Print out unversioned provides, requires, recommends, conflicts print(name)