From 1de7c30f288502caf6f8b91ef9ae1feba697c5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Tue, 17 Mar 2020 16:52:11 +0000 Subject: [PATCH] add zip importer test (#1727) Signed-off-by: Bernat Gabor --- docs/changelog/1715.bugfix.rst | 2 ++ .../create/via_global_ref/_virtualenv.py | 5 +++- tests/unit/create/test_creator.py | 23 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/1715.bugfix.rst diff --git a/docs/changelog/1715.bugfix.rst b/docs/changelog/1715.bugfix.rst new file mode 100644 index 000000000..91cf9b016 --- /dev/null +++ b/docs/changelog/1715.bugfix.rst @@ -0,0 +1,2 @@ +Do not fail if the distutils/setuptools patch happens on a C-extension loader (such as ``zipimporter`` on Python 3.7 or +earlier) - by :user:`gaborbernat`. diff --git a/src/virtualenv/create/via_global_ref/_virtualenv.py b/src/virtualenv/create/via_global_ref/_virtualenv.py index 5a1f76a02..b399da4cc 100644 --- a/src/virtualenv/create/via_global_ref/_virtualenv.py +++ b/src/virtualenv/create/via_global_ref/_virtualenv.py @@ -61,7 +61,10 @@ def find_spec(self, fullname, path, target=None): old = getattr(spec.loader, func_name) func = self.exec_module if is_new_api else self.load_module if old is not func: - setattr(spec.loader, func_name, partial(func, old)) + try: + setattr(spec.loader, func_name, partial(func, old)) + except AttributeError: + pass # C-Extension loaders are r/o such as zipimporter with