-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
Parse pyproject.toml statically where possible #1964
Conversation
Plz use pathlib everywhere instead of low-level os calls. |
Sure, was just matching style to preexisting code |
Just to be explicit: atugushev suggested I don't work on this PR until #1681 is merged. This makes sense to me, since the two conflict. |
Hey @hauntsaninja, that PR was merged about a month ago. So it seems like this one can be considered unblocked. |
1fcb6c9
to
15de8f0
Compare
for more information, see https://pre-commit.ci
Thanks for the nudge, I've rebased the changes on top of main |
Ah, I was just cleaning up the old notification emails and noticed this.. Since this looks up the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that such changes require tests. Could you add some?
piptools/build.py
Outdated
@@ -41,6 +48,67 @@ class ProjectMetadata: | |||
build_requirements: tuple[InstallRequirement, ...] | |||
|
|||
|
|||
def maybe_statically_parse_project_metadata( | |||
src_file: pathlib.Path, | |||
) -> ProjectMetadata | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better not to use None
as a magic sentinel value that the caller shouldn't forget to check for.
Instead, how about raising a LookupError
. The handling would be cleaner, then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we're using a static type checker, I think that would actually be less safe. mypy will complain if you do not handle None, but it will not complain if you do not handle the exception
piptools/build.py
Outdated
comes_from = f"{package_name} ({src_file}::build-system.requires)" | ||
build_requirements = [ | ||
InstallRequirement(Requirement(req), comes_from) | ||
for req in pyproject_contents.get("build-system", {}).get("requires", []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't return complete build deps. It should call the corresponding hooks or not inject the build deps at all. An incomplete list would be harmful, expectations-wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
Could you also include more information regarding the motivation, use case, possible side effects, usage examples etc. into the PR description? Make sure all of those are also present as tests. |
Oh, and it looks like the contributor checklist might've been overlooked, could you verify? |
14502f4
to
1d95efd
Compare
Thanks for the initial review! I pushed a bunch of changes; this should now be much closer to shippable |
:param isolated: Whether to run invoke the backend in the current | ||
environment or to create an isolated one and invoke it | ||
there. | ||
:param quiet: Whether to suppress the output of subprocesses. | ||
""" | ||
|
||
if attempt_static_parse: | ||
if build_targets: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you prefer to do this implicitly based on the value of build_targets
, instead of having a separate param. I did it this way because it feels a little easier to test / harder to mess up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how you did it.
Co-authored-by: chrysle <[email protected]>
Co-authored-by: chrysle <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@webknjaz Could you review again? This is a larger change, so I wouldn't like to merge this on my own. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have got two minor suggestions, and a larger design question. If @webknjaz does not respond in the near future, I think I'll merge.
for req in project_table.get("dependencies", []) | ||
] | ||
for extra, reqs in ( | ||
pyproject_contents.get("project", {}).get("optional-dependencies", {}).items() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we support Poetry for static metadata parsing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone is interested in that, it can be a follow-up PR. It's been tough enough getting this one in, so I want to just stick with the standards based thing in this one
Co-authored-by: chrysle <[email protected]>
Thank you for the reviews! |
Thanks, I was about to suggest the same! Could you rebase properly? |
1b85599
to
2098b99
Compare
fixed the test and ungoofed the git! |
Great, thank you for the contribution! |
Just as a heads up, since we struggle with a similar thing in uv, I think this will error on Hatch projects that use Hatch's context formatting. Here's an example: https://github.com/astral-sh/uv/blob/ae35a215c67a161e759769b832b99740f4ecad69/scripts/packages/root_editable/pyproject.toml. If I run from
|
Hmm that's a violation of standards. It should probably declare dependencies as |
Yeah, there's a discussion on it here if you'd like to chime in: pypa/hatch#1331 |
Contributor checklist
Maintainer checklist
backwards incompatible
,feature
,enhancement
,deprecation
,bug
,dependency
,docs
orskip-changelog
as they determine changelog listing.