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

Refactor project interpreter request for requires-python specifiers #4216

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Jun 10, 2024

Refactor following #4214 to avoid parsing the specifiers again

@zanieb zanieb added the preview Experimental behavior label Jun 10, 2024
@zanieb zanieb force-pushed the zb/fix-project-requires-python branch from 2c1499b to 8e63d1d Compare June 10, 2024 20:11
@zanieb zanieb marked this pull request as draft June 10, 2024 20:39
Base automatically changed from zb/version-request-range to main June 10, 2024 23:20
@zanieb zanieb force-pushed the zb/fix-project-requires-python branch from 8e63d1d to f444f3c Compare June 10, 2024 23:20
@zanieb zanieb marked this pull request as ready for review June 10, 2024 23:21
@zanieb zanieb changed the title Fix project interpreter support for requires-python specifiers Refactor project interpreter request for requires-python specifiers Jun 10, 2024
)
} else {
Toolchain::find(
None,
Copy link
Member Author

Choose a reason for hiding this comment

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

Guess I might want to make find take a Option<ToolchainRequest> as well.

Copy link
Member

Choose a reason for hiding this comment

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

Personally find it a little easier to read as:

let interpreter = python
    .map(ToolchainRequest::parse)
    .or(requires_python
        .map(|specifiers| ToolchainRequest::Version(VersionRequest::Range(specifiers.clone()))))
    .map_or_else(
        || {
            Toolchain::find(
                None,
                // Otherwise we'll try to use the venv we just deleted.
                SystemPython::Required,
                preview,
                cache,
            )
        },
        |request| {
            Toolchain::find_requested(
                &request,
                // Otherwise we'll try to use the venv we just deleted.
                SystemPython::Required,
                preview,
                cache,
            )
        },
    )?
    .into_interpreter();

But totally subjective.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oooh that's really nice haha but... I think I still want to refactor Toolchain::find to just not take strings anymore so I'll probably just merge and change it later.

Copy link
Member

Choose a reason for hiding this comment

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

Wow...

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 want it in the release and it's after work hours! hehe

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 do really like it actually <3

@zanieb zanieb merged commit f296ef0 into main Jun 11, 2024
47 checks passed
@zanieb zanieb deleted the zb/fix-project-requires-python branch June 11, 2024 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants