#77 Add %python3_platform_triplet and %python3_ext_suffix
Merged 3 years ago by churchyard. Opened 3 years ago by churchyard.
rpms/ churchyard/python-rpm-macros platform_triplet_macros  into  master

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

  %python_version %(%{__python} -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")

  %python_version_nodots %(%{__python} -Esc "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")

  %python_platform %(%{__python} -Esc "import sysconfig; print(sysconfig.get_platform())")

+ %python_platform_triplet %(%{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))")

+ %python_ext_suffix %(%{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")

  

  %py_setup setup.py

  %py_shbang_opts -s

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

  %python3_version %(%{__python3} -Ic "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")

  %python3_version_nodots %(%{__python3} -Ic "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")

  %python3_platform %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())")

+ %python3_platform_triplet %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))")

+ %python3_ext_suffix %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")

  %py3dir %{_builddir}/python3-%{name}-%{version}-%{release}

  

  %py3_shbang_opts -s

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

  Name:           python-rpm-macros

  Version:        3.9

- Release:        9%{?dist}

+ Release:        10%{?dist}

  Summary:        The common Python RPM macros

  

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

  

  

  %changelog

+ * 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

+ 

  * Fri Jul 24 2020 Lumír Balhar <lbalhar@redhat.com> - 3.9-9

  - Adapt %%py[3]_shebang_fix to use versioned pathfixX.Y.py

  

file modified
+17
@@ -1,5 +1,6 @@ 

  import os

  import subprocess

+ import platform

  import sys

  import textwrap

  
@@ -398,6 +399,8 @@ 

      '%python_sitelib',

      '%python_sitearch',

      '%python_platform',

+     '%python_platform_triplet',

+     '%python_ext_suffix',

      '%py_shebang_fix',

      '%py_build',

      '%py_build_egg',
@@ -419,3 +422,17 @@ 

  def test_unversioned_python_works_when_defined(macro):

      macro3 = macro.replace('python', 'python3').replace('py_', 'py3_')

      assert rpm_eval(macro, __python='/usr/bin/python3') == rpm_eval(macro3)

+ 

+ 

+ # we could rework the test for multiple architectures, but the Fedora CI currently only runs on x86_64

+ x86_64_only = pytest.mark.skipif(platform.machine() != "x86_64", reason="works on x86_64 only")

+ 

+ 

+ @x86_64_only

+ def test_platform_triplet():

+     assert rpm_eval("%python3_platform_triplet")[0] == "x86_64-linux-gnu"

+ 

+ 

+ @x86_64_only

+ def test_ext_suffix():

+     assert rpm_eval("%python3_ext_suffix")[0] == f".cpython-{XY}-x86_64-linux-gnu.so"

file modified
+1
@@ -23,5 +23,6 @@ 

      - rpm-build

      - python-rpm-macros

      - python3-rpm-macros

+     - python3-devel

      - python3-pytest

  

Also add %python_platform_triplet and %python_ext_suffix.

The CI tests are limited to x86_64 for now.

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

Build succeeded.

Code looks good to me, testing on x64 is reasonable. Will test it manually as well.

Fedora CI failure seems unrelated:

error: Failed build dependencies:
    python3-devel is needed by pythontest-0-0.x86_64

%python_platform_triplet and %python3_platform_triplet work correctly for all Pythons >= 3.6 as expected.

%python_ext_suffix and %python3_ext_suffix work correctly for all Pythons >= 3.5 as expected, including a change of the schema in regards to the m with Python >= 3.8.

LGTM

rebased onto a712d45

3 years ago

Added a commit that should fix the Fedora CI.

Build succeeded.

Pull-Request has been merged by churchyard

3 years ago