#2 Preserve macros in name
Closed 6 years ago by zbyszek. Opened 6 years ago by churchyard.
churchyard/pyrenamer macroname  into  master

file modified
+18 -6
@@ -110,6 +110,18 @@ 

          stats['MANY-SUBPACKAGES'] += 1

          continue

  

+     # find macros in name

+     for line in stripped:

+         if line.startswith('Name:'):

+             _, name = line.split(':')

+             name = name.strip()

+             python, _, macroname = name.partition('-')

+             if python == 'python' and macroname:

+                 pass

+             else:

+                 macroname = modname  # better safe than sorry

+             break

+ 

      # find description

      if '%description %{_description}' in stripped:

          i = j = stripped.index('%description %{_description}')
@@ -137,9 +149,9 @@ 

  

      # Detect old Provides

      # Assume that it appears only above %description

-     provides = [f'%{{?python_provide:%python_provide python2-{modname}}}']

+     provides = [f'%{{?python_provide:%python_provide python2-{macroname}}}']

      for k in reversed(range(i)):

-         match = re.match(fr'Provides:\s*python2?-({Modname}|{modname})\s*(?:=.*)', lines[k])

+         match = re.match(fr'Provides:\s*python2?-({Modname}|{modname}|{re.escape(macroname)})\s*(?:=.*)', lines[k])

          if match:

              del lines[k]

              tosub += 1
@@ -147,7 +159,7 @@ 

                  del lines[k]

                  tosub += 1

              provided = match.group(1)

-             if provided != modname:

+             if provided not in (modname, macroname):

                  provides.append(f'%{{?python_provide:%python_provide python2-{provided}}}')

  

      # Move Requires down.
@@ -191,11 +203,11 @@ 

          ''] if description else []

  

      lines[i:j] = global_desc + [

-         f'%package -n python2-{modname}',

+         f'%package -n python2-{macroname}',

          'Summary: %summary',

          '\n'.join(requires + provides),

          '',

-         f'%description -n python2-{modname} {desc_macro}'] \

+         f'%description -n python2-{macroname} {desc_macro}'] \

          + ([] if lines[j].strip() == '' else [''])

  

      # Move unqualified %files to new subpackage
@@ -203,7 +215,7 @@ 

      for files_i in range(len(lines)):

          match = re.match(r'%files\s*(-f\s*[^ ]+)?\s*', lines[files_i])

          if match:

-             lines[files_i] = f'%files -n python2-{modname}' + (

+             lines[files_i] = f'%files -n python2-{macroname}' + (

                  f' {match.group(1)}' if match.group(1) is not None else '')

              # detect _bindir in files

              for files_j in range(files_i + 1, len(lines)):

This uses the original casing of the name. E.g. the diff between the diff before your patch and with your patch:

 +%description %_description
 +
-+%package -n python2-4suite-xml
++%package -n python2-4Suite-XML
 +Summary: %summary
-+%{?python_provide:%python_provide python2-4suite-xml}
++%{?python_provide:%python_provide python2-4Suite-XML}
 +
-+%description -n python2-4suite-xml %_description
++%description -n python2-4Suite-XML %_description
 +

I think we want the names to be lower case. That's what ncoghlan wrote:

immediately before the first BuildRequires or Requires entry, add a
%package section header for "-n python2-<name>" (where "<name>" is the lowercased package source name with any "python-" prefix stripped)

and what the guidelines for package naming recommend. I think it'd be preferable not to add any new mixed-case names.

So I think it'd be better to filter out the cases where this would create a mixed-case name. First, look for the python3- subpackage declaration, and if that uses a macro, try that in preference to the macro from "Name:". And second, do rpmspec -q --qf '%{name}\n' ... | grep python2- and if that gives a mixed-case name, revert to using the lower-case string in the python2- subpackage declaration.

This will give a few packages which will have python2- and python3- subpackages with different casing. I'd rather rename the python3- subpackages by hand. If I got my query correctly, that'd be:
- python-astroML/
- python-CacheControl/
- python-PyGithub/
- python-WSGIProxy2/
- python-astroML-addons/
- python-OWSLib/
- python-PyRSS2Gen/

I see. You are right, will revisit the patch tomorrow.

I rebased your patch and applied it, and then added a detection for name lowercasedness on top. Seems pretty nice now.

It seems I cannot close a PR. What?!

Update: found the button ;) It's just in an unexpected place.

Pull-Request has been closed by zbyszek

6 years ago

Oh, sorry for not finishing it. I was overwhelmed with other deadlines.

No, no problem. It was fun to work on this.

Metadata