Skip to content

Commit c9a828d

Browse files
committed
Remove sys.modules hack
Fix #1888 (metadata accidentally not picklable), and removes a case where reimporting a vendored module results in a second copy of the same module.
1 parent 297f2ad commit c9a828d

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

changelog.d/1890.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix vendored dependencies so importing ``setuptools.extern.some_module`` gives the same object as ``setuptools._vendor.some_module``. This makes Metadata picklable again.

setuptools/extern/__init__.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,16 @@ def load_module(self, fullname):
4343
__import__(extant)
4444
mod = sys.modules[extant]
4545
sys.modules[fullname] = mod
46-
# mysterious hack:
47-
# Remove the reference to the extant package/module
48-
# on later Python versions to cause relative imports
49-
# in the vendor package to resolve the same modules
50-
# as those going through this importer.
51-
if sys.version_info >= (3, ):
52-
del sys.modules[extant]
5346
return mod
5447
except ImportError:
5548
pass
5649
else:
5750
raise ImportError(
58-
"The '{target}' package is required; "
59-
"normally this is bundled with this package so if you get "
60-
"this warning, consult the packager of your "
61-
"distribution.".format(**locals())
62-
)
51+
"The '{target}' package is required; "
52+
"normally this is bundled with this package so if you get "
53+
"this warning, consult the packager of your "
54+
"distribution.".format(**locals())
55+
)
6356

6457
def install(self):
6558
"""

setuptools/tests/test_extern.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import importlib
2+
import pickle
3+
4+
from setuptools import Distribution
5+
from setuptools.extern import ordered_set
6+
from setuptools.tests import py3_only
7+
8+
9+
def test_reimport_extern():
10+
ordered_set2 = importlib.import_module(ordered_set.__name__)
11+
assert ordered_set is ordered_set2
12+
13+
14+
def test_orderedset_pickle_roundtrip():
15+
o1 = ordered_set.OrderedSet([1, 2, 5])
16+
o2 = pickle.loads(pickle.dumps(o1))
17+
assert o1 == o2
18+
19+
20+
@py3_only
21+
def test_distribution_picklable():
22+
pickle.loads(pickle.dumps(Distribution()))

0 commit comments

Comments
 (0)