Skip to content

Use sysconfig.get_path instead of distutils to find stdlib #1323

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 7 commits into from
Feb 1, 2022

Conversation

DanielNoord
Copy link
Collaborator

Steps

  • Write a good description on what the PR does.

Description

2/3 of PRs mentioned in #1322

For the change in this PR:
get_python_lib will "If standard_lib is true, the directory for the standard library is returned rather than the directory for the installation of third-party extensions."
This is thus the parent directory of site-packages.
This functionality is "replaced" by sysconfig.get_path with stdlib.

The commit that added this particular fix was 70b7afc

I have looked around but the closest I got to finding any information on the presumed bug was https://bugs.python.org/issue11320. I also found a number of older Python 2 and 3.6 < issues about virtualenv and distutils. I couldn't find the actual issue here..
However, I think sysconfig in combination with newer versions of virtualenv have fixed these underlying issues. The tests seems to pass anyway, so I would argue to go for the YOLO-option here as well: we need to get rid of distutils someday anyway 😅

Type of Changes

Type
🔨 Refactoring

Related Issue

@DanielNoord DanielNoord added the Maintenance Discussion or action around maintaining astroid or the dev workflow label Dec 31, 2021
@cdce8p cdce8p self-assigned this Dec 31, 2021
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! Thank you for opening small MR for this. I think sys config was not used before because it was not available in python 3.5 [citation required], and that it's pretty safe to use it now that we support only > 3.6.2.

# non-valid path, see https://bugs.pypy.org/issue1164
except DistutilsPlatformError:
STD_LIB_DIRS = set()
STD_LIB_DIRS = {sysconfig.get_path("stdlib")}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include sysconfig.get_path("platstdlib") too?
That would match get_python_lib(standard_lib=True, prefix=sys.prefix).

{
 'platstdlib': '/home/runner/work/astroid/astroid/venv/lib/python3.10',
 'stdlib': '/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10'
}

Usually stdlib should be enough. I just don't know if virtualenv or others do something unexpected with the lib files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure? It was added in:
b8c4825
But there was not test or related issue that prompted the change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would had to be a virtualenv issue from the looks of it. Tbh I don't know if it has been fixed in the meantime. Maybe we should include in for now, just to be safe. The additional path doesn't really hurt.

If we really want to, we could revisit this in the future and just remove it then to see if it causes any new regressions. I just wouldn't suggest to do it now. It would make it more difficult to see if the current changes were correct.

@DanielNoord
Copy link
Collaborator Author

By the way, for some reason the previous crash no longer happens after merging main. I'd like to investigate this.

@cdce8p
Copy link
Member

cdce8p commented Jan 31, 2022

By the way, for some reason the previous crash no longer happens after merging main. I'd like to investigate this.

Which crash?

@DanielNoord
Copy link
Collaborator Author

See failing test in the first commit and the issue I opened against python. This wasn't actually a python issue but rather something to do with astroid adding itself to PATH. That seems to have been resolved I guess? But I haven't looked into what actually changed.

@cdce8p
Copy link
Member

cdce8p commented Jan 31, 2022

See failing test in the first commit and the issue I opened against python. This wasn't actually a python issue but rather something to do with astroid adding itself to PATH. That seems to have been resolved I guess? But I haven't looked into what actually changed.

It looks like the setuptools / distutils.version issue we dealt we back in December. So all good I think.
https://github.com/PyCQA/astroid/runs/4673501905?check_suite_focus=true#step:6:67

@DanielNoord
Copy link
Collaborator Author

DanielNoord commented Jan 31, 2022

See failing test in the first commit and the issue I opened against python. This wasn't actually a python issue but rather something to do with astroid adding itself to PATH. That seems to have been resolved I guess? But I haven't looked into what actually changed.

It looks like the setuptools / distutils.version issue we dealt we back in December. So all good I think. https://github.com/PyCQA/astroid/runs/4673501905?check_suite_focus=true#step:6:67

Well.. That actually regressed 😓 See pylint-dev/pylint#5645.

Hmm looking back the failing test is not actually related. Let me have another look.

Edit: I'm mixing up my PRs. See #1326, that's where I opened an incorrect issue report against Python.

@cdce8p
Copy link
Member

cdce8p commented Feb 1, 2022

Well.. That actually regressed 😓 See PyCQA/pylint#5645.

Hmm looking back the failing test is not actually related. Let me have another look.

Edit: I'm mixing up my PRs. See #1326, that's where I opened an incorrect issue report against Python.

😞 We did however remove the failing test case with it and it wasn't added back. That at least explains why this one isn't failing anymore. https://github.com/PyCQA/astroid/pull/1321/files#diff-fce15b6315286261c040399638ba825e411e7c0284c1006a50aa271f405beef6L75

It should be safe to move forward with this PR. The last open items are probably

@DanielNoord DanielNoord requested a review from cdce8p February 1, 2022 17:30
Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some last formatting suggesting. Looks good otherwise!
Thank you @DanielNoord for driving the effort to replace distutils!

@cdce8p
Copy link
Member

cdce8p commented Feb 1, 2022

Think it's ready now 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining astroid or the dev workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants