From 299d27655f3f3a06d698b9ae06a3e3ad13943e81 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 18 Jul 2024 10:42:40 -0400 Subject: [PATCH] Reset the backports module when enabling vendored packages. Closes #4476 --- newsfragments/4476.bugfix.rst | 1 + pkg_resources/__init__.py | 2 ++ ruff.toml | 5 +++++ setuptools/__init__.py | 2 ++ 4 files changed, 10 insertions(+) create mode 100644 newsfragments/4476.bugfix.rst diff --git a/newsfragments/4476.bugfix.rst b/newsfragments/4476.bugfix.rst new file mode 100644 index 0000000000..96122578c8 --- /dev/null +++ b/newsfragments/4476.bugfix.rst @@ -0,0 +1 @@ +Reset the backports module when enabling vendored packages. \ No newline at end of file diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 822232a7fb..6b273d4d23 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -75,6 +75,8 @@ import _imp sys.path.extend(((vendor_path := os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setuptools', '_vendor')) not in sys.path) * [vendor_path]) # fmt: skip +# workaround for #4476 +sys.modules.pop('backports', None) # capture these to bypass sandboxing from os import utime diff --git a/ruff.toml b/ruff.toml index be78969cdb..af3c567d83 100644 --- a/ruff.toml +++ b/ruff.toml @@ -43,6 +43,11 @@ ignore = [ "ISC002", ] +# Suppress nuisance warnings about E402 due to workaround for #4476 +[lint.per-file-ignores] +"setuptools/__init__.py" = ["E402"] +"pkg_resources/__init__.py" = ["E402"] + [format] # Enable preview to get hugged parenthesis unwrapping preview = true diff --git a/setuptools/__init__.py b/setuptools/__init__.py index 8b0e494f01..afca08be9c 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -7,6 +7,8 @@ from typing import TYPE_CHECKING sys.path.extend(((vendor_path := os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setuptools', '_vendor')) not in sys.path) * [vendor_path]) # fmt: skip +# workaround for #4476 +sys.modules.pop('backports', None) import _distutils_hack.override # noqa: F401 import distutils.core