Skip to content

refactor: make sure that marker_env is complete for each type of Env #10414

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

radoering
Copy link
Member

@radoering radoering commented May 31, 2025

  • add a test that checks that marker_env is equal for all types of envs
  • make marker_env a TypedDict
  • add sysconfig_platform to SystemEnv.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

  • 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

Copy link

sourcery-ai bot commented May 31, 2025

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"
    }
Loading

File-Level Changes

Change Details Files
Define MarkerEnv TypedDict and update marker_env APIs to use it
  • Add MarkerEnv TypedDict listing all environment marker keys including sysconfig_platform
  • Change Env.marker_env and get_marker_env signatures to return MarkerEnv
  • Update VirtualEnv.get_marker_env to load JSON as MarkerEnv and convert version_info to tuple
  • Update SystemEnv.get_marker_env signature to return MarkerEnv
src/poetry/utils/env/base_env.py
src/poetry/utils/env/virtual_env.py
src/poetry/utils/env/system_env.py
src/poetry/utils/env/mock_env.py
Refine MockEnv.get_marker_env logic
  • Support version_info as 3- or 5-tuple and normalize to full PythonVersion
  • Adjust python_full_version to use only the first three components
  • Defer merging of _mock_marker_env overrides until after default keys are set
src/poetry/utils/env/mock_env.py
Update tests for PythonVersion and add cross-env marker_env equality test
  • Import and use PythonVersion instead of raw tuple[int,int,int] in fixtures and mocks
  • Adjust check_output_wrapper invocation to unpack only first three version parts
  • Add test asserting marker_env equality across VirtualEnv, GenericEnv, and SystemEnv
tests/utils/env/test_env.py
tests/console/commands/env/test_use.py
tests/conftest.py
tests/repositories/test_installed_repository.py
Adapt puzzle modules to accept generic mappings for marker_env
  • Change marker_env parameter type in transaction to Mapping[str,Any]
  • Replace .copy() calls with dict() to support Mapping
  • Apply same dict() casting in provider when injecting extras
src/poetry/puzzle/transaction.py
src/poetry/puzzle/provider.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on 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 issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on 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 dismiss on 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 review to 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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @radoering - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@radoering radoering requested a review from a team May 31, 2025 16:03
@radoering radoering force-pushed the typed-dict-marker-env branch from 1a17ed1 to feeee27 Compare June 7, 2025 04:34
@radoering radoering force-pushed the typed-dict-marker-env branch 2 times, most recently from cbbf051 to cae264b Compare June 29, 2025 15:15
* add a test that checks that `marker_env` is equal for all types of envs
* make `marker_env` a `TypedDict`
* add `sysconfig_platform` to `SystemEnv.marker_env` (is not used so that it is not a relevant bug that it was missing)
@radoering radoering force-pushed the typed-dict-marker-env branch from cae264b to 253a30a Compare August 3, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant