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 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
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 @@ -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
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