--- Python-2.7.15-orig/Python/pythonrun.c +++ Python-2.7.15/Python/pythonrun.c @@ -180,6 +182,49 @@ char buf[128]; #endif extern void _Py_ReadyTypes(void); + char *py2_allow_flag = getenv("RHEL_ALLOW_PYTHON2_FOR_BUILD"); + + // Fail unless a specific workaround is applied + if ((!py2_allow_flag || strcmp(py2_allow_flag, "1") != 0) + && (strstr(Py_GetProgramName(), "for-tests") == NULL) + ) { + fprintf(stderr, + "\n" + "ERROR: Python 2 is disabled in RHEL8.\n" + "\n" + "- For guidance on porting to Python 3, see the\n" + " Conservative Python3 Porting Guide:\n" + " http://portingguide.readthedocs.io/\n" + "\n" + "- If you need Python 2 at runtime:\n" + " - Use the python27 module\n" + "\n" + "- If you do not have access to BZ#1533919:\n" + " - Use the python27 module\n" + "\n" + "- If you need to use Python 2 only at RPM build time:\n" + " - File a bug blocking BZ#1533919:\n" + " https://bugzilla.redhat.com/show_bug.cgi?id=1533919\n" + " - Set the environment variable RHEL_ALLOW_PYTHON2_FOR_BUILD=1\n" + " (Note that if you do not file the bug as above,\n" + " this workaround will break without warning in the future.)\n" + "\n" + "- If you need to use Python 2 only for tests:\n" + " - File a bug blocking BZ#1533919:\n" + " https://bugzilla.redhat.com/show_bug.cgi?id=1533919\n" + " (If your test tool does not have a Bugzilla component,\n" + " feel free to use `python2`.)\n" + " - Use /usr/bin/python2-for-tests instead of python2 to run\n" + " your tests.\n" + " (Note that if you do not file the bug as above,\n" + " this workaround will break without warning in the future.)\n" + "\n" + "For details, see https://hurl.corp.redhat.com/rhel8-py2\n" + "\n" + ); + fflush(stderr); + Py_FatalError("Python 2 is disabled"); + } if (initialized) return;