Skip to content
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

Prevent first-party imports from being resolved to site-packages #1756

Merged

Conversation

jacobtylerwalls
Copy link
Member

Description

Regression in 5067f08.

Type of Changes

Type
βœ“ πŸ› Bug fix

Related Issue

Closes pylint-dev/pylint#7365

@jacobtylerwalls jacobtylerwalls added the pylint-tested PRs that don't cause major regressions with pylint label Aug 27, 2022
@coveralls
Copy link

coveralls commented Aug 27, 2022

Pull Request Test Coverage Report for Build 2943907425

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 92.35%

Totals Coverage Status
Change from base Build 2940627623: 0.003%
Covered Lines: 9718
Relevant Lines: 10523

πŸ’› - Coveralls

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 but let's wait for another review :)

@Pierre-Sassoulas
Copy link
Member

@DanielNoord could you check this please ? I'm thinking of releasing astroid 2.14.5 once it's merged.

@jacobtylerwalls
Copy link
Member Author

jacobtylerwalls commented Aug 28, 2022

EDIT: fixed in 22ce69e
Test passes on macOS for me locally but fails on CI because of a discrepancy between:
'/home/runner/work/astroid/astroid/venv/lib/python3.7/site-packages' found by sysconfig.get_path("purelib")
and
'/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages' found by python's import system

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Change itself looks good, just some stylistic and trivial changes! Thanks @jacobtylerwalls!

@@ -15,6 +15,13 @@

@lru_cache(maxsize=4096)
def is_namespace(modname: str) -> bool:
from astroid.modutils import ( # pylint: disable=import-outside-toplevel
EXT_LIB_DIRS,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we move these to const to remove any import cycles? We could also move the union there.

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered that, but there's too much logic in modutils that would have to be moved. My preference would be to move is_namespace into modutils, but I'd prefer to do that in a followup commit that wouldn't be backported. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be good to back port this. We never know how long it takes until we release a minor version and we might want to make more fixes here.

I'd be happy to make a back port PR πŸ˜„

Copy link
Member

Choose a reason for hiding this comment

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

I opened #1759 we just need to merge this and cherry pick it before releasing 2.12.5.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it would be good to back port this

Ah, we might be miscommunicating! I'm saying yes, we should definitely backport the crash fix, but also that I wouldn't want to block that on refactoring the cyclic import out. There's a lot of logic in modutils that would have to be moved, and it's all public, so I wouldn't want to break backwards compatibility on that in a patch release.

So I was hoping to merge and backport this in its current form, and leave the refactor for another day (and not backport the refactor, as usual). How does that sound?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's merge this as is, but let's also back port the refactor. Like I said: with astroid the time in between minor versions can be quite long and we might need to fix something and release a patch version after the refactor. To avoid future merge issues I would also merge any refactor to this particular piece of code.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @DanielNoord about cherry-picking the refactors. Case in point the 2.12 maintenance branch has been live for 2 months now. Cherry-picking things after a refactor without the refactor is a lot harder than just cherry-picking the refactor too. (We do need to make sure our refactor are just refactor, but we never had any problem with this so far).

astroid/interpreter/_import/util.py Show resolved Hide resolved
dalcinl added a commit to mpi4py/mpi4py that referenced this pull request Aug 28, 2022
@dalcinl
Copy link

dalcinl commented Aug 28, 2022

@jacobtylerwalls Success!

Rather than fighting with local reproduction, I fired up a test on the original place of failure, that is, GitHub Actions.

I force-installed this PR the following way. The pylint run step is now clean.

Many thanks for the prompt address of this issue! I really appreciate it.

@DanielNoord DanielNoord merged commit 5dfc004 into pylint-dev:main Aug 29, 2022
Pierre-Sassoulas added a commit that referenced this pull request Aug 29, 2022
…1756)

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Pierre-Sassoulas added a commit that referenced this pull request Aug 29, 2022
…1756)

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
@jacobtylerwalls jacobtylerwalls deleted the first-party-import-ext-lib branch August 29, 2022 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug πŸͺ³ pylint-tested PRs that don't cause major regressions with pylint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First-party import incorrectly resolved to site-packages rather than source
5 participants