From 96f8319bb94fb81406678b7ee519430767d07345 Mon Sep 17 00:00:00 2001 From: Iryna Shcherbina Date: Jan 29 2018 16:37:37 +0000 Subject: Add more ignores, and fix other modification issues --- diff --git a/fixrequires/modifier.py b/fixrequires/modifier.py index c3f475b..2e1397d 100644 --- a/fixrequires/modifier.py +++ b/fixrequires/modifier.py @@ -11,13 +11,32 @@ R_IGNORE_IN_CLAUSES = ( '%if {?el6}', '%if 0%{?el6}', '%if {?epel7}', '%if 0%{?epel7}', '%if 0%{?rhel} && 0%{?rhel} <= 7', - '%if %{is_rhel}') + '%if %{is_rhel}', + '%if ( 0%{?rhel} )', + '%if 0%{?el7}', + '%if 0%{?epel} < 7', +) R_ELSE_CLAUSES = [elem + '%else' for elem in R_IGNORE_IN_CLAUSES] -F_IGNORE_IN_CLAUSES = ('%if %{fedora} < 27', '%if 0%{?fedora} < 23') -F_IGNORE_ELSE_CLAUSES = ('%if %{fedora} > 27%else',) +F_IGNORE_IN_CLAUSES = ( + '%if %{fedora} < 27', + '%if 0%{?fedora} < 23', + '%if 0%{fedora} < 24', + '%if 0%{?fedora} < 25', + '%if 0%{?fedora} < 26', + '%if 0%{?old_python_prefix}') +F_IGNORE_ELSE_CLAUSES = ( + '%if %{fedora} > 27%else', + '%if %{use_python3}%else', + '%if 0%{?fedora} >= 23%else', + '%if 0%{?fedora} >=21%else', + '%if 0%{fedora} >= 24%else', + '%if 0%{?fedora}%else', + '%if 0%{?fedora} > 23%else') REQUIRES_PATTERN = '#?\s*(Build)?(Requires|Recommends|Suggests|Supplements|Enhances)(\(postu?n?\))?:\s+(.*)' +NAME_PATTERN = 'Name:\s(.*)' +PACKAGE_PATTERN = '%package\s-n\s(.*)' # pattern: (what to replace, how to replace, what to prepend) REPLACE_PATTERNS = { @@ -33,6 +52,7 @@ SPECIAL = { 'python2-imaging': 'python2-imaging', # Do not replace with python2-pillow 'python-imaging': 'python2-imaging', # Do not replace with python2-pillow 'python-yaml': 'python2-yaml', # Do not replace with python2-pyyaml + 'python2-yaml': 'python2-yaml', # Do not replace with python2-pyyaml } @@ -45,7 +65,11 @@ def is_allowed_name(package_name): def requires_itself(require_name): - return '{name}' in require_name or '%{?_isa}' in require_name + macros = ('%{name}', '%{srcname}', '%{?_isa}', '%{modname}', + '%{pypi_name}', '%{stackname}') + for macro in macros: + if macro in require_name: + return True class RequiresModifier(object): @@ -54,6 +78,8 @@ class RequiresModifier(object): self.logger = logger self.dnf_info = DNFInfo(logger) self.modified_requires = set() + self.name_macro = '' + self.package_macro = '' def run(self, spec): self.modified_requires = set() @@ -63,7 +89,15 @@ class RequiresModifier(object): modified_spec = [] for index, line in enumerate(spec.split('\n')): + name_match = re.match(NAME_PATTERN, line) + if name_match: + self.name_macro = name_match.groups()[0].strip() match = re.match(REQUIRES_PATTERN, line) + + package_match = re.match(PACKAGE_PATTERN, line) + if package_match: + self.package_macro = package_match.groups()[0].strip() + if match: for requires in match.groups(): if requires in (None, 'Requires', 'Build'): @@ -107,6 +141,9 @@ class RequiresModifier(object): modified_requires = [] for require in requires: + # TODO: remove when pyparsing is fixed. + if require == 'pyparsing': + require = 'python2-pyparsing' # If the package does not depend on # python2, then we do not care about it (e.g. python-rpm-macros) if (is_allowed_name(require) and self.dnf_info.requires_py2(require)) or requires_itself(require): @@ -129,6 +166,13 @@ class RequiresModifier(object): f'{require} should be changed to {new_require}, ' 'but seems like it was converted wrong!') + # Handle unversioned %{name} in requirements. + if require == '%{name}' and self.name_macro.startswith('python-'): + if 'python2-' in self.package_macro: + require = self.package_macro + else: + require = self.name_macro.replace('python-', 'python2-') + modified_requires.append(require) return ''.join(modified_requires) + comment