Warn/fail if /usr/bin/python is called with PYTHON_DISALLOW_AMBIGUOUS_VERSION
See https://fedoraproject.org/wiki/User:Pviktori/Avoid_usr_bin_python_in_RPM_Build
This commit is contained in:
parent
9c6e188db0
commit
7143d8af3a
|
@ -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()
|
||||||
|
|
13
python2.spec
13
python2.spec
|
@ -112,7 +112,7 @@ Summary: An interpreted, interactive, object-oriented programming language
|
||||||
Name: %{python}
|
Name: %{python}
|
||||||
# Remember to also rebase python-docs when changing this:
|
# Remember to also rebase python-docs when changing this:
|
||||||
Version: 2.7.14
|
Version: 2.7.14
|
||||||
Release: 8%{?dist}
|
Release: 9%{?dist}
|
||||||
License: Python
|
License: Python
|
||||||
Group: Development/Languages
|
Group: Development/Languages
|
||||||
Requires: %{python}-libs%{?_isa} = %{version}-%{release}
|
Requires: %{python}-libs%{?_isa} = %{version}-%{release}
|
||||||
|
@ -758,11 +758,17 @@ Patch285: 00285-fix-non-deterministic-read-in-test_pty.patch
|
||||||
# Fixed upstream: https://bugs.python.org/issue32186
|
# Fixed upstream: https://bugs.python.org/issue32186
|
||||||
Patch287: 00287-fix-thread-hanging-on-inaccessible-nfs-server.patch
|
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/Changes/Avoid_usr_bin_python_in_RPM_Build
|
||||||
|
Patch288: 00288-ambiguous-python-version-rpmbuild-warn.patch
|
||||||
|
|
||||||
# 00289 #
|
# 00289 #
|
||||||
# Disable automatic detection for the nis module
|
# Disable automatic detection for the nis module
|
||||||
# (we handle it it in Setup.dist, see Patch0)
|
# (we handle it it in Setup.dist, see Patch0)
|
||||||
Patch289: 00289-disable-nis-detection.patch
|
Patch289: 00289-disable-nis-detection.patch
|
||||||
|
|
||||||
|
|
||||||
# (New patches go here ^^^)
|
# (New patches go here ^^^)
|
||||||
#
|
#
|
||||||
# When adding new patches to "python2" and "python3" in Fedora, EL, etc.,
|
# When adding new patches to "python2" and "python3" in Fedora, EL, etc.,
|
||||||
|
@ -1086,6 +1092,7 @@ mv Modules/cryptmodule.c Modules/_cryptmodule.c
|
||||||
%patch284 -p1
|
%patch284 -p1
|
||||||
%patch285 -p1
|
%patch285 -p1
|
||||||
%patch287 -p1
|
%patch287 -p1
|
||||||
|
%patch288 -p1
|
||||||
%patch289 -p1
|
%patch289 -p1
|
||||||
|
|
||||||
|
|
||||||
|
@ -1967,6 +1974,10 @@ rm -fr %{buildroot}
|
||||||
# ======================================================
|
# ======================================================
|
||||||
|
|
||||||
%changelog
|
%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
|
* Sat Jan 20 2018 Björn Esser <besser82@fedoraproject.org> - 2.7.14-8
|
||||||
- Rebuilt for switch to libxcrypt
|
- Rebuilt for switch to libxcrypt
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue