#52 Add %py_provides
Merged 20 days ago by churchyard. Opened a month ago by churchyard.
rpms/ churchyard/python-rpm-macros py_provides  into  master

file modified
+13 -24

@@ -53,43 +53,32 @@ 

  }

  

  %python_provide() %{lua:

+   local python = require "fedora.srpm.python"

    function string.starts(String,Start)

      return string.sub(String,1,string.len(Start))==Start

    end

-   package = rpm.expand("%{?1}")

-   vr = rpm.expand("%{?epoch:%{epoch}:}%{version}-%{release}")

+   local package = rpm.expand("%{?1}")

+   local vr = rpm.expand("%{?epoch:%{epoch}:}%{version}-%{release}")

+   local provides = python.python_altprovides(package, vr)

    if (string.starts(package, "python3-")) then

-     print("\\nProvides: python-")

-     print(string.sub(package,9,string.len(package)))

-     print(" = ")

-     print(vr)

-     print("\\nProvides: python" .. rpm.expand("%{__default_python3_pkgversion}") .. "-")

-     print(string.sub(package,9,string.len(package)))

-     print(" = ")

-     print(vr)

+     for i, provide in ipairs(provides) do

+       print("\\nProvides: " .. provide)

+     end

      --Obsoleting the previous default python package (if it doesn't have isa)

      if (string.sub(package, "-1") ~= ")") then

        print("\\nObsoletes: python-")

        print(string.sub(package,9,string.len(package)))

-       print(" < ")

-       print(vr)

+       print(" < " .. vr)

      end

    elseif (string.starts(package, "python" .. rpm.expand("%{__default_python3_pkgversion}") .. "-")) then

-     print("\\nProvides: python-")

-     l = 8 + string.len(rpm.expand("%{__default_python3_pkgversion}"))

-     print(string.sub(package,l,string.len(package)))

-     print(" = ")

-     print(vr)

-     print("\\nProvides: python3-")

-     print(string.sub(package,l,string.len(package)))

-     print(" = ")

-     print(vr)

+     for i, provide in ipairs(provides) do

+       print("\\nProvides: " .. provide)

+     end

      --Obsoleting the previous default python package (if it doesn't have isa)

      if (string.sub(package, "-1") ~= ")") then

        print("\\nObsoletes: python-")

-       print(string.sub(package,l,string.len(package)))

-       print(" < ")

-       print(vr)

+       print(string.sub(package,10,string.len(package)))

+       print(" < " .. vr)

      end

    elseif (string.starts(package, "python")) then

      --No unversioned provides as other python3 cases are not the default

file modified
+17

@@ -137,3 +137,20 @@ 

  \

      print(url .. first .. '/' .. src .. '/' .. src .. '-' .. ver .. '.' .. ext)

  }

+ 

+ %py_provides() %{lua:

+     local python = require 'fedora.srpm.python'

+     local name = rpm.expand('%1')

+     if name == '%1' then

+         rpm.expand('%{error:%%py_provides requires at least 1 argument, the name to provide}')

+     end

+     local evr = rpm.expand('%2')

+     if evr == '%2' then

+         evr = rpm.expand('%{?epoch:%{epoch}:}%{version}-%{release}')

+     end

+     print('Provides: ' .. name .. ' = ' .. evr .. '\\n')

+     local provides = python.python_altprovides(name, evr)

+     for i, provide in ipairs(provides) do

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

+     end

+ }

file modified
+51 -21

@@ -1,22 +1,31 @@ 

  Name:           python-rpm-macros

  Version:        3.8

- Release:        4%{?dist}

+ Release:        5%{?dist}

  Summary:        The common Python RPM macros

  

- # macros: MIT, compileall2.py: PSFv2

+ # macros and lua: MIT, compileall2.py: PSFv2

  License:        MIT and Python

- Source0:        macros.python

- Source1:        macros.python-srpm

- Source2:        macros.python2

- Source3:        macros.python3

- Source4:        macros.pybytecompile

- Source5:        https://github.com/fedora-python/compileall2/raw/v0.7.1/compileall2.py

+ 

+ # Macros:

+ Source101:      macros.python

+ Source102:      macros.python-srpm

+ Source103:      macros.python2

+ Source104:      macros.python3

+ Source105:      macros.pybytecompile

+ 

+ # Lua files

+ Source201:      python.lua

+ 

+ # Python code

+ %global compileall2_version 0.7.1

+ Source301:      https://github.com/fedora-python/compileall2/raw/v%{compileall2_version}/compileall2.py

  

  BuildArch:      noarch

- # For %%python3_pkgversion used in %%python_provide and compileall2.py

- Requires:       python-srpm-macros >= 3-46

- Obsoletes:      python-macros < 3

- Provides:       python-macros = %{version}-%{release}

+ 

+ # For %%__default_python3_pkgversion used in %%python_provide

+ # For python.lua

+ # For compileall2.py

+ Requires:       python-srpm-macros

  

  %description

  This package contains the unversioned Python RPM macros, that most

@@ -25,26 +34,40 @@ 

  You should not need to install this package manually as the various

  python?-devel packages require it. So install a python-devel package instead.

  

+ 

  %package -n python-srpm-macros

  Summary:        RPM macros for building Python source packages

+ 

+ # For directory structure and flags macros

  Requires:       redhat-rpm-config

  

+ # We bundle our own software here :/

+ Provides:       bundled(python3dist(compileall2)) = %{compileall2_version}

+ 

  %description -n python-srpm-macros

  RPM macros for building Python source packages.

  

+ 

  %package -n python2-rpm-macros

  Summary:        RPM macros for building Python 2 packages

- Requires:       python-srpm-macros >= 3-38

+ 

+ # For %%__python2 and %%python2

+ Requires:       python-srpm-macros

+ 

+ # For %%py_setup

  Requires:       python-rpm-macros

- # Would need to be different for each release - worth it?

- #Conflicts:      python2-devel < 2.7.11-3

  

  %description -n python2-rpm-macros

  RPM macros for building Python 2 packages.

  

+ 

  %package -n python3-rpm-macros

  Summary:        RPM macros for building Python 3 packages

- Requires:       python-srpm-macros >= 3-38

+ 

+ # For %%__python3 and %%python3

+ Requires:       python-srpm-macros

+ 

+ # For %%py_setup

  Requires:       python-rpm-macros

  

  %description -n python3-rpm-macros

@@ -52,17 +75,20 @@ 

  

  

  %prep

+ %autosetup -c -T

+ cp -a %{sources} .

  

- %build

  

  %install

  mkdir -p %{buildroot}%{rpmmacrodir}

- install -m 644 %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} \

-   %{buildroot}%{rpmmacrodir}/

+ install -m 644 macros.* %{buildroot}%{rpmmacrodir}/

+ 

+ mkdir -p %{buildroot}%{_rpmluadir}/fedora/srpm

+ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm python.lua

  

  mkdir -p %{buildroot}%{_rpmconfigdir}/redhat

- install -m 644 %{SOURCE5} \

-   %{buildroot}%{_rpmconfigdir}/redhat/

+ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/

+ 

  

  %files

  %{rpmmacrodir}/macros.python

@@ -71,6 +97,7 @@ 

  %files -n python-srpm-macros

  %{rpmmacrodir}/macros.python-srpm

  %{_rpmconfigdir}/redhat/compileall2.py

+ %{_rpmluadir}/fedora/srpm/python.lua

  

  %files -n python2-rpm-macros

  %{rpmmacrodir}/macros.python2

@@ -80,6 +107,9 @@ 

  

  

  %changelog

+ * Tue May 05 2020 Miro Hrončok <mhroncok@redhat.com> - 3.8-5

+ - Implement %%py_provides

+ 

  * Mon May 04 2020 Tomas Hrnciar <thrnciar@redhat.com> - 3.8-4

  - Make %%py3_install_wheel macro remove direct_url.json file created by PEP 610.

  - https://discuss.python.org/t/pep-610-usage-guidelines-for-linux-distributions/4012

file added
+68

@@ -0,0 +1,68 @@ 

+ -- Convenience Lua functions that can be used within Python srpm/rpm macros

+ 

+ -- Determine alternate names provided from the given name.

+ -- Used in pythonname provides generator, python_provide and py_provides.

+ -- There are 2 rules:

+ --  python3-foo  -> python-foo, python3X-foo

+ --  python3X-foo -> python-foo, python3-foo

+ -- There is no python-foo -> rule, python-foo packages are version agnostic.

+ -- Returns a table/array with strings. Empty when no rule matched.

+ local function python_altnames(name)

+   local xy = rpm.expand('%{__default_python3_pkgversion}')

+   local altnames = {}

+   local replaced

+   -- NB: dash needs to be escaped!

+   if name:match('^python3%-') then

+     for i, prefix in ipairs({'python-', 'python' .. xy .. '-'}) do

+       replaced = name:gsub('^python3%-', prefix)

+       table.insert(altnames, replaced)

+     end

+   elseif name:match('^python' .. xy .. '%-') then

+     for i, prefix in ipairs({'python-', 'python3-'}) do

+       replaced = name:gsub('^python' .. xy .. '%-', prefix)

+       table.insert(altnames, replaced)

+     end

+   end

+   return altnames

+ end

+ 

+ 

+ -- For any given name and epoch-version-release, return provides except self.

+ -- Uses python_altnames under the hood

+ -- Returns a table/array with strings.

+ local function python_altprovides(name, evr)

+   -- global cache that tells what provides were already processed

+   if __python_altnames_provides_beenthere == nil then

+     __python_altnames_provides_beenthere = {}

+   end

+   __python_altnames_provides_beenthere[name .. ' ' .. evr] = true

+   local altprovides = {}

+   for i, altname in ipairs(python_altnames(name)) do

+     table.insert(altprovides, altname .. ' = ' .. evr)

+   end

+   return altprovides

+ end

+ 

+ 

+ -- Like python_altprovides but only return something once.

+ -- For each argument can only be used once, returns nil otherwise.

+ -- Previous usage of python_altprovides counts as well.

+ local function python_altprovides_once(name, evr)

+   -- global cache that tells what provides were already processed

+   if __python_altnames_provides_beenthere == nil then

+     __python_altnames_provides_beenthere = {}

+   end

+   if __python_altnames_provides_beenthere[name .. ' ' .. evr] == nil then

+     __python_altnames_provides_beenthere[name .. ' ' .. evr] = true

+     return python_altprovides(name, evr)

+   else

+     return nil

+   end

+ end

+ 

+ 

+ return {

+   python_altnames = python_altnames,

+   python_altprovides = python_altprovides,

+   python_altprovides_once = python_altprovides_once,

+ }

file added
+1

@@ -0,0 +1,1 @@ 

+ __*__/

file added
+124

@@ -0,0 +1,124 @@ 

+ import subprocess

+ import sys

+ 

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

+ 

+ 

+ def rpm_eval(expression, **kwargs):

+     cmd = ['rpmbuild']

+     for var, value in kwargs.items():

+         cmd += ['--define', f'{var} {value}']

+     cmd += ['--eval', expression]

+     cp = subprocess.run(cmd, text=True,

+                         stdout=subprocess.PIPE, stderr=subprocess.PIPE)

+     assert cp.returncode == 0, cp.stderr

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

+ 

+ 

+ def test_python_provide_python():

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

+ 

+ 

+ def test_python_provide_python3():

+     lines = rpm_eval('%python_provide python3-foo', version='6', release='1.fc66')

+     assert 'Obsoletes: python-foo < 6-1.fc66' in lines

+     assert 'Provides: python-foo = 6-1.fc66' in lines

+     assert f'Provides: python{XY}-foo = 6-1.fc66' in lines

+     assert len(lines) == 3

+ 

+ 

+ def test_python_provide_python3_epoched():

+     lines = rpm_eval('%python_provide python3-foo', epoch='1', version='6', release='1.fc66')

+     assert 'Obsoletes: python-foo < 1:6-1.fc66' in lines

+     assert 'Provides: python-foo = 1:6-1.fc66' in lines

+     assert f'Provides: python{XY}-foo = 1:6-1.fc66' in lines

+     assert len(lines) == 3

+ 

+ 

+ def test_python_provide_python3X():

+     lines = rpm_eval(f'%python_provide python{XY}-foo', version='6', release='1.fc66')

+     assert 'Obsoletes: python-foo < 6-1.fc66' in lines

+     assert 'Provides: python-foo = 6-1.fc66' in lines

+     assert 'Provides: python3-foo = 6-1.fc66' in lines

+     assert len(lines) == 3

+ 

+ 

+ def test_python_provide_python3X_epoched():

+     lines = rpm_eval(f'%python_provide python{XY}-foo', epoch='1', version='6', release='1.fc66')

+     assert 'Obsoletes: python-foo < 1:6-1.fc66' in lines

+     assert 'Provides: python-foo = 1:6-1.fc66' in lines

+     assert 'Provides: python3-foo = 1:6-1.fc66' in lines

+     assert len(lines) == 3

+ 

+ 

+ def test_python_provide_doubleuse():

+     lines = rpm_eval('%{python_provide python3-foo}%{python_provide python3-foo}',

+                      version='6', release='1.fc66')

+     assert 'Obsoletes: python-foo < 6-1.fc66' in lines

+     assert 'Provides: python-foo = 6-1.fc66' in lines

+     assert f'Provides: python{XY}-foo = 6-1.fc66' in lines

+     assert len(lines) == 6

+     assert len(set(lines)) == 3

+ 

+ 

+ def test_py_provides_python():

+     lines = rpm_eval('%py_provides python-foo', version='6', release='1.fc66')

+     assert 'Provides: python-foo = 6-1.fc66' in lines

+     assert len(lines) == 1

+ 

+ 

+ def test_py_provides_whatever():

+     lines = rpm_eval('%py_provides whatever', version='6', release='1.fc66')

+     assert 'Provides: whatever = 6-1.fc66' in lines

+     assert len(lines) == 1

+ 

+ 

+ def test_py_provides_python3():

+     lines = rpm_eval('%py_provides python3-foo', version='6', release='1.fc66')

+     assert 'Provides: python3-foo = 6-1.fc66' in lines

+     assert 'Provides: python-foo = 6-1.fc66' in lines

+     assert f'Provides: python{XY}-foo = 6-1.fc66' in lines

+     assert len(lines) == 3

+ 

+ 

+ def test_py_provides_python3_epoched():

+     lines = rpm_eval('%py_provides python3-foo', epoch='1', version='6', release='1.fc66')

+     assert 'Provides: python3-foo = 1:6-1.fc66' in lines

+     assert 'Provides: python-foo = 1:6-1.fc66' in lines

+     assert f'Provides: python{XY}-foo = 1:6-1.fc66' in lines

+     assert len(lines) == 3

+ 

+ 

+ def test_py_provides_python3X():

+     lines = rpm_eval(f'%py_provides python{XY}-foo', version='6', release='1.fc66')

+     assert f'Provides: python{XY}-foo = 6-1.fc66' in lines

+     assert 'Provides: python-foo = 6-1.fc66' in lines

+     assert 'Provides: python3-foo = 6-1.fc66' in lines

+     assert len(lines) == 3

+ 

+ 

+ def test_py_provides_python3X_epoched():

+     lines = rpm_eval(f'%py_provides python{XY}-foo', epoch='1', version='6', release='1.fc66')

+     assert f'Provides: python{XY}-foo = 1:6-1.fc66' in lines

+     assert 'Provides: python-foo = 1:6-1.fc66' in lines

+     assert 'Provides: python3-foo = 1:6-1.fc66' in lines

+     assert len(lines) == 3

+ 

+ 

+ def test_py_provides_doubleuse():

+     lines = rpm_eval('%{py_provides python3-foo}%{py_provides python3-foo}',

+                      version='6', release='1.fc66')

+     assert 'Provides: python3-foo = 6-1.fc66' in lines

+     assert 'Provides: python-foo = 6-1.fc66' in lines

+     assert f'Provides: python{XY}-foo = 6-1.fc66' in lines

+     assert len(lines) == 6

+     assert len(set(lines)) == 3

+ 

+ 

+ def test_py_provides_with_evr():

+     lines = rpm_eval('%py_provides python3-foo 123',

+                      version='6', release='1.fc66')

+     assert 'Provides: python3-foo = 123' in lines

+     assert 'Provides: python-foo = 123' in lines

+     assert f'Provides: python{XY}-foo = 123' in lines

+     assert len(lines) == 3

file added
+23

@@ -0,0 +1,23 @@ 

+ ---

+ - hosts: localhost

+   tags:

+     - classic

+   tasks:

+     - dnf:

+         name: "*"

+         state: latest

+ 

+ - hosts: localhost

+   roles:

+   - role: standard-test-basic

+     tags:

+     - classic

+     tests:

+     - pytest:

+         dir: .

+         run: pytest -v

+     required_packages:

+     - rpm-build

+     - python-rpm-macros

+     - python3-pytest

+ 

2 new commits added

  • Make %py_provides work repeatedly
  • Implement %py_provides
a month ago

8 new commits added

  • Fedora CI: Add eval tests for %python_provide and %py_provides
  • Make %py_provides work repeatedly
  • Implement %py_provides
  • WIP: TO BE MOVED port %__pythonname_provides to python.python_altprovides_once(name, evr)
  • WIP: TO BE REMOVED (moved here from python-rpm-generators for testing only)
  • Add functions to be used in %py_provides and the provides generator
  • Reorganize the spec
  • Add common Lua functions, use a Lua function in %python_provide
a month ago

@pviktori Please take a look. Commit by commit is easier. The WIP commits will be removed.

8 new commits added

  • Fedora CI: Add eval tests for %python_provide and %py_provides
  • Make %py_provides work repeatedly
  • Implement %py_provides
  • WIP: TO BE MOVED port %__pythonname_provides to python.python_altprovides_once(name, evr)
  • WIP: TO BE REMOVED (moved here from python-rpm-generators for testing only)
  • Add functions to be used in %py_provides and the provides generator
  • Reorganize the spec
  • Add common Lua functions, use a Lua function in %python_provide
a month ago

Should the new python_provide tests pass on current Fedora?

Not sure about the fedora directory, AFAIK things like this are in redhat.

I'm not very good at reviewing Lua, but the code looks reasonable.

Should the new python_provide tests pass on current Fedora?

Yes, but only on rawhide.

Not sure about the fedora directory, AFAIK things like this are in redhat.

Not the lua stuff, see:

$ repoquery --repo=rawhide -l redhat-rpm-config | grep lua
/usr/lib/rpm/lua/fedora
/usr/lib/rpm/lua/fedora/common.lua
/usr/lib/rpm/lua/fedora/rpm
/usr/lib/rpm/lua/fedora/srpm
/usr/lib/rpm/lua/fedora/srpm/forge.lua

This is confusing, maybe we should file a redhat-rpm-config bugzilla about that, but in the meantime, this is what we have.

This is confusing, maybe we should file a redhat-rpm-config bugzilla about that...

https://bugzilla.redhat.com/show_bug.cgi?id=1829430

Let's use python_altprovides(package, vr) here -- it should work the same, but prevent the duplicate provide by the generator.

1 new commit added

  • Reuse python.python_altprovides in %python_provide
21 days ago

Let's use python_altprovides(package, vr) here -- it should work the same, but prevent the duplicate provide by the generator.

Done.

1 new commit added

  • fixup! Fedora CI: Add eval tests for %python_provide and %py_provides
21 days ago

7 new commits added

  • Reuse python.python_altprovides in %python_provide
  • Fedora CI: Add eval tests for %python_provide and %py_provides
  • Make %py_provides work repeatedly
  • Implement %py_provides
  • Add functions to be used in %py_provides and the provides generator
  • Reorganize the spec
  • Add common Lua functions, use a Lua function in %python_provide
21 days ago

Build succeeded.

rebased onto b314efc

21 days ago

Build succeeded.

Build succeeded.

Pull-Request has been merged by churchyard

20 days ago