Skip to content

Infer python dist ics from pyproject#23495

Open
thani-ath-nain wants to merge 4 commits into
pantsbuild:mainfrom
thani-ath-nain:infer-python-dist-ics-from-pyproject
Open

Infer python dist ics from pyproject#23495
thani-ath-nain wants to merge 4 commits into
pantsbuild:mainfrom
thani-ath-nain:infer-python-dist-ics-from-pyproject

Conversation

@thani-ath-nain

Copy link
Copy Markdown
Contributor

A python_distribution target now infers its interpreter_constraints from the [project].requires-python value in a pyproject.toml in the same directory, when the field is not set explicitly. An explicit interpreter_constraints field still takes precedence, and targets without a sibling pyproject.toml (or requires-python) continue to fall back to [python].interpreter_constraints (#23417).

Happy to take feedback and add / remove changes that maintainers suggest.

@ndellosa95 ndellosa95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have a few nits but looks good overall and thanks for handling this!

value: InterpreterConstraints


def _pyproject_requires_python(contents: DigestContents, address: Address) -> str | None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change the signature of this function to just take file_content: bytes and move the digest contents unboxing and exception handling to the rule? This makes it easier to unit test the specific toml parsing we want to do.



@rule
async def resolve_python_distribution_effective_interpreter_constraints(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we cut out the wrapper types and go right from PythonDistributionInterpreterConstraintsField -> InterpreterConstraints?

if requires_python is None:
return None
if not isinstance(requires_python, str):
raise InvalidFieldException(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We typically use InvalidFieldException for invalid Pants fields. I think there's a separate exception we typically use here, or maybe just ValueError?

@ndellosa95
ndellosa95 requested review from benjyw and cburroughs July 6, 2026 19:49
@cburroughs

Copy link
Copy Markdown
Contributor

Thanks for the contribution. We've just branched for 2.33.x, so merging this pull request now will come out in 2.34.x, please move the release notes updates to docs/notes/2.34.x.md if that's appropriate.

@thani-ath-nain
thani-ath-nain force-pushed the infer-python-dist-ics-from-pyproject branch from 2222f03 to f56d292 Compare July 17, 2026 19:03
@thani-ath-nain

Copy link
Copy Markdown
Contributor Author

Thank you for taking the time to review these changes @ndellosa95 I have addressed your comments, but please do let me know if any follow-up change is required. Also, I have moved the release notes to 2.34 @cburroughs

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.

3 participants