refactor: make sure that `marker_env` is complete for each type of `Env`
- add a test that checks that
marker_envis equal for all types of envs - make
marker_envaTypedDict - add
sysconfig_platformtoSystemEnv.marker_env(is not used so that it is not a relevant bug that it was missing)
Pull Request Check List
Resolves: #issue-number-here
- [x] Added tests for changed code.
- [ ] Updated documentation for changed code.
Summary by Sourcery
Define a TypedDict for environment markers, enforce complete marker_env structures across all Env implementations, and add a test to ensure consistency
Bug Fixes:
- Add missing 'sysconfig_platform' key to SystemEnv.marker_env for completeness
Enhancements:
- Introduce MarkerEnv TypedDict and update marker_env method signatures in all Env classes
- Normalize MockEnv version_info to full PythonVersion tuple and streamline its marker_env assembly
- Replace dict.copy() with dict() constructors when copying marker_env in puzzle.transaction and provider modules
Tests:
- Add a test to assert marker_env equality for VirtualEnv, GenericEnv, and SystemEnv
- Refactor test fixtures and mocks to use the new PythonVersion alias instead of raw tuples
Chores:
- Update type hints in puzzle.transaction and provider to use Mapping[str, Any] for marker_env
Reviewer's Guide
Introduces a formal MarkerEnv TypedDict and migrates all marker_env APIs to use it (including adding sysconfig_platform), refactors MockEnv for consistent version_info handling and override merging, updates tests to leverage the new PythonVersion type and adds an equality check across env types, and adjusts puzzle modules to accept generic Mappings and cast them for marker_env.
Entity Relationship Diagram: New MarkerEnv Data Structure
erDiagram
MarkerEnv {
string implementation_name
string implementation_version
string os_name
string platform_machine
string platform_release
string platform_system
string platform_version
string python_full_version
string platform_python_implementation
string python_version
string sys_platform
string version_info "PythonVersion (tuple[int,int,int,str,int])"
string interpreter_name
string interpreter_version
string sysconfig_platform "New attribute"
}
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Define MarkerEnv TypedDict and update marker_env APIs to use it |
|
src/poetry/utils/env/base_env.pysrc/poetry/utils/env/virtual_env.pysrc/poetry/utils/env/system_env.pysrc/poetry/utils/env/mock_env.py |
| Refine MockEnv.get_marker_env logic |
|
src/poetry/utils/env/mock_env.py |
| Update tests for PythonVersion and add cross-env marker_env equality test |
|
tests/utils/env/test_env.pytests/console/commands/env/test_use.pytests/conftest.pytests/repositories/test_installed_repository.py |
| Adapt puzzle modules to accept generic mappings for marker_env |
|
src/poetry/puzzle/transaction.pysrc/poetry/puzzle/provider.py |
Tips and commands
Interacting with Sourcery
-
Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
-
Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. -
Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. -
Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. -
Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. -
Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. -
Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.