Skip to content

Make manager required in AstroidBuilder/InspectBuilder #2313

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

Conversation

jacobtylerwalls
Copy link
Member

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

Closes #251

Remove delayed imports in AstroidManager by requiring AstroidManager to be provided to AstroidBuilder/InspectBuilder.

A couple new delayed imports became necessary, but they're in helpers like parse() and _astroid_bootstrapping(). We could address those by:

  • Requiring AstroidManager for parse() calls also.
  • Moving _astroid_bootstrapping() to manager.py.

@jacobtylerwalls jacobtylerwalls added this to the 4.0.0 milestone Sep 30, 2023
@jacobtylerwalls jacobtylerwalls force-pushed the refactor-circular-manager branch from 938cbee to c9399bb Compare September 30, 2023 16:17
@codecov
Copy link

codecov bot commented Sep 30, 2023

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 93.19%. Comparing base (6805fa3) to head (c452b0f).
Report is 47 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2313      +/-   ##
==========================================
- Coverage   93.19%   93.19%   -0.01%     
==========================================
  Files          93       93              
  Lines       11088    11066      -22     
==========================================
- Hits        10334    10313      -21     
+ Misses        754      753       -1     
Flag Coverage Ξ”
linux 93.08% <100.00%> (-0.01%) ⬇️
pypy 93.19% <100.00%> (-0.01%) ⬇️
windows 93.19% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Ξ”
astroid/brain/brain_nose.py 95.00% <100.00%> (ΓΈ)
astroid/builder.py 95.13% <100.00%> (+0.02%) ⬆️
astroid/interpreter/_import/spec.py 97.26% <100.00%> (+0.01%) ⬆️
astroid/manager.py 89.75% <100.00%> (-0.21%) ⬇️
astroid/raw_building.py 94.53% <100.00%> (-0.02%) ⬇️
astroid/rebuilder.py 98.18% <100.00%> (-0.03%) ⬇️

... and 3 files with indirect coverage changes

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

This one bring a lot of joy. Were you able to use nodes.X instead of X thanks to the fixed circular imports ?

@jacobtylerwalls
Copy link
Member Author

I didn't have a choice, because the second import statement [from nodes import ...] was failing because nodes was now partially installed at that point. I think before, it was an accident that nodes was fully initialized already.

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.

Although really in favour, this do introduce more global state for AstroidManager(), see also #2048.

As long as AstroidManager is a singleton we'll keep accessing shared memory in multiprocessing scenarios. Ideally, to me, we would change it in 4.x so that the manager needs to be instantiated.

@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label May 6, 2024
@jacobtylerwalls
Copy link
Member Author

Although really in favour, this do introduce more global state for AstroidManager(), see also #2048.

Getting back up to speed on this to see if I can get it in for 4.0. @DanielNoord can you remind me what you meant by "more global state"? I'm not sure I follow.

@DanielNoord
Copy link
Collaborator

From my testing with multiprocessing on of the issues is that the cache of all nodes is stored on the manager, which means that we have a lot of dependency on this one shared object. Since it is global, and not passed or instantiated in pylint, it is quite hard to extract that dependency and (for example) give every process its own cache.

I'm fine with this PR, but I do think at some point we need to look into making the manager something that is instantiated by the process that wants to do inference.

@jacobtylerwalls jacobtylerwalls force-pushed the refactor-circular-manager branch from c9399bb to 2b3ee1b Compare February 2, 2025 18:36
@jacobtylerwalls jacobtylerwalls force-pushed the refactor-circular-manager branch from f917b0b to 1e06ce2 Compare February 2, 2025 18:41
@jacobtylerwalls jacobtylerwalls changed the title [4.0.x] Make manager required in AstroidBuilder/InspectBuilder Make manager required in AstroidBuilder/InspectBuilder Feb 2, 2025
@jacobtylerwalls jacobtylerwalls marked this pull request as ready for review February 2, 2025 18:42
@jacobtylerwalls
Copy link
Member Author

Thanks.

As long as AstroidManager is a singleton we'll keep accessing shared memory in multiprocessing scenarios. Ideally, to me, we would change it in 4.x so that the manager needs to be instantiated.

Makes sense. For another day :-)

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, just a nit.

def visit_matchor(self, node: ast.MatchOr, parent: NodeNG) -> nodes.MatchOr:
def visit_matchor(
self, node: ast.MatchOr, parent: nodes.NodeNG
) -> nodes.MatchOr:
newnode = nodes.MatchOr(
lineno=node.lineno,
col_offset=node.col_offset,
Copy link
Member

Choose a reason for hiding this comment

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

This file would deserve to be a package, github refuse to display the diff, like it's a package-lock.json. (Just a passing observation, I'm not suggesting we immediately do something about it)

Co-authored-by: Pierre Sassoulas <[email protected]>
@Pierre-Sassoulas Pierre-Sassoulas merged commit 3c6516e into pylint-dev:main Feb 3, 2025
20 checks passed
@jacobtylerwalls jacobtylerwalls deleted the refactor-circular-manager branch February 3, 2025 12:55
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 4.0.0, 4.0.0a0 Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor circular dependency in builder, manager, and raw_building
3 participants