parseDependencies
Parses the value of a package dependency field (Depends, Requires, depends, …) into a
structure: groups of alternatives, each alternative a name with an optional version constraint.
format says how the text is written, and decides the exact shape of each dependency and the
operator spellings (see DependencyFormats); the options are those of that format only.
'debian' — a relationship field of the Debian Policy Manual, chapter 7.1 (Depends,
Pre-Depends, Recommends, Suggests, Enhances, Breaks, Conflicts, Provides,
Replaces, Build-Depends, …). Commas separate the entries that must all hold (AND), |
separates the alternatives inside an entry (OR). Each alternative is
name[:arch] [(op version)] [[archs]] [<profiles>], in that order, with any whitespace (line
breaks included, as in a multi-line Depends) between the parts. The operators are Debian’s
<<, <=, =, >= and >>, kept as written; the obsolete < and > throw unless
options.compat is set, in which case they are read as <= and >= like dpkg does.
Whitespace-only entries (a trailing comma, a,, b) are skipped, as dpkg does. The
${substvars} of source debian/control files are not supported.
'rpm' — an RPM Requires value: capabilities separated by commas and/or whitespace, each
name [op version] with <, <=, =, >= or >; boolean dependencies (a or b) give the
alternatives of a group.
'arch' — an Arch Linux depends array or .PKGINFO list: entries separated by whitespace
(quotes and surrounding parentheses of a PKGBUILD array are accepted), each name[op version].
'alpine' — an Alpine depends list: entries separated by whitespace, each
[!]name[op version] (! is a conflict).
'pep508' — PEP 508 requirements, one per line (as in requirements.txt or the
dependencies of a pyproject.toml): name[extras] specifiers ; marker, or name @ url.
Every entry that is not valid throws a SyntaxError quoting the offending text. Parsing is
linear in the input.
Available since v3.1.10
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
field | string | The value of a dependency field |
format | Format | How the field is written |
options | ParseDependenciesOptions<Format> | The options of `format`, if it has any |
Returns
Section titled “Returns”DependencyGroup<DependencyOf<Format>>[] — One group of alternatives per entry
Examples
Section titled “Examples”Read a Depends field
Section titled “Read a Depends field”Commas are AND, | is OR inside an entry; each alternative carries its qualifier, version and restrictions.
Read a multi-line field and list the package names
Section titled “Read a multi-line field and list the package names”Line breaks are plain whitespace, and a trailing comma is tolerated.
Reject an invalid field
Section titled “Reject an invalid field”A fragment that is not valid throws a SyntaxError that quotes it.
Read the obsolete < and > of old packages
Section titled “Read the obsolete < and > of old packages”They are refused by default; compat mode reads them as dpkg does, <= and >=.
Read an RPM Requires, with an alternative
Section titled “Read an RPM Requires, with an alternative”Boolean dependencies (a or b) become the alternatives of a group.
Read a PKGBUILD depends array
Section titled “Read a PKGBUILD depends array”Quotes and the surrounding parentheses of the array are accepted.
Read an Alpine depends list, with a conflict
Section titled “Read an Alpine depends list, with a conflict”A leading ! marks a package that must not be installed.
Read Python requirements
Section titled “Read Python requirements”Extras, specifiers and the environment marker are separated; the marker is kept as written.
Related Types
Section titled “Related Types”DependencyFormats
Section titled “DependencyFormats”For each supported format, the shape of one dependency and the options its parser takes. This is what makes parseDependencies and stringifyDependencies type-safe per format.
DependencyGroup
Section titled “DependencyGroup”The alternatives (a | b) that satisfy one entry of a dependency field. A format without
alternatives ('arch', 'alpine', 'pep508') always has a single one.
DependencyOf
Section titled “DependencyOf”The dependency type of a format.
ParseDependenciesOptions
Section titled “ParseDependenciesOptions”The extra arguments of parseDependencies: the options of the format if it has some, none otherwise.
DependencyFormat
Section titled “DependencyFormat”The formats of dependency fields: 'debian', 'rpm', 'arch', 'alpine' and 'pep508'.
