aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Rose <dan@digilabs.io>2019-10-27 02:31:59 -0500
committerDan Rose <dan@digilabs.io>2019-10-27 02:59:55 -0500
commit2d25ca89318922e63b74c37e36d099173cf0da5a (patch)
tree4f96a50932b122eade8fcee76197b82de6e56858
parent297f2adceda3af402fc08311e42505c8cdc9c54b (diff)
downloadexternal_python_setuptools-2d25ca89318922e63b74c37e36d099173cf0da5a.tar.gz
external_python_setuptools-2d25ca89318922e63b74c37e36d099173cf0da5a.tar.bz2
external_python_setuptools-2d25ca89318922e63b74c37e36d099173cf0da5a.zip
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.
-rw-r--r--changelog.d/1890.change.rst1
-rw-r--r--setuptools/extern/__init__.py7
-rw-r--r--setuptools/tests/test_extern.py22
3 files changed, 23 insertions, 7 deletions
diff --git a/changelog.d/1890.change.rst b/changelog.d/1890.change.rst
new file mode 100644
index 00000000..458d8117
--- /dev/null
+++ b/changelog.d/1890.change.rst
@@ -0,0 +1 @@
+Fix vendored dependencies so importing ``setuptools.extern.some_module`` gives the same object as ``setuptools._vendor.some_module``. This makes Metadata picklable again. \ No newline at end of file
diff --git a/setuptools/extern/__init__.py b/setuptools/extern/__init__.py
index e8c616f9..4e79aa17 100644
--- a/setuptools/extern/__init__.py
+++ b/setuptools/extern/__init__.py
@@ -43,13 +43,6 @@ class VendorImporter:
__import__(extant)
mod = sys.modules[extant]
sys.modules[fullname] = mod
- # mysterious hack:
- # Remove the reference to the extant package/module
- # on later Python versions to cause relative imports
- # in the vendor package to resolve the same modules
- # as those going through this importer.
- if sys.version_info >= (3, ):
- del sys.modules[extant]
return mod
except ImportError:
pass
diff --git a/setuptools/tests/test_extern.py b/setuptools/tests/test_extern.py
new file mode 100644
index 00000000..3519a680
--- /dev/null
+++ b/setuptools/tests/test_extern.py
@@ -0,0 +1,22 @@
+import importlib
+import pickle
+
+from setuptools import Distribution
+from setuptools.extern import ordered_set
+from setuptools.tests import py3_only
+
+
+def test_reimport_extern():
+ ordered_set2 = importlib.import_module(ordered_set.__name__)
+ assert ordered_set is ordered_set2
+
+
+def test_orderedset_pickle_roundtrip():
+ o1 = ordered_set.OrderedSet([1, 2, 5])
+ o2 = pickle.loads(pickle.dumps(o1))
+ assert o1 == o2
+
+
+@py3_only
+def test_distribution_picklable():
+ pickle.loads(pickle.dumps(Distribution()))