-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional Python dependencies are being over connected. When building Python dep-graphs the current algorithm does not consider whether a transitive should be traversed based on 'extra' definitions. When a Python dependency uses extras, this means that dependency is optional and will only be installed when the installer asks. For example if 'my-package' has the following METADATA snippet: ``` Requires-Dist: logger>=1.0 Provides-Extra: test Requires-Dist: tester>=0.5.0; extra == 'test' ``` This means 'logger' is always installed, but 'tester' is only installed if 'my-package' is installed with extra 'test' dependencies, like so: ``` my-package[test]==1.2.3 ``` The current algorithm sometimes gets away with this lack of accuracy because the dependency is skipped if the METADATA file doesn't even exist. However in many cases what's optional in one transitive line is not in another and this can mean the METADATA file does exists. This results in the current algorithm accidentally associating potentially large sub-graphs to transitive lines that should be terminated when extras are not being used. The first change here introduces code that firstly parses out these extra definitions in both requirements.txt and METADATA files. Then also parsers that pick out the Provides-Extra and Requires-Dist extra environment markers. The second change adapts the pip dep-graph builder to take into account extra properties to decide whether a dependency should be traversed or not.
- Loading branch information
Showing
47 changed files
with
9,277 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// https://packaging.python.org/en/latest/specifications/core-metadata/#provides-extra-multiple-use | ||
const PROVIDES_EXTRA = "Provides-Extra:"; | ||
|
||
// given the lines of a METADATA file, find all 'Provides-Extra' names | ||
export function findProvidesExtras(lines: string[]): string[] { | ||
const extras = new Set<string>(); | ||
for (const line of lines) { | ||
const l = line.trim(); | ||
if (l.startsWith(PROVIDES_EXTRA)) { | ||
const extra = l.substring(PROVIDES_EXTRA.length).trim(); | ||
extras.add(extra); | ||
} | ||
} | ||
return Array.from(extras); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.