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

Expand the pipenv resolver to be more customizable for what python version is specified and how markers should evaluate. #5931

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

matteius
Copy link
Member

@matteius matteius commented Sep 11, 2023

I am exploring how the resolver determines what python version its using and what markers to evaluate against.

The issue

Fixes #5908

The fix

Adds another reserved named category for pipenv and a patch to packaging, that allows overriding any of the default environment keys. Additionally, support ranges for python_version and python_full_version and a python key to specify the base package finder python version to use for the resolver.

In my example, I've added these constraints to our Pipfile to show that I can resolve the requirements that require python 3.7 using a python 3.11 version.

Also explore allowing multiple operating system markers to resolve.

Note: This branch started as me removing some unused code based on a coverage report and some extra analysis.

The checklist

  • Associated issue
  • A news fragment in the news/ directory to describe this fix with the extension .bugfix.rst, .feature.rst, .behavior.rst, .doc.rst. .vendor.rst. or .trivial.rst (this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.

…ersion is specified and how markers should evaluate.
@@ -236,7 +236,6 @@ def _evaluate_markers(markers: List[Any], environment: Dict[str, str]) -> bool:
else:
lhs_value = lhs.value
rhs_value = _get_env(environment, rhs.value)

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 should undo this non-change.

@matteius matteius requested a review from oz123 September 16, 2023 03:01
@@ -99,8 +54,6 @@ def get_source_list(


def parse_indexes(line, strict=False):
from argparse import ArgumentParser
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't agree with the linter here.

from argparse import ArgumentParser

Can be used locally inside a function if it's imported to be used in a different place.
Imports can be expensive (argparse isn't giant, but still...).
The linter rule here should be relaxed.

@@ -1,18 +1,11 @@
from __future__ import annotations

import re
from collections.abc import Mapping
from argparse import ArgumentParser
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment below.

@@ -41,3 +41,9 @@ test = "pytest -vvs"

[pipenv]
allow_prereleases = true

[resolver]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to be optional for usrers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup -- the code still gets the default platform dictionary, this just provide a mechanism to override.

python_full_version = "3.7.13"
python_version = "3.7"
finder_python = "3.7"
os_name = "win32"
Copy link
Contributor

Choose a reason for hiding this comment

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

How do teams that work on multiple OS can specify multiple OSs here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a minimal patch, so it doesn't provide a way to target multiple versions -- I went down that path initially but it involves changes in the packaging markers code, and it got too complicated for a first pass.

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.

Issue resolving of python version with point python version check
2 participants