#9 Warn/fail if /usr/bin/python is called with PYTHON_DISALLOW_AMBIGUOUS_VERSION
Closed 6 years ago by churchyard. Opened 6 years ago by pviktori.
rpms/ pviktori/python2 disallow-ambiguous-version  into  master

@@ -0,0 +1,53 @@ 

+ diff -U3 -r Python-2.7.14.orig/Lib/site.py Python-2.7.14/Lib/site.py

+ --- Python-2.7.14.orig/Lib/site.py	2018-01-29 15:05:04.517599815 +0100

+ +++ Python-2.7.14/Lib/site.py	2018-01-30 09:13:17.305270500 +0100

+ @@ -515,6 +515,41 @@

+                  "'import usercustomize' failed; use -v for traceback"

+  

+  

+ +def handle_ambiguous_python_version():

+ +    """Warn or fail if /usr/bin/python is used

+ +

+ +    Behavior depends on the value of PYTHON_DISALLOW_AMBIGUOUS_VERSION:

+ +    - "warn" - print warning to stderr

+ +    - "1" - print error and exit with positive exit code

+ +    - otherwise: do nothing

+ +

+ +    This is a Fedora modification, see the Change page for details:

+ +    See https://fedoraproject.org/wiki/Changes/Avoid_usr_bin_python_in_RPM_Build

+ +    """

+ +    if sys.executable == "/usr/bin/python":

+ +        setting = os.environ.get("PYTHON_DISALLOW_AMBIGUOUS_VERSION")

+ +        if setting == 'warn':

+ +            print>>sys.stderr, (

+ +                "DEPRECATION WARNING: python2 invoked with /usr/bin/python.\n"

+ +                "    Use /usr/bin/python3 or /usr/bin/python2\n"

+ +                "    /usr/bin/python will be removed or switched to Python 3"

+ +                    " in the future.\n"

+ +                "    If you cannot make the switch now, please follow"

+ +                    " instructions at"

+ +                    " https://fedoraproject.org/wiki/Changes/"

+ +                    "Avoid_usr_bin_python_in_RPM_Build#Quick_Opt-Out")

+ +        elif setting == '1':

+ +            print>>sys.stderr, (

+ +                "ERROR: python2 invoked with /usr/bin/python.\n"

+ +                "    Use /usr/bin/python3 or /usr/bin/python2\n"

+ +                "    /usr/bin/python will be switched to Python 3"

+ +                    " in the future.\n"

+ +                "    More details are at"

+ +                    " https://fedoraproject.org/wiki/Changes/"

+ +                    "Avoid_usr_bin_python_in_RPM_Build#Quick_Opt-Out")

+ +            exit(1)

+ +

+ +

+  def main():

+      global ENABLE_USER_SITE

+  

+ @@ -543,6 +578,7 @@

+      # this module is run as a script, because this code is executed twice.

+      if hasattr(sys, "setdefaultencoding"):

+          del sys.setdefaultencoding

+ +    handle_ambiguous_python_version()

+  

+  main()

+  

file modified
+12 -1
@@ -112,7 +112,7 @@ 

  Name: %{python}

  # Remember to also rebase python-docs when changing this:

  Version: 2.7.14

- Release: 8%{?dist}

+ Release: 9%{?dist}

  License: Python

  Group: Development/Languages

  Requires: %{python}-libs%{?_isa} = %{version}-%{release}
@@ -758,11 +758,17 @@ 

  # Fixed upstream: https://bugs.python.org/issue32186

  Patch287: 00287-fix-thread-hanging-on-inaccessible-nfs-server.patch

  

+ # 00288 #

+ # Adds a warning when /usr/bin/python is invoked during rpmbuild

+ # See https://fedoraproject.org/wiki/User:Pviktori/Avoid_usr_bin_python_in_RPM_Build

+ Patch288: 00288-ambiguous-python-version-rpmbuild-warn.patch

+ 

  # 00289 #

  # Disable automatic detection for the nis module

  # (we handle it it in Setup.dist, see Patch0)

  Patch289: 00289-disable-nis-detection.patch

  

+ 

  # (New patches go here ^^^)

  #

  # When adding new patches to "python2" and "python3" in Fedora, EL, etc.,
@@ -1086,6 +1092,7 @@ 

  %patch284 -p1

  %patch285 -p1

  %patch287 -p1

+ %patch288 -p1

  %patch289 -p1

  

  
@@ -1967,6 +1974,10 @@ 

  # ======================================================

  

  %changelog

+ * Tue Jan 30 2018 Petr Viktorin <pviktori@redhat.com> - 2.7.14-9

+ - Add patch 288: warn/fail if Python 2 is called as /usr/bin/python and

+   PYTHON_DISALLOW_AMBIGUOUS_VERSION is set

+ 

  * Sat Jan 20 2018 Björn Esser <besser82@fedoraproject.org> - 2.7.14-8

  - Rebuilt for switch to libxcrypt

  

See https://fedoraproject.org/wiki/User:Pviktori/Avoid_usr_bin_python_in_RPM_Build

I have trouble building this, due to what appear to be unrelated issues.
One thing I did to make this build (more often) was disable strict symbol checks; this should be solved properly but that's a different issue.

The comments near the patch definition in the spec are out of date. The code of the patch looks reasonable, but I haven't tested it.

1 new commit added

  • Remove out-of-date comments
6 years ago

Stale comments removed, thanks.

The build failure on x86_64 is apparently due to the GCC/annobin issue that's currently affecting all of Rawhide.

rebased onto 21418b1

6 years ago

Removed commit for the -z defs; squashed.

Pull-Request has been closed by churchyard

6 years ago