Skip to content

Restore custom distutils handling for resolving paths to submodules. #1386

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 15 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from 11 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
35 changes: 35 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,38 @@ jobs:
run: |
. venv/bin/activate
pytest tests/

specific-virtualenv-test:
name: Regression test for virtualenv==15.1.0 on Windows
runs-on: windows-latest
timeout-minutes: 5
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Restore Python virtual environment
id: cache-virtualenv15
uses: actions/[email protected]
with:
path: venv2
key: >-
${{ runner.os }}-virtualenv15
restore-keys: |
${{ runner.os }}-virtualenv15-${{ env.CACHE_VERSION }}
- name: Create Python virtual environment with virtualenv==15.1.0
if: steps.cache-virtualenv15_1_0.outputs.cache-hit != 'true'
run: |
python -m pip install virtualenv==15.1.0
python -m virtualenv venv2
. venv2\scripts\activate
python -m pip install pylint
python -m pip install -e .
- name: Test distutils edge case
run: |
. venv2\scripts\activate
echo "import distutils.util # pylint: disable=unused-import" > test.py
pylint test.py
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ Release date: 2021-12-31

Ref #1321

* Restore custom ``distutils`` handling for resolving paths to submodules.

Closes PyCQA/pylint#5645

* Fix ``deque.insert()`` signature in ``collections`` brain.

Closes #1260
Expand Down
13 changes: 13 additions & 0 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import sys
import zipimport
from functools import lru_cache
from pathlib import Path

from . import util

Expand Down Expand Up @@ -160,6 +161,18 @@ def contribute_to_path(self, spec, processed):
for p in sys.path
if os.path.isdir(os.path.join(p, *processed))
]
elif spec.name == "distutils":
# virtualenv below 20.0 patches distutils in an unexpected way
# so we just find the location of distutils that will be
# imported to avoid spurious import-error messages
distutils_spec = importlib.util.find_spec("distutils")
if distutils_spec:
origin_path = Path(
distutils_spec.origin
) # e.g. .../distutils/__init__.py
path = [str(origin_path.parent)] # e.g. .../distutils
else:
path = [spec.location]
else:
path = [spec.location]
return path
Expand Down