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

Support pip-style VCS requirements. #15097

Merged
merged 5 commits into from Apr 11, 2022

Conversation

benjyw
Copy link
Sponsor Contributor

@benjyw benjyw commented Apr 11, 2022

[ci skip-rust]

[ci skip-build-wheels]

[ci skip-rust]

[ci skip-build-wheels]
return cls(pkg_resources.Requirement.parse(line))
except Exception as e:
scheme, netloc, path, query, fragment = urllib.parse.urlsplit(line)
if scheme and fragment.startswith("egg="):
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

Hmm, what do we do with those other fragments in the converted URL? I suppose we can leave them all in and assume they will be used if needed and ignored if not needed.

Experiments show that this works (e.g., leaving the fragment #egg=Django in Django @ git+https://github.com/django/django.git@stable/2.1.x#egg=Django works, and also the subdirectory gets used correctly in sdev_logging_utils @ git+https://github.com/SerialDev/sdev_py_utils.git@bd4d36a0#egg=sdev_logging_utils&subdirectory=sdev_logging_utils)

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

BTW, re the comment here re "This is a trick you cannot do with a direct reference VCS URL". Does "this" refer to specifying a subdirectory?

Because that does seem to work with a direct reference VCS URL, in practice anyway. E.g., sdev_logging_utils @ git+https://github.com/SerialDev/sdev_py_utils.git@bd4d36a0#egg=sdev_logging_utils&subdirectory=sdev_logging_utils works (And omitting the subdirectory does not work)

Copy link
Member

Choose a reason for hiding this comment

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

Aha. Gotcha. It works because Pip is in the pipeline and the PEP-440 is agnostic about URL content. Feed that PEP-440 to Poetry and it will fail (I'd bet).

src/python/pants/backend/python/pip_requirement.py Outdated Show resolved Hide resolved
src/python/pants/backend/python/pip_requirement.py Outdated Show resolved Hide resolved
[ci skip-rust]

[ci skip-build-wheels]
@benjyw benjyw requested a review from jsirois April 11, 2022 15:04
pep_440_req_str = f"{project}@ {full_url}"
try:
ret = cls(pkg_resources.Requirement.parse(pep_440_req_str))
logger.warning(
Copy link
Member

Choose a reason for hiding this comment

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

This is unfortunate. I asked seperately, but why are we getting in the way here still - if even just in a naggy way with a warning? My only guess is we ~need the project name parsed out for dep inference.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

I think that is exactly it. I can remove the warning though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I don't think that this warning is good. I'm excited about being able to remove the section in the docs explaining how you must use pep 440.

Copy link
Member

Choose a reason for hiding this comment

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

Oh - you definitely can't remove that because of this change. As pointed out in the comments there are plenty of valid Pip requirements this does not handle. Like . (Pex uses this to package itself) and more. We're still getting in the way here and should just be more lax and try to get a project name and if we can't, move on.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

We also need some string to use as the target name, but we can synthesize one

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Very cool!!

pep_440_req_str = f"{project}@ {full_url}"
try:
ret = cls(pkg_resources.Requirement.parse(pep_440_req_str))
logger.warning(
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I don't think that this warning is good. I'm excited about being able to remove the section in the docs explaining how you must use pep 440.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
[ci skip-rust]

[ci skip-build-wheels]
@benjyw
Copy link
Sponsor Contributor Author

benjyw commented Apr 11, 2022

I'd like to merge this without tackling the handful of remaining cases just yet (e.g., an omitted egg= fragment). This is already a huge improvement on the status quo, and finessing those last few cases will require a little more thought.

[ci skip-rust]

[ci skip-build-wheels]
@benjyw benjyw merged commit aecb211 into pantsbuild:main Apr 11, 2022
@benjyw benjyw deleted the parse_pip_vcs_requirements branch April 11, 2022 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants