From 137ab9d684075f772c322f455b0dd1f992ddcd8f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 20 Dec 2021 19:46:08 -0500 Subject: Avoid KeyError in distutils hack when pip is imported during ensurepip. Fixes #2940. --- _distutils_hack/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to '_distutils_hack') diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py index da51b433..22bc9ed6 100644 --- a/_distutils_hack/__init__.py +++ b/_distutils_hack/__init__.py @@ -119,7 +119,11 @@ class DistutilsMetaFinder: @staticmethod def frame_file_is_setup(frame): - return frame.f_globals['__file__'].endswith('setup.py') + """ + Return True if the indicated frame suggests a setup.py file. + """ + # some frames may not have __file__ (#2940) + return frame.f_globals.get('__file__', '').endswith('setup.py') DISTUTILS_FINDER = DistutilsMetaFinder() -- cgit v1.2.1