Skip to content

Commit

Permalink
Fixed being unable to find distutils submodules by name when in a vir…
Browse files Browse the repository at this point in the history
…tualenv (#672)

Close pylint-dev/pylint#73
  • Loading branch information
AWhetter authored and PCManticore committed May 23, 2019
1 parent 66e673b commit 6ca01e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Release Date: TBA

Close PyCQA/pylint#1628

* Fixed being unable to find distutils submodules by name when in a virtualenv.

Close PyCQA/pylint#73

What's New in astroid 2.2.0?
============================
Expand Down
7 changes: 7 additions & 0 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import abc
import collections
import distutils
import enum
import imp
import os
Expand Down Expand Up @@ -145,6 +146,12 @@ def contribute_to_path(self, spec, processed):
for p in sys.path
if os.path.isdir(os.path.join(p, *processed))
]
# We already import distutils elsewhere in astroid,
# so if it is the same module, we can use it directly.
elif spec.name == "distutils" and spec.location in distutils.__path__:
# distutils is patched inside virtualenvs to pick up submodules
# from the original Python, not from the virtualenv itself.
path = list(distutils.__path__)
else:
path = [spec.location]
return path
Expand Down
5 changes: 5 additions & 0 deletions astroid/tests/unittest_modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""
unit tests for module modutils (module manipulation utilities)
"""
import distutils.version
import email
import os
import sys
Expand Down Expand Up @@ -60,6 +61,10 @@ def test_find_egg_module(self):
["data", "MyPyPa-0.1.0-py2.5.egg", self.package],
)

def test_find_distutils_submodules_in_virtualenv(self):
found_spec = spec.find_spec(["distutils", "version"])
self.assertEqual(found_spec.location, distutils.version.__file__)


class LoadModuleFromNameTest(unittest.TestCase):
""" load a python module from it's name """
Expand Down

0 comments on commit 6ca01e0

Please sign in to comment.