#58 Implement %pyX_shebang_fix
Merged 3 years ago by churchyard. Opened 3 years ago by churchyard.
rpms/ churchyard/python-rpm-macros py3_shebang_fix  into  master

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

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

  %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

file modified
+24 -1
@@ -7,7 +7,10 @@ 

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

      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 modified
+1
@@ -19,5 +19,6 @@ 

      required_packages:

      - rpm-build

      - python-rpm-macros

+     - python3-rpm-macros

      - python3-pytest