#61 Fedora 31 backports: %py_provides, %pytest, %pypi_source tildes stripping, %pyX_shebang_fix
Merged 3 years ago by churchyard. Opened 3 years ago by churchyard.
rpms/ churchyard/python-rpm-macros f31-backports  into  f31

file modified
+2
@@ -8,6 +8,8 @@ 

  %py_setup setup.py

  %py_shbang_opts -s

  %py_shbang_opts_nodash %(opts=%{py_shbang_opts}; echo ${opts#-})

+ %py_shebang_flags %(opts=%{py_shbang_opts}; echo ${opts#-})

+ %py_shebang_fix %{expand:/usr/bin/pathfix.py -pni %{__python} -k%{?py_shebang_flags:a %py_shebang_flags}}

  

  # Use the slashes after expand so that the command starts on the same line as

  # the macro

file modified
+19 -2
@@ -93,7 +93,7 @@ 

  # Accepts zero to three arguments:

  # 1:  The PyPI project name, defaulting to %srcname if it is defined, then

  #     %pypi_name if it is defined, then just %name.

- # 2:  The PYPI version, defaulting to %version.

+ # 2:  The PYPI version, defaulting to %version with tildes stripped.

  # 3:  The file extension, defaulting to "tar.gz".  (A period will be added

  #     automatically.)

  # Requires %__pypi_url and %__pypi_default_extension to be defined.
@@ -120,7 +120,7 @@ 

  \

      -- If no second argument, use %version

      if ver == '%2' then

-         ver = rpm.expand('%version')

+         ver = rpm.expand('%version'):gsub('~', '')

      end

  \

      -- If no third argument, use the preset default extension
@@ -132,3 +132,20 @@ 

  \

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

  }

+ 

+ %py_provides() %{lua:

+     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')

+     -- NB: dash needs to be escaped!

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

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

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

+     end

+ }

file modified
+2
@@ -5,6 +5,8 @@ 

  

  %py2_shbang_opts -s

  %py2_shbang_opts_nodash %(opts=%{py2_shbang_opts}; echo ${opts#-})

+ %py2_shebang_flags %(opts=%{py2_shbang_opts}; echo ${opts#-})

+ %py2_shebang_fix %{expand:/usr/bin/pathfix.py -pni %{__python2} -k%{?py2_shebang_flags:a %py2_shebang_flags}}

  

  # Use the slashes after expand so that the command starts on the same line as

  # the macro

file modified
+11
@@ -7,6 +7,8 @@ 

  

  %py3_shbang_opts -s

  %py3_shbang_opts_nodash %(opts=%{py3_shbang_opts}; echo ${opts#-})

+ %py3_shebang_flags %(opts=%{py3_shbang_opts}; echo ${opts#-})

+ %py3_shebang_fix %{expand:/usr/bin/pathfix.py -pni %{__python3} -k%{?py3_shebang_flags:a %py3_shebang_flags}}

  

  # Use the slashes after expand so that the command starts on the same line as

  # the macro
@@ -53,3 +55,12 @@ 

      print("\\n" .. dirname .. "__pycache__/" .. modulename .. ".cpython-3" .. pyminor .. "{,.opt-?}.pyc")

    end

  }

+ 

+ # This is intended for Python 3 only, hence also no Python version in the name.

+ %__pytest /usr/bin/pytest

+ %pytest %{expand:\\\

+   CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\

+   PATH="%{buildroot}%{_bindir}:$PATH"\\\

+   PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\

+   PYTHONDONTWRITEBYTECODE=1\\\

+   %__pytest}

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

  Name:           python-rpm-macros

  Version:        3

- Release:        55%{?dist}

+ Release:        56%{?dist}

  Summary:        The unversioned Python RPM macros

  

  # macros: MIT, compileall2.py: PSFv2
@@ -80,6 +80,12 @@ 

  

  

  %changelog

+ * Wed May 20 2020 Miro Hrončok <mhroncok@redhat.com> - 3-56

+ - Implement %%py_provides

+ - Implement %%pytest

+ - Implement %%pyX_shebang_fix

+ - Strip tildes from %%version in %%pypi_source by default

+ 

  * Tue Apr 28 2020 Miro Hrončok <mhroncok@redhat.com> - 3-55

  - Make pythonX-rpm-macros depend on python-rpm-macros (#1827811)

  

file added
+1
@@ -0,0 +1,1 @@ 

+ __*__/

file added
+170
@@ -0,0 +1,170 @@ 

+ import subprocess

+ import sys

+ 

+ 

+ def rpm_eval(expression, **kwargs):

+     cmd = ['rpmbuild']

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

+         if value is None:

+             cmd += ['--undefine', var]

+         else:

+             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 len(lines) == 2

+ 

+ 

+ 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 len(lines) == 2

+ 

+ 

+ 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 len(lines) == 4

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

+ 

+ 

+ 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 len(lines) == 2

+ 

+ 

+ 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 len(lines) == 2

+ 

+ 

+ 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 len(lines) == 4

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

+ 

+ 

+ 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 len(lines) == 2

+ 

+ 

+ def test_pytest_passes_options_naturally():

+     lines = rpm_eval('%pytest -k foo')

+     assert '/usr/bin/pytest -k foo' in lines[-1]

+ 

+ 

+ def test_pytest_different_command():

+     lines = rpm_eval('%pytest', __pytest='pytest-3')

+     assert 'pytest-3' in lines[-1]

+ 

+ 

+ def test_pypi_source_default_name():

+     url = rpm_eval('%pypi_source',

+                    name='foo', version='6')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/f/foo/foo-6.tar.gz'

+ 

+ 

+ def test_pypi_source_default_srcname():

+     url = rpm_eval('%pypi_source',

+                    name='python-foo', srcname='foo', version='6')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/f/foo/foo-6.tar.gz'

+ 

+ 

+ def test_pypi_source_default_pypi_name():

+     url = rpm_eval('%pypi_source',

+                    name='python-foo', pypi_name='foo', version='6')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/f/foo/foo-6.tar.gz'

+ 

+ 

+ def test_pypi_source_default_name_uppercase():

+     url = rpm_eval('%pypi_source',

+                    name='Foo', version='6')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/F/Foo/Foo-6.tar.gz'

+ 

+ 

+ def test_pypi_source_provided_name():

+     url = rpm_eval('%pypi_source foo',

+                    name='python-bar', pypi_name='bar', version='6')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/f/foo/foo-6.tar.gz'

+ 

+ 

+ def test_pypi_source_provided_name_version():

+     url = rpm_eval('%pypi_source foo 6',

+                    name='python-bar', pypi_name='bar', version='3')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/f/foo/foo-6.tar.gz'

+ 

+ 

+ def test_pypi_source_provided_name_version_ext():

+     url = rpm_eval('%pypi_source foo 6 zip',

+                    name='python-bar', pypi_name='bar', version='3')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/f/foo/foo-6.zip'

+ 

+ 

+ def test_pypi_source_prerelease():

+     url = rpm_eval('%pypi_source',

+                    name='python-foo', pypi_name='foo', version='6~b2')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/f/foo/foo-6b2.tar.gz'

+ 

+ 

+ def test_pypi_source_explicit_tilde():

+     url = rpm_eval('%pypi_source foo 6~6',

+                    name='python-foo', pypi_name='foo', version='6')[0]

+     assert url == 'https://files.pythonhosted.org/packages/source/f/foo/foo-6~6.tar.gz'

+ 

+ 

+ def test_py3_shebang_fix():

+     cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3')[0]

+     assert cmd == '/usr/bin/pathfix.py -pni /usr/bin/python3 -ka s arg1 arg2 arg3'

+ 

+ 

+ def test_py3_shebang_fix_custom_flags():

+     cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3', py3_shebang_flags='Es')[0]

+     assert cmd == '/usr/bin/pathfix.py -pni /usr/bin/python3 -ka Es arg1 arg2 arg3'

+ 

+ 

+ def test_py3_shebang_fix_empty_flags():

+     cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3', py3_shebang_flags=None)[0]

+     assert cmd == '/usr/bin/pathfix.py -pni /usr/bin/python3 -k arg1 arg2 arg3'

+ 

+ 

+ def test_py_shebang_fix_custom():

+     cmd = rpm_eval('%py_shebang_fix arg1 arg2 arg3', __python='/usr/bin/pypy')[0]

+     assert cmd == '/usr/bin/pathfix.py -pni /usr/bin/pypy -ka s arg1 arg2 arg3'

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-rpm-macros

+     - python3-pytest