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

docs: mention that python requirements need to be specified using full address from the root #21293

Conversation

AlexTereshenkov
Copy link
Member

@AlexTereshenkov AlexTereshenkov commented Aug 12, 2024

It may be not so obvious that referring to the Python requirements using their "regular" path produced by the list goal will not be compatible with the format expected in the [tool].requirements field, see https://www.pantsbuild.org/2.21/reference/subsystems/ruff#requirements:

$ pants list 3rdparty/python | grep "flake8"
3rdparty/python:flake8#flake8
...

The target should be referred to as requirements = ["//3rdparty/python:flake8"]. If it's not (e.g. using 3rdparty/python:flake8), then an error is raised:

$ pants lint ::
...
ValueError: Invalid requirement '3rdparty/python:flake8': Parse error at "'/python'": Expected string_end

@AlexTereshenkov AlexTereshenkov added category:documentation release-notes:not-required PR doesn't require mention in release notes labels Aug 12, 2024
@AlexTereshenkov AlexTereshenkov self-assigned this Aug 12, 2024
@AlexTereshenkov AlexTereshenkov marked this pull request as ready for review August 12, 2024 18:05
@AlexTereshenkov AlexTereshenkov requested review from kaos and huonw August 12, 2024 18:06
@huonw huonw requested a review from benjyw August 12, 2024 23:32
Copy link
Contributor

@huonw huonw left a comment

Choose a reason for hiding this comment

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

Thanks for the patch. Seems reasonable to document the current behaviour... but, why do we have this behaviour? Can we allow path/to:requirement to work too, not just //path/to:requirement?

@AlexTereshenkov AlexTereshenkov force-pushed the docs/python-tool-base-requirements-field branch from cff12ff to 7ac339a Compare August 13, 2024 06:54
@AlexTereshenkov
Copy link
Member Author

Thanks for the patch. Seems reasonable to document the current behaviour... but, why do we have this behaviour? Can we allow path/to:requirement to work too, not just //path/to:requirement?

I've extended the help to clarify why this is necessary. The reqs might be in the form of VCS requirements that resembles the addresses (with colons in between), see https://pip.pypa.io/en/stable/topics/vcs-support/. So the // prefix is to help to differentiate between those.

async def get_req_strings(pex_reqs: PexRequirements) -> PexRequirementsInfo:
addrs: list[Address] = []
specs: list[str] = []
req_strings: list[str] = []
find_links: set[str] = set()
for req_str_or_addr in pex_reqs.req_strings_or_addrs:
if isinstance(req_str_or_addr, Address):
addrs.append(req_str_or_addr)
else:
assert isinstance(req_str_or_addr, str)
# Require a `//` prefix, to distinguish address specs from
# local or VCS requirements.
if req_str_or_addr.startswith(os.path.sep * 2):
specs.append(req_str_or_addr)
else:
req_strings.append(req_str_or_addr)

@AlexTereshenkov AlexTereshenkov force-pushed the docs/python-tool-base-requirements-field branch from 7ac339a to b09e482 Compare August 13, 2024 06:58
@AlexTereshenkov AlexTereshenkov force-pushed the docs/python-tool-base-requirements-field branch from b09e482 to d2c0d36 Compare August 13, 2024 06:59
@AlexTereshenkov AlexTereshenkov merged commit feedb0f into pantsbuild:main Aug 13, 2024
25 checks passed
@AlexTereshenkov AlexTereshenkov deleted the docs/python-tool-base-requirements-field branch August 13, 2024 08:02
@huonw
Copy link
Contributor

huonw commented Aug 13, 2024

Ah, cool, nice find and good thinking to explain the background in the docs 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:documentation release-notes:not-required PR doesn't require mention in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants