#81 Support defining %py3_shebang_flags to %nil
Merged 3 years ago by pviktori. Opened 3 years ago by churchyard.
rpms/ churchyard/python-rpm-macros py3_shebang_empty_flags  into  master

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

      # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly

      pathfix=/usr/bin/pathfix.py

    fi

-   $pathfix -pni %{__python} -k%{?py_shebang_flags:a %py_shebang_flags}}

+   if [ -z "%{?py_shebang_flags}" ]; then

+     shebang_flags="-k"

+   else

+     shebang_flags="-ka%{py_shebang_flags}"

+   fi

+   $pathfix -pni %{__python} $shebang_flags}

  

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

  # the macro

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

  %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}}

+ %py2_shebang_fix %{expand:\\\

+   if [ -z "%{?py_shebang_flags}" ]; then

+     shebang_flags="-k"

+   else

+     shebang_flags="-ka%{py2_shebang_flags}"

+   fi

+   /usr/bin/pathfix.py -pni %{__python2} $shebang_flags}

  

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

  # the macro

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

      # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly

      pathfix=/usr/bin/pathfix.py

    fi

-   $pathfix -pni %{__python3} -k%{?py3_shebang_flags:a %py3_shebang_flags}}

+   if [ -z "%{?py3_shebang_flags}" ]; then

+     shebang_flags="-k"

+   else

+     shebang_flags="-ka%{py3_shebang_flags}"

+   fi

+   $pathfix -pni %{__python3} $shebang_flags}

  

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

  # the macro

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

  Name:           python-rpm-macros

  Version:        3.9

- Release:        10%{?dist}

+ Release:        11%{?dist}

  Summary:        The common Python RPM macros

  

  # macros and lua: MIT, compileall2.py: PSFv2
@@ -107,6 +107,9 @@ 

  

  

  %changelog

+ * Tue Dec 08 2020 Miro Hrončok <mhroncok@redhat.com> - 3.9-11

+ - Support defining %%py3_shebang_flags to %%nil

+ 

  * Mon Sep 14 2020 Miro Hrončok <mhroncok@redhat.com> - 3.9-10

  - Add %%python3_platform_triplet and %%python3_ext_suffix

  - https://fedoraproject.org/wiki/Changes/Python_Upstream_Architecture_Names

file modified
+25 -9
@@ -42,6 +42,13 @@ 

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

  

  

+ def shell_stdout(script):

+     return subprocess.check_output(script,

+                                    env={**os.environ, 'LANG': 'C.utf-8'},

+                                    text=True,

+                                    shell=True).rstrip()

+ 

+ 

  @pytest.mark.parametrize('argument, result', [

      ('a', 'a'),

      ('a-a', 'a-a'),
@@ -252,22 +259,31 @@ 

  

  def test_py3_shebang_fix():

      cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3')[-1].strip()

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

+     assert cmd == '$pathfix -pni /usr/bin/python3 $shebang_flags arg1 arg2 arg3'

+ 

+ 

+ def test_py3_shebang_fix_default_shebang_flags():

+     lines = rpm_eval('%py3_shebang_fix arg1 arg2')

+     lines[-1] = 'echo $shebang_flags'

+     assert shell_stdout('\n'.join(lines)) == '-kas'

  

  

- def test_py3_shebang_fix_custom_flags():

-     cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3', py3_shebang_flags='Es')[-1].strip()

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

+ def test_py3_shebang_fix_custom_shebang_flags():

+     lines = rpm_eval('%py3_shebang_fix arg1 arg2', py3_shebang_flags='Es')

+     lines[-1] = 'echo $shebang_flags'

+     assert shell_stdout('\n'.join(lines)) == '-kaEs'

  

  

- def test_py3_shebang_fix_empty_flags():

-     cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3', py3_shebang_flags=None)[-1].strip()

-     assert cmd == '$pathfix -pni /usr/bin/python3 -k arg1 arg2 arg3'

+ @pytest.mark.parametrize('flags', [None, '%{nil}'])

+ def test_py3_shebang_fix_no_shebang_flags(flags):

+     lines = rpm_eval('%py3_shebang_fix arg1 arg2', py3_shebang_flags=flags)

+     lines[-1] = 'echo $shebang_flags'

+     assert shell_stdout('\n'.join(lines)) == '-k'

  

  

- def test_py_shebang_fix_custom():

+ def test_py_shebang_fix_custom_python():

      cmd = rpm_eval('%py_shebang_fix arg1 arg2 arg3', __python='/usr/bin/pypy')[-1].strip()

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

+     assert cmd == '$pathfix -pni /usr/bin/pypy $shebang_flags arg1 arg2 arg3'

  

  

  def test_pycached_in_sitelib():

no initial comment

There's an extra whitespace here between '-ka' and '%{py3_shebang_flags}'

Yes. For readability. Should I document that in the commit message?

I meant that's causing test failures.
E AssertionError: assert '-ka s' == '-kas'
I don't think -ka s will work either, if you want to retain the whitespace I think it should be -ka -s.

Oh, it's also different in different files. Good catch.

I don't think -ka s will work either, if you want to retain the whitespace I think it should be -ka -s.

I don't think so. But moot, I'm removing the space.

rebased onto c4547819002e3f7d57a2101794c2b3c16b4829e5

3 years ago

rebased onto e5429a7

3 years ago

Build succeeded.

+1. The tests are comewhat fragile, but they can be adjusted when they break.

Pull-Request has been merged by pviktori

3 years ago