-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Allow envvar POETRY_PROJECT_PLUGIN_CACHE to override plugin cache path #10618
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
Open
colindean
wants to merge
2
commits into
python-poetry:main
Choose a base branch
from
colindean:patch-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Mixing Path and str types in os.environ.get default may cause issues.
Since os.environ.get returns a str if the variable is set, PATH may be a str or Path. To avoid type issues, wrap the result with Path(), ensuring PATH is always a Path object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I hate it:
slightly better:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to refactor this constant to a static method… that would enable testing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactoring the constant to a static method is a solid approach! It makes the logic testable and more flexible for future changes. You could implement it like this:
This way, you can easily write tests for different environment variable scenarios, and the type consistency is maintained. If you need to keep a class-level attribute, you could also set
PATH = get_path()in__init__or as a property. Let me know if you'd like a test example or further tweaks!Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sourcery-ai Refactor usages of ProjectPluginCache.PATH, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely! If you refactor
ProjectPluginCache.PATHto a static method (e.g.,get_path()), you'll need to update all usages ofProjectPluginCache.PATHthroughout the codebase and tests. For example, any code like:should become:
This change will ensure that the plugin cache path is always computed dynamically, making it easier to test and to respect the environment variable override. You can search for all usages of
ProjectPluginCache.PATHin your codebase and update them accordingly. If you need help with a specific usage or want a test example for the new method, let me know!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sourcery-ai I hoped you would provide a comment with a suggestion code block ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a suggestion for refactoring usages of
ProjectPluginCache.PATHto use a static methodget_path(). This will ensure all references dynamically compute the path and respect the environment variable override.First, update the class definition:
Then, update all usages of
ProjectPluginCache.PATHtoProjectPluginCache.get_path():src/poetry/plugins/plugin_manager.py
tests/console/test_application.py
tests/plugins/test_plugin_manager.py
This approach keeps the logic centralized and testable. If you need a more detailed diff or want to see how to update a specific test, let me know!