Skip to content

Remove module importing hack #1890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1890.change.rst
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 0 additions & 7 deletions pkg_resources/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ def load_module(self, fullname):
__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 prefix and sys.version_info > (3, 3):
del sys.modules[extant]
return mod
except ImportError:
pass
Expand Down
7 changes: 0 additions & 7 deletions setuptools/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ def load_module(self, fullname):
__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
Expand Down
22 changes: 22 additions & 0 deletions setuptools/tests/test_extern.py
Original file line number Diff line number Diff line change
@@ -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()))