Skip to content

Commit

Permalink
Restore custom distutils handling for resolving paths to submodules. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Feb 27, 2022
1 parent 8f7f078 commit 62aa3bb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/release-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release tests

on: workflow_dispatch

env:
DEFAULT_PYTHON: 3.8

jobs:
virtualenv-15-windows-test:
# Regression test added in https://github.com/PyCQA/astroid/pull/1386
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
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Create Python virtual environment with virtualenv==15.1.0
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 no import-error from distutils.util
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 @@ -110,6 +110,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
17 changes: 17 additions & 0 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import collections
import enum
import importlib.machinery
import importlib.util
import os
import sys
import zipimport
from functools import lru_cache
from pathlib import Path

from . import util

Expand Down Expand Up @@ -160,6 +162,21 @@ 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
# https://github.com/PyCQA/pylint/issues/5645
# A regression test to create this scenario exists in release-tests.yml
# and can be triggered manually from GitHub Actions
distutils_spec = importlib.util.find_spec("distutils")
if distutils_spec and distutils_spec.origin:
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
2 changes: 2 additions & 0 deletions doc/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ So, you want to release the `X.Y.Z` version of astroid ?

## Process

(Consider triggering the "release tests" workflow in GitHub Actions first.)

1. Check if the dependencies of the package are correct
2. Check the result (Do `git diff vX.Y.Z-1 ChangeLog` in particular).
3. Install the release dependencies `pip3 install pre-commit tbump`
Expand Down

0 comments on commit 62aa3bb

Please sign in to comment.