Miro Hrončok 2020-05-18 18:58:39 +02:00
parent eb50d8e147
commit 1bdef041df
6 changed files with 32 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -83,6 +83,7 @@ install -m 644 %{SOURCE5} \
* Wed May 20 2020 Miro Hrončok <mhroncok@redhat.com> - 3-57
- 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-56

View File

@ -5,7 +5,10 @@ import sys
def rpm_eval(expression, **kwargs):
cmd = ['rpmbuild']
for var, value in kwargs.items():
cmd += ['--define', f'{var} {value}']
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)
@ -145,3 +148,23 @@ 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'

View File

@ -19,4 +19,5 @@
required_packages:
- rpm-build
- python-rpm-macros
- python3-rpm-macros
- python3-pytest