Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace legacy packageand() with 'and' expression #254

Merged
merged 2 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec_cleaner/rpmregexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class Regexp(object):
# Special bracketed deps dection
re_brackety_requires = re.compile(r'(pkgconfig|cmake|perl|tex|rubygem)\(')
re_version_separator = re.compile(r'(\S+)((\s*[<>=\s]+)(\S+))*')
# packageand(pkg1:pkg2)
re_packageand = re.compile(r'^packageand\(\s*(\S+)\s*:\s*(\S+)\s*\)\s*$')
# otherproviders(foo)
re_otherproviders = re.compile(r'^otherproviders\(\s*(\S+)\s*\)\s*$')

# rpmdescription
re_authors = re.compile(r'^\s*Author(s)?:\s*')
Expand Down
21 changes: 14 additions & 7 deletions spec_cleaner/rpmrequirestoken.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import Optional

from .rpmexception import RpmException
from .rpmregexp import Regexp


class RpmRequiresToken(object):
"""
Class containing information about the dependency token.

Can be used to specify all the values present on the line.
Later on we use this to do various conversions.
Process dependencies like Requires, Recommends, Suggests, Supplements, Enhances, Conflicts. Can be used to specify
all the values present on the line. Later on we use this to do various conversions.

This class uses the following format and naming:

Expand Down Expand Up @@ -44,7 +45,7 @@ def _format_operator(operator: str) -> str:
@staticmethod
def _format_name(name: str) -> str:
"""
Make sure the name looks sane.
Make sure the name looks sane and make various replacements.

Args:
name: A string representing the name used in the dependency token.
Expand All @@ -55,10 +56,16 @@ def _format_name(name: str) -> str:
# we just rename pkgconfig names to one unified one working everywhere
if name == 'pkgconfig(pkg-config)' or name == 'pkg-config':
name = 'pkgconfig'
# if there is otherproviders codeblock just ommit it
if name.startswith('otherproviders('):
name = name.rstrip(')')
name = name.replace('otherproviders(', '')

# omit legacy 'otherproviders' codeblock
match = Regexp.re_otherproviders.match(name)
if match:
name = match.group(1)

# replace 'packageand(pkgA:pkgB)' with '(pkgA and pkgB)' - new in RPM 4.13
match = Regexp.re_packageand.match(name)
if match:
name = f'({match.group(1)} and {match.group(2)})'
return name

def __str__(self) -> str:
Expand Down
10 changes: 10 additions & 0 deletions tests/in/packageand.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Requires: packageand(packA:packB)
Recommends: packageand(packC:packD)
Suggests: packageand(packE:packF)
Supplements: packageand(packG:packH)
Enhances: packageand(packI:packJ)
Conflicts: packageand(packK:packL)
Supplements: packageand(nginx:moodle)
Supplements: packageand(pam_xyz:pam-32bit)
Supplements: packageand(libpulse0:libxine1)
Supplements: packageand(MozillaFirefox:branding-openSUSE)
12 changes: 12 additions & 0 deletions tests/out-minimal/packageand.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Requires: (packA and packB)
Recommends: (packC and packD)
Suggests: (packE and packF)
Enhances: (packI and packJ)
Supplements: (MozillaFirefox and branding-openSUSE)
Supplements: (libpulse0 and libxine1)
Supplements: (nginx and moodle)
Supplements: (packG and packH)
Supplements: (pam_xyz and pam-32bit)
Conflicts: (packK and packL)

%changelog
12 changes: 12 additions & 0 deletions tests/out/packageand.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Requires: (packA and packB)
Recommends: (packC and packD)
Suggests: (packE and packF)
Enhances: (packI and packJ)
Supplements: (MozillaFirefox and branding-openSUSE)
Supplements: (libpulse0 and libxine1)
Supplements: (nginx and moodle)
Supplements: (packG and packH)
Supplements: (pam_xyz and pam-32bit)
Conflicts: (packK and packL)

%changelog