#59 Add %python_extras_subpkg
Merged 3 years ago by churchyard. Opened 3 years ago by churchyard.
rpms/ churchyard/python-rpm-macros python_extras_subpkg  into  master

file modified
+49 -1
@@ -70,7 +70,7 @@ 

  # Converts Python dist name to a canonical format

  %py_dist_name() %{lua:\

          name = rpm.expand("%{?1:%{1}}");\

-         canonical = string.gsub(string.lower(name), "%W+", "-");\

+         canonical = string.gsub(string.lower(name), "[^%w%[%]]+", "-");\

          print(canonical);\

  }

  
@@ -175,3 +175,51 @@ 

          print('Provides: ' .. provide .. '\\n')

      end

  }

+ 

+ %python_extras_subpkg(n:i:f:F) %{expand:%{lua:

+     local option_n = '-n (name of the base package)'

+     local option_i = '-i (buildroot path to metadata)'

+     local option_f = '-f (builddir path to a filelist)'

+     local option_F = '-F (skip %%files section)'

+     local value_n = rpm.expand('%{-n*}')

+     local value_i = rpm.expand('%{-i*}')

+     local value_f = rpm.expand('%{-f*}')

+     local value_F = rpm.expand('%{-F}')

+     local args = rpm.expand('%{*}')

+     if value_n == '' then

+         rpm.expand('%{error:%%%0: missing option ' .. option_n .. '}')

+     end

+     if value_i == '' and value_f == '' and value_F == '' then

+         rpm.expand('%{error:%%%0: missing option ' .. option_i .. ' or ' .. option_f .. ' or ' .. option_F .. '}')

+     end

+     if value_i ~= '' and value_f ~= '' then

+         rpm.expand('%{error:%%%0: simultaneous ' .. option_i .. ' and ' .. option_f .. ' options are not possible}')

+     end

+     if value_i ~= '' and value_F ~= '' then

+         rpm.expand('%{error:%%%0: simultaneous ' .. option_i .. ' and ' .. option_F .. ' options are not possible}')

+     end

+     if value_f ~= '' and value_F ~= '' then

+         rpm.expand('%{error:%%%0: simultaneous ' .. option_f .. ' and ' .. option_F .. ' options are not possible}')

+     end

+     if args == '' then

+         rpm.expand('%{error:%%%0 requires at least one argument with "extras" name}')

+     end

+     local requires = 'Requires: ' .. value_n .. ' = %{?epoch:%{epoch}:}%{version}-%{release}'

+     for extras in args:gmatch('%w+') do

+         local rpmname = value_n .. '+' .. extras

+         local pkgdef = '%package -n ' .. rpmname

+         local summary = 'Summary: Metapackage for ' .. value_n .. ': ' .. extras .. ' extras'

+         local description = '%description -n ' .. rpmname .. '\\\n' ..

+                             'This is a metapackage bringing in ' .. extras .. ' extras requires for ' .. value_n .. '.\\\n' ..

+                             'It contains no code, just makes sure the dependencies are installed.\\\n'

+         local files = ''

+         if value_i ~= '' then

+             files = '%files -n ' .. rpmname .. '\\\n' .. '%ghost ' .. value_i

+         elseif value_f ~= '' then

+             files = '%files -n ' .. rpmname .. ' -f ' .. value_f

+         end

+         for i, line in ipairs({pkgdef, summary, requires, description, files, ''}) do

+             print(line .. '\\\n')

+         end

+     end

+ }}

file modified
+6 -1
@@ -1,6 +1,6 @@ 

  Name:           python-rpm-macros

  Version:        3.9

- Release:        4%{?dist}

+ Release:        5%{?dist}

  Summary:        The common Python RPM macros

  

  # macros and lua: MIT, compileall2.py: PSFv2
@@ -107,6 +107,11 @@ 

  

  

  %changelog

+ * Wed Jul 08 2020 Miro Hrončok <mhroncok@redhat.com> - 3.9-5

+ - Introduce %%python_extras_subpkg

+ - Adapt %%py_dist_name to keep square brackets

+ - https://fedoraproject.org/wiki/Changes/PythonExtras

+ 

  * Tue Jun 16 2020 Lumír Balhar <lbalhar@redhat.com> - 3.9-4

  - Use compileall from stdlib for Python >= 3.9

  

file modified
+102
@@ -1,6 +1,9 @@ 

  import os

  import subprocess

  import sys

+ import textwrap

+ 

+ import pytest

  

  X_Y = f'{sys.version_info[0]}.{sys.version_info[1]}'

  XY = f'{sys.version_info[0]}{sys.version_info[1]}'
@@ -23,6 +26,30 @@ 

      return cp.stdout.strip().splitlines()

  

  

+ @pytest.mark.parametrize('argument, result', [

+     ('a', 'a'),

+     ('a-a', 'a-a'),

+     ('a_a', 'a-a'),

+     ('a.a', 'a-a'),

+     ('a---a', 'a-a'),

+     ('a-_-a', 'a-a'),

+     ('a-_-a', 'a-a'),

+     ('a[b]', 'a[b]'),

+     ('Aha[Boom]', 'aha[boom]'),

+     ('a.a[b.b]', 'a-a[b-b]'),

+ ])

+ def test_pydist_name(argument, result):

+     assert rpm_eval(f'%py_dist_name {argument}') == [result]

+ 

+ 

+ def test_py2_dist():

+     assert rpm_eval(f'%py2_dist Aha[Boom] a') == ['python2dist(aha[boom]) python2dist(a)']

+ 

+ 

+ def test_py3_dist():

+     assert rpm_eval(f'%py3_dist Aha[Boom] a') == ['python3dist(aha[boom]) python3dist(a)']

+ 

+ 

  def test_python_provide_python():

      assert rpm_eval('%python_provide python-foo') == []

  
@@ -260,3 +287,78 @@ 

  def test_pycached_fails_with_extension_glob():

      lines = rpm_eval('%pycached %{python3_sitelib}/foo.py*', fails=True)

      assert lines[0] == 'error: %pycached can only be used with paths explicitly ending with .py'

+ 

+ 

+ def test_python_extras_subpkg_i():

+     lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -i %{python3_sitelib}/*.egg-info toml yaml',

+                      version='6', release='7')

+     expected = textwrap.dedent(f"""

+         %package -n python3-setuptools_scm+toml

+         Summary: Metapackage for python3-setuptools_scm: toml extras

+         Requires: python3-setuptools_scm = 6-7

+         %description -n python3-setuptools_scm+toml

+         This is a metapackage bringing in toml extras requires for python3-setuptools_scm.

+         It contains no code, just makes sure the dependencies are installed.

+ 

+         %files -n python3-setuptools_scm+toml

+         %ghost /usr/lib/python{X_Y}/site-packages/*.egg-info

+ 

+         %package -n python3-setuptools_scm+yaml

+         Summary: Metapackage for python3-setuptools_scm: yaml extras

+         Requires: python3-setuptools_scm = 6-7

+         %description -n python3-setuptools_scm+yaml

+         This is a metapackage bringing in yaml extras requires for python3-setuptools_scm.

+         It contains no code, just makes sure the dependencies are installed.

+ 

+         %files -n python3-setuptools_scm+yaml

+         %ghost /usr/lib/python{X_Y}/site-packages/*.egg-info

+         """).lstrip().splitlines()

+     assert lines == expected

+ 

+ 

+ def test_python_extras_subpkg_f():

+     lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -f ghost_filelist toml yaml',

+                      version='6', release='7')

+     expected = textwrap.dedent(f"""

+         %package -n python3-setuptools_scm+toml

+         Summary: Metapackage for python3-setuptools_scm: toml extras

+         Requires: python3-setuptools_scm = 6-7

+         %description -n python3-setuptools_scm+toml

+         This is a metapackage bringing in toml extras requires for python3-setuptools_scm.

+         It contains no code, just makes sure the dependencies are installed.

+ 

+         %files -n python3-setuptools_scm+toml -f ghost_filelist

+ 

+         %package -n python3-setuptools_scm+yaml

+         Summary: Metapackage for python3-setuptools_scm: yaml extras

+         Requires: python3-setuptools_scm = 6-7

+         %description -n python3-setuptools_scm+yaml

+         This is a metapackage bringing in yaml extras requires for python3-setuptools_scm.

+         It contains no code, just makes sure the dependencies are installed.

+ 

+         %files -n python3-setuptools_scm+yaml -f ghost_filelist

+         """).lstrip().splitlines()

+     assert lines == expected

+ 

+ 

+ def test_python_extras_subpkg_F():

+     lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -F toml yaml',

+                      version='6', release='7')

+     expected = textwrap.dedent(f"""

+         %package -n python3-setuptools_scm+toml

+         Summary: Metapackage for python3-setuptools_scm: toml extras

+         Requires: python3-setuptools_scm = 6-7

+         %description -n python3-setuptools_scm+toml

+         This is a metapackage bringing in toml extras requires for python3-setuptools_scm.

+         It contains no code, just makes sure the dependencies are installed.

+ 

+ 

+ 

+         %package -n python3-setuptools_scm+yaml

+         Summary: Metapackage for python3-setuptools_scm: yaml extras

+         Requires: python3-setuptools_scm = 6-7

+         %description -n python3-setuptools_scm+yaml

+         This is a metapackage bringing in yaml extras requires for python3-setuptools_scm.

+         It contains no code, just makes sure the dependencies are installed.

+         """).lstrip().splitlines()

+     assert lines == expected

Note to self: pythhon3-setuptools_scm[toml] doesn't make much sense.

rebased onto 4b200437ef0e642f8c8b63b1be2b3b7e1b5fe524

3 years ago

Amended not to say python3-setuptools_scm[toml]

rebased onto 6a4012232e734f279ad4a1ed0116b4d170b238fa

3 years ago

Rebased. Added a way to skip the files section to support packagers to do the section manually. useful if they want to package test files to [test] extra or if they want to add obsoletes/provides/requires/etc. to the subpackage (e.g. when one extras obsoletes another or when it has external dependencies).

The crossed out section is in fact not possible due to the %description. Adding an extra option to omit %description would make it needlessly complicated, we'll document that extra provides and obsoletes need to be added by creating the package manually and we can later add a shortcut if packagers desire it.

rebased onto 763d24c

3 years ago

Build succeeded.

1 new commit added

  • Adapt %%py_dist_name to keep square brackets
3 years ago

The new commit for %py_dist_name looks good!

Build succeeded.

2 new commits added

  • Adapt %%py_dist_name to keep square brackets
  • Add %python_extras_subpkg
3 years ago

The new commit for %py_dist_name looks good!

Thanks. Amended it with tests.

Build succeeded.

Pull-Request has been merged by churchyard

3 years ago