-
Notifications
You must be signed in to change notification settings - Fork 3k
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
'pip freeze PKG' outputs the installed version of PKG and its dependencies #1946
Closed
benoitbryon
wants to merge
18
commits into
pypa:develop
from
benoitbryon:feature/freeze-subset-recursively
Closed
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
982a891
'pip freeze {NAME}' outputs the installed versions of package {NAME} …
benoitbryon cc94c3a
'pip show {NAME}' also shows the list of recursive dependencies of pa…
benoitbryon 24a2dda
Fixed line count in 'pip show' tests. Renamed 'pip.util.recursive_dep…
benoitbryon d84fb4a
In 'pip show' tests, shifted output lines to insert 'Requires recursi…
benoitbryon ffa2694
Psyko-rebased branch feature/freeze-subset-recursively on top of deve…
benoitbryon 4396efa
pip freeze is not recursive by default. Added --recursive option to m…
benoitbryon 28d098c
Updated examples in documentation around 'pip freeze PKG' and 'Requir…
benoitbryon 4b43c91
Psycho-rebased branch feature/freeze-subset-recursively on top of dev…
benoitbryon f895418
pip.utils.get_recursive_dependencies() takes a list as first argument…
benoitbryon 098ec7e
Improved readability of pip.utils.get_recursive_dependencies().
benoitbryon 5c2efb1
Removed duplicate recursive calls in pip.utils.get_recursive_dependen…
benoitbryon bdd2fda
'pip show' shows *ordered* list of recursive dependencies (was unorde…
benoitbryon 8fb3bbf
pip.utils.get_recursive_dependencies() returns case-sensitive names, …
benoitbryon 98b004f
Psycho-rebased branch feature/freeze-subset-recursively on top of dev…
benoitbryon e27ed4b
Used case-insensitive order for recursive dependencies in 'pip show' …
benoitbryon 9bb013d
In 'pip freeze PKG', compare safe names (was lowercase names).
benoitbryon 8cfb9ad
Typos in 'pip freeze' and 'pip show' documentation.
benoitbryon 186ddf2
Merge remote-tracking branch 'origin/develop' into freeze_recursive_r…
msabramo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,6 +400,23 @@ def get_installed_distributions(local_only=True, | |
] | ||
|
||
|
||
def recursive_dependencies(query): | ||
"""Return list of dependencies of dists in ``query``, recursively.""" | ||
dependencies = set() | ||
installed = dict( | ||
[(p.project_name.lower(), p) for p in pkg_resources.working_set]) | ||
query_names = [name.lower() for name in query] | ||
for pkg in query_names: | ||
try: | ||
dist = installed[pkg] | ||
for dep in dist.requires(): | ||
dependencies.add(dep.project_name) | ||
dependencies.update(recursive_dependencies([dep.project_name])) | ||
except KeyError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This except could be moved at line 412 to not catch exception from anywhere else. |
||
pass # pkg is not installed. | ||
return dependencies | ||
|
||
|
||
def egg_link_path(dist): | ||
""" | ||
Return the path for the .egg-link file if it exists, otherwise, None. | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than just lowercasing the name, you might want to use the canonical form of the name (
-
and_
should be treated as the same, IIRC). I think you should be using thesafe_name
function from setuptools, but pip should probably implement its own "canonical name" function inutils
or somewhere. @dstufft?For now, just a
.replace('_', '-')
is probably good enough though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That
safe_name
function that pip might want to provide may be better placed in pypa/packaging since pypa/twine would make good use of it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately I agree. But I don't want to leave these things waiting for ages (practicality beats purity) so I'd suggest
.replace()
for now, then when someone gets to it we put a function inutil
, and then, when we get to the point where we vendor inpackaging
we can switch to using the function from there at that point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Sorry. It can be in both places and then removed from pip as soon as packaging becomes a dependency. (That was in my head but not in my writing. ;))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found and used pkg_resources.safe_extra()