Skip to content

Commit 5cdfa53

Browse files
authored
Merge pull request #112 from ISISComputingGroup/dont_import_pip
Don't import pip
2 parents ee8674a + 28b393d commit 5cdfa53

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

test_genie_python_common_imports.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99
"dockerpty", # Not supported on windows
1010
"adodbapi", # Not needed by users
1111
"black", # Not needed by users
12+
# importing pip overwrites distutils in sys.modules
13+
# with a copy of setuptools instead, which then breaks
14+
# any packages that depend on distutils directly.
15+
# https://github.com/pypa/pip/issues/8761
16+
#
17+
# Importing pip as a module in general is a bad idea (tm), so just don't do that.
18+
#
19+
# It's possible to use:
20+
# >>> import _distutils_hack
21+
# >>> _distutils_hack.remove_shim()
22+
# >>> import pip
23+
# if someone *really* needs to import pip (yes, seriously; no, it's not a good idea).
24+
"pip",
1225
}
1326

1427

@@ -17,7 +30,7 @@ class TestGeniePythonImports(unittest.TestCase):
1730
Tests that modules which users use can be imported.
1831
"""
1932

20-
def _attempt_to_import_module_by_name(self, module_name):
33+
def _attempt_to_import_module_by_name(self, module_name: str) -> str | None:
2134
"""
2235
Attempts to import a module by name.
2336
:param module_name: the module name to import
@@ -38,12 +51,13 @@ def _attempt_to_import_module_by_name(self, module_name):
3851
else:
3952
return None
4053

41-
def test_WHEN_importing_all_installed_packages_THEN_no_error(self):
54+
def test_WHEN_importing_all_installed_packages_THEN_no_error(self) -> None:
4255
"""
4356
This tests that all of the modules we've installed are importable as modules.
4457
"""
4558

46-
# Ignore warnings. We get lots of these from various modules and it's too noisy for this test suite.
59+
# Ignore warnings. We get lots of these from various modules and it's too noisy for this
60+
# test suite.
4761
warnings.filterwarnings("ignore")
4862

4963
failures = []

0 commit comments

Comments
 (0)