Expand description
Parses a subset of requirement.txt syntax
https://pip.pypa.io/en/stable/reference/requirements-file-format/
Supported:
- PEP 508 requirements
-r-c--hash(postfix)-e
Unsupported:
<path>. TBD<archive_url>. TBD- Options without a requirement, such as
--find-linksor--index-url
Grammar as implemented:
file = (statement | empty ('#' any*)? '\n')*
empty = whitespace*
statement = constraint_include | requirements_include | editable_requirement | requirement
constraint_include = '-c' ('=' | wrappable_whitespaces) filepath
requirements_include = '-r' ('=' | wrappable_whitespaces) filepath
editable_requirement = '-e' ('=' | wrappable_whitespaces) requirement
# We check whether the line starts with a letter or a number, in that case we assume it's a
# PEP 508 requirement
# https://packaging.python.org/en/latest/specifications/name-normalization/#valid-non-normalized-names
# This does not (yet?) support plain files or urls, we use a letter or a number as first
# character to assume a PEP 508 requirement
requirement = [a-zA-Z0-9] pep508_grammar_tail wrappable_whitespaces hashes
hashes = ('--hash' ('=' | wrappable_whitespaces) [a-zA-Z0-9-_]+ ':' [a-zA-Z0-9-_] wrappable_whitespaces+)*
# This should indicate a single backslash before a newline
wrappable_whitespaces = whitespace ('\\\n' | whitespace)*Structs§
- Requirement
Entry - A Requirement with additional metadata from the
requirements.txt, currently only hashes but in the future also editable and similar information. - Requirements
Txt - Parsed and flattened requirements.txt with requirements and constraints
- Requirements
TxtFile Error - Error parsing requirements.txt, wrapper with filename
Enums§
- Requirements
TxtParser Error - Error parsing requirements.txt, error disambiguation
- Requirements
TxtRequirement - A requirement specifier in a
requirements.txtfile.
Type Aliases§
- Source
Cache - A cache of file contents, keyed by path, to avoid re-reading files from disk.