From 9c9c91c0a3951a7c521bd6eddc3aa5f84f0cfd9f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 28 Dec 2021 14:34:37 -0500 Subject: [PATCH] Bypass distutils loader when setuptools module is no longer available on sys.path. Fixes #2980. --- _distutils_hack/__init__.py | 7 +++++++ changelog.d/2980.misc.rst | 1 + 2 files changed, 8 insertions(+) create mode 100644 changelog.d/2980.misc.rst diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py index 85a51370b6..55ea082565 100644 --- a/_distutils_hack/__init__.py +++ b/_distutils_hack/__init__.py @@ -86,6 +86,13 @@ def spec_for_distutils(self): import importlib.abc import importlib.util + # In cases of path manipulation during sitecustomize, + # Setuptools might actually not be present even though + # the hook has been loaded. Allow the caller to fall + # back to stdlib behavior. See #2980. + if not importlib.util.find_spec('setuptools'): + return + class DistutilsLoader(importlib.abc.Loader): def create_module(self, spec): diff --git a/changelog.d/2980.misc.rst b/changelog.d/2980.misc.rst new file mode 100644 index 0000000000..222a3adbf2 --- /dev/null +++ b/changelog.d/2980.misc.rst @@ -0,0 +1 @@ +Bypass distutils loader when setuptools module is no longer available on sys.path.