Skip to content

Refactor project interpreter request for requires-python specifiers - #4216

Merged
zanieb merged 1 commit into
mainfrom
zb/fix-project-requires-python
Jun 11, 2024
Merged

zanieb merged 1 commit into
mainfrom
zb/fix-project-requires-python

Conversation

@zanieb

@zanieb zanieb commented Jun 10, 2024 •

Copy link
Copy Markdown
Member

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/version-request-range branch from fc7e190 to 1321ccf Compare June 10, 2024 20:11
@zanieb
zanieb force-pushed the zb/fix-project-requires-python branch from 2c1499b to 8e63d1d Compare June 10, 2024 20:11
@zanieb
zanieb force-pushed the zb/version-request-range branch from 1321ccf to d19f861 Compare June 10, 2024 20:35
@zanieb
zanieb marked this pull request as draft June 10, 2024 20:39
@zanieb
zanieb force-pushed the zb/version-request-range branch from 1a449ca to 662a4c2 Compare June 10, 2024 22:40
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wow...

Copy link
Copy Markdown
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
Copy Markdown
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
@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