Skip to content

Commit 62aa3bb

Browse files
Restore custom distutils handling for resolving paths to submodules. (#1386)
1 parent 8f7f078 commit 62aa3bb

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

.github/workflows/release-tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release tests
2+
3+
on: workflow_dispatch
4+
5+
env:
6+
DEFAULT_PYTHON: 3.8
7+
8+
jobs:
9+
virtualenv-15-windows-test:
10+
# Regression test added in https://github.com/PyCQA/astroid/pull/1386
11+
name: Regression test for virtualenv==15.1.0 on Windows
12+
runs-on: windows-latest
13+
timeout-minutes: 5
14+
steps:
15+
- name: Check out code from GitHub
16+
uses: actions/[email protected]
17+
- name: Set up Python
18+
id: python
19+
uses: actions/[email protected]
20+
with:
21+
python-version: ${{ env.DEFAULT_PYTHON }}
22+
- name: Create Python virtual environment with virtualenv==15.1.0
23+
run: |
24+
python -m pip install virtualenv==15.1.0
25+
python -m virtualenv venv2
26+
. venv2\scripts\activate
27+
python -m pip install pylint
28+
python -m pip install -e .
29+
- name: Test no import-error from distutils.util
30+
run: |
31+
. venv2\scripts\activate
32+
echo "import distutils.util # pylint: disable=unused-import" > test.py
33+
pylint test.py

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ Release date: 2021-12-31
110110

111111
Ref #1321
112112

113+
* Restore custom ``distutils`` handling for resolving paths to submodules.
114+
115+
Closes PyCQA/pylint#5645
116+
113117
* Fix ``deque.insert()`` signature in ``collections`` brain.
114118

115119
Closes #1260

astroid/interpreter/_import/spec.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import collections
2020
import enum
2121
import importlib.machinery
22+
import importlib.util
2223
import os
2324
import sys
2425
import zipimport
2526
from functools import lru_cache
27+
from pathlib import Path
2628

2729
from . import util
2830

@@ -160,6 +162,21 @@ def contribute_to_path(self, spec, processed):
160162
for p in sys.path
161163
if os.path.isdir(os.path.join(p, *processed))
162164
]
165+
elif spec.name == "distutils":
166+
# virtualenv below 20.0 patches distutils in an unexpected way
167+
# so we just find the location of distutils that will be
168+
# imported to avoid spurious import-error messages
169+
# https://github.com/PyCQA/pylint/issues/5645
170+
# A regression test to create this scenario exists in release-tests.yml
171+
# and can be triggered manually from GitHub Actions
172+
distutils_spec = importlib.util.find_spec("distutils")
173+
if distutils_spec and distutils_spec.origin:
174+
origin_path = Path(
175+
distutils_spec.origin
176+
) # e.g. .../distutils/__init__.py
177+
path = [str(origin_path.parent)] # e.g. .../distutils
178+
else:
179+
path = [spec.location]
163180
else:
164181
path = [spec.location]
165182
return path

doc/release.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ So, you want to release the `X.Y.Z` version of astroid ?
44

55
## Process
66

7+
(Consider triggering the "release tests" workflow in GitHub Actions first.)
8+
79
1. Check if the dependencies of the package are correct
810
2. Check the result (Do `git diff vX.Y.Z-1 ChangeLog` in particular).
911
3. Install the release dependencies `pip3 install pre-commit tbump`

0 commit comments

Comments
 (0)