Miro Hrončok 2020-05-18 18:58:39 +02:00
parent 4569c61d8d
commit 72371929c5
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

@ -109,6 +109,7 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/
%changelog
* Mon May 11 2020 Miro Hrončok <mhroncok@redhat.com> - 3.8-8
- Implement %%pytest
- Implement %%pyX_shebang_fix
- Strip tildes from %%version in %%pypi_source by default
* Thu May 07 2020 Miro Hrončok <mhroncok@redhat.com> - 3.8-7

View File

@ -7,7 +7,10 @@ X_Y = 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}']
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)
@ -186,3 +189,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,5 +19,6 @@
required_packages:
- rpm-build
- python-rpm-macros
- python3-rpm-macros
- python3-pytest