Skip to content

Commit

Permalink
env: validate PEP 508 specifiers before passing them as arguments to pip
Browse files Browse the repository at this point in the history
Per the specification for pyproject.toml build-system.requires, these
MUST be valid PEP 508 strings, and when checking to see if they are
satisfied during --no-isolation builds, they will be parsed using
`packaging.requirements` which checks this for free as a side effect of
converting each string into a good format for checking against
importlib.metadata dists.

But when building by default, they are just pip installed and pip
supports many things that aren't just PEP 508 strings. Fix this by
first parsing them with `packaging.requirements` just to get the error
message.
  • Loading branch information
eli-schwartz committed Aug 24, 2023
1 parent a167ba4 commit e73f5ca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/build/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ def install(self, requirements: Collection[str]) -> None:
Install packages from PEP 508 requirements in the isolated build environment.
:param requirements: PEP 508 requirement specification to install
:note: Passing non-PEP 508 strings will result in undefined behavior, you *should not* rely on it. It is
merely an implementation detail, it may change any time without warning.
"""
if not requirements:
return

import packaging.requirements

for r in requirements:
# raise exception for invalid requirements
packaging.requirements.Requirement(r)

self.log(f'Installing packages in isolated environment... ({", ".join(sorted(requirements))})')

# pip does not honour environment markers in command line arguments
Expand Down

0 comments on commit e73f5ca

Please sign in to comment.