From 3b1a9dc2dc280ad68148282eaf047e988ee6112b Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Mon, 4 May 2020 07:25:56 +0100 Subject: [PATCH] Make change a bit more compact and add changelog Signed-off-by: Bernat Gabor --- docs/changelog/1810.bugfix.rst | 1 + src/virtualenv/create/debug.py | 11 +++-------- src/virtualenv/discovery/py_info.py | 13 +++---------- 3 files changed, 7 insertions(+), 18 deletions(-) create mode 100644 docs/changelog/1810.bugfix.rst diff --git a/docs/changelog/1810.bugfix.rst b/docs/changelog/1810.bugfix.rst new file mode 100644 index 000000000..17691be4a --- /dev/null +++ b/docs/changelog/1810.bugfix.rst @@ -0,0 +1 @@ +Fixes older CPython2 versions use ``_get_makefile_filename`` instead of ``get_makefile_filename`` on ``sysconfig`` - by :user:`ianw`. diff --git a/src/virtualenv/create/debug.py b/src/virtualenv/create/debug.py index 5ff76eafd..0cdaa4941 100644 --- a/src/virtualenv/create/debug.py +++ b/src/virtualenv/create/debug.py @@ -55,14 +55,9 @@ def run(): try: import sysconfig - try: - get_makefile_filename = sysconfig.get_makefile_filename - except AttributeError: - # On some platforms, get_makefile_filename doesn't exist - # https://bugs.python.org/issue22199 - get_makefile_filename = sysconfig._get_makefile_filename - - result["makefile_filename"] = encode_path(get_makefile_filename()) + # https://bugs.python.org/issue22199 + makefile = getattr(sysconfig, "get_makefile_filename", getattr(sysconfig, "_get_makefile_filename", None)) + result["makefile_filename"] = encode_path(makefile()) except ImportError: pass diff --git a/src/virtualenv/discovery/py_info.py b/src/virtualenv/discovery/py_info.py index 996ef3357..cdf7b4706 100644 --- a/src/virtualenv/discovery/py_info.py +++ b/src/virtualenv/discovery/py_info.py @@ -24,14 +24,6 @@ def _get_path_extensions(): return list(OrderedDict.fromkeys([""] + os.environ.get("PATHEXT", "").lower().split(os.pathsep))) -try: - get_makefile_filename = sysconfig.get_makefile_filename -except AttributeError: - # On some platforms, get_makefile_filename doesn't exist - # https://bugs.python.org/issue22199 - get_makefile_filename = sysconfig._get_makefile_filename - - EXTENSIONS = _get_path_extensions() _CONF_VAR_RE = re.compile(r"\{\w+\}") @@ -83,12 +75,13 @@ def abs_path(v): self.stdout_encoding = u(getattr(sys.stdout, "encoding", None)) self.sysconfig_paths = {u(i): u(sysconfig.get_path(i, expand=False)) for i in sysconfig.get_path_names()} - + # https://bugs.python.org/issue22199 + makefile = getattr(sysconfig, "get_makefile_filename", getattr(sysconfig, "_get_makefile_filename", None)) self.sysconfig = { u(k): u(v) for k, v in [ # a list of content to store from sysconfig - ("makefile_filename", get_makefile_filename()), + ("makefile_filename", makefile()), ] if k is not None }