Skip to content
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

Conversation

benoitbryon
Copy link

@benoitbryon benoitbryon commented Jul 23, 2014

This pull-request is a proposal around "recursive dependencies listing":

  • pip freeze PKG outputs only version of PKG (a subset of pip freeze)
  • pip freeze --recursive PKG outputs versions of PKG and its (recursive) dependencies
  • pip show PKG also outputs "Require recursive: " which contains PKG's recursive dependencies (not PKG itself)

My motivation (i.e. my use case) is to get a known good set of versions for a project.
As a developer, in order to get the known good set of versions of a project,
Given a Python environment (typically a virtualenv) where my project is installed,
Given I made sure project works in this environment (i.e. validated the "known good" set of versions)
Given the environment contains other projects and developer tools (such as bpython, pytest, tox, ...)
I want to get the versions of PKG and its dependencies only, i.e. ignore everything in the environment not required by my project.

An example... Let's install bpython, Sphinx and Fabric:

$ pip install bpython Sphinx Fabric

pip freeze works as always:

$ pip freeze
bpython==0.13.1
docutils==0.12
ecdsa==0.11
Fabric==1.9.0
Jinja2==2.7.3
MarkupSafe==0.23
paramiko==1.14.0
pycrypto==2.6.1
Pygments==1.6
Sphinx==1.2.2

pip freeze bpython shows only versions of bpython:

$ pip freeze bpython
bpython==0.13.1

pip freeze --recursive bpython and its recursive dependencies, a.k.a. versions of everything related to bpython in the current Python environment:

$ pip freeze --recursive bpython
bpython==0.13.1
Pygments==1.6

Same idea for pip freeze Sphinx and pip freeze --recursive Sphinx:

$ pip freeze Sphinx
Sphinx==1.2.2

$ pip freeze --recursive Sphinx
docutils==0.12
Jinja2==2.7.3
MarkupSafe==0.23
Pygments==1.6
Sphinx==1.2.2

pip freeze bpython Sphinx displays frozen versions for both bpython and Sphinx:

$ pip freeze bpython Sphinx
bpython==0.13.1
Sphinx==1.2.2

$ pip freeze --recursive bpython Sphinx
bpython==0.13.1
docutils==0.12
Jinja2==2.7.3
MarkupSafe==0.23
Pygments==1.6
Sphinx==1.2.2

pip show bpython Sphinx has additional "Requires recursive: " items:

$ pip show bpython Sphinx

---
Name: bpython
Version: 0.13.1
Location: /mnt/data/web/django-generic-filters/env/pip/lib/python2.7/site-packages
Requires: pygments
Requires recursive: pygments

---
Name: Sphinx
Version: 1.2.2
Location: /mnt/data/web/django-generic-filters/env/pip/lib/python2.7/site-packages
Requires: Jinja2, Pygments, docutils
Requires recursive: markupsafe, Pygments, Jinja2, docutils

@benoitbryon
Copy link
Author

I created this pull request as a proof-of-concept. I didn't took too much care of the tests or the code style. Because I guess the feature/usage has to be discussed/accepted first. And then obviously I would do my best to make this pull-request mergeable.

for dep in dist.requires():
dependencies.add(dep.project_name)
dependencies.update(recursive_dependencies([dep.project_name]))
except KeyError:
Copy link
Author

Choose a reason for hiding this comment

The 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.

…endencies()' to 'pip.util.get_recursive_dependencies()'. This function now takes a list of positional arguments (was a list as first positional argument).
@benoitbryon
Copy link
Author

The Travis build looks nearly good, except some timeout error: https://travis-ci.org/pypa/pip/builds/30765608
I guess this timeout error is not related to this pull-request, but I do not have the permissions to restart the failed py27 build... unless I add some commits :(

@Ivoz
Copy link
Contributor

Ivoz commented Jul 25, 2014

Restarted

@benoitbryon
Copy link
Author

Restarted

Thanks @Ivoz :)

The latest py27 build failed with errors (including some timeout errors). Still, I think errors are not related to the changes I introduced... or I cannot figure out how they are related. Any idea?

@benoitbryon
Copy link
Author

\o/ the build passed! Looks like this pull-request does not break current features.
That said, what do you think about the feature proposal?

If it is accepted, I guess the docs (and perhaps more tests) have to be updated too! I am okay to do it, but I'd like some feedback about the concept before I put more efforts in the docs.

@benoitbryon
Copy link
Author

Any comments about this feature? Should I ask the question on another channel?

@thedrow
Copy link

thedrow commented Aug 26, 2014

Look pretty good. It should probably include more tests though.

@benoitbryon
Copy link
Author

It should probably include more tests though

@thedrow: do you have examples about these tests? What should they check?

@xavfernandez
Copy link
Member

#1308 is similar but simpler.

Maybe an option --with-dependencies could reconciliate the two propositions...

The addition of "Requires recursive" to pip show is a nice idea though.

@xavfernandez
Copy link
Member

#858 is an other one

@benoitbryon
Copy link
Author

@thedrow: Added functional tests in tests/functional/test_freeze.py

@xavfernandez: I changed the feature to look like #1308:

  • pip freeze shows all installed packages
  • pip freeze PKG shows only PKG
  • pip freeze --recursive PKG shows PKG and its (recursive) dependencies
  • I performed a simple case insensitive match: pip freeze SamPLE shows sample but not anothersample. I think the match rules (seen in Freeze with args #1308 and in arguments to freeze are used to filter installed packages #858) can be added later, as another pull request.
  • I did not merge Freeze with args #1308 because it is a very old pull request and I was unable to update it easily and resolve conflicts

@benoitbryon
Copy link
Author

:( I updated the pull-request on top of recent "develop" branch... perhaps it was not a good idea.
I mean, I do not understand why the tests fail. There is some error in functional/test_install.py, which should not be changed by this pull-request. See https://travis-ci.org/pypa/pip/jobs/39079327#L234

@benoitbryon
Copy link
Author

@megies: does this pull-request match yours?

@benoitbryon
Copy link
Author

Note: just discovered pipdeptree by @naiquevin.

@megies
Copy link

megies commented Oct 27, 2014

@megies: does this pull-request match yours?

Mine can just be dropped, this looks way more advanced.. ;)

@benoitbryon
Copy link
Author

Note: updated top-level description of ticket, to reflect pull-request's latest changes.

@benoitbryon
Copy link
Author

I do not understand the build error :(
Any idea there?

On my computer, I have other errors, including errors related to pypa/pip-test-package... I do not know why the results are not the same as told by Travis. That said, I do not understand the relationship with this PR.

@benoitbryon
Copy link
Author

Just updated the branch on top of "develop" and the tests are ok!
Is there something else I can do for this pull-request to be merged?

@msabramo
Copy link
Contributor

msabramo commented Dec 4, 2014

I would want to compare this to pipdeptree (https://pypi.python.org/pypi/pipdeptree), which I've used in the past.

This PR shows a flat view. pipdeptree shows a tree. But this PR has some interesting ways of invoking it. Maybe combine the two?

@benoitbryon
Copy link
Author

Yes! ready for another round of review :)

@msabramo
Copy link
Contributor

This has merge conflicts because my PR #2173 was merged. I can take a stab at fixing it.

msabramo added a commit to msabramo/pip that referenced this pull request Jan 16, 2015
…edux

Conflicts:
	pip/commands/freeze.py
	pip/commands/show.py
	tests/functional/test_show.py
@benoitbryon
Copy link
Author

Thanks @msabramo for the update!

@msabramo
Copy link
Contributor

I like this. @dstufft, @pfmoore ?

@pfmoore
Copy link
Member

pfmoore commented Jan 22, 2015

Seems reasonable. I'm happy for it to be merged. Any objections @dstufft @carljm @jezdez ?

@msabramo
Copy link
Contributor

msabramo commented Feb 7, 2015

This one needs another look from a code contributor

@msabramo
Copy link
Contributor

Any objections?

@msabramo
Copy link
Contributor

I think the silence means that @pfmoore should merge this. 😄

@pfmoore
Copy link
Member

pfmoore commented Mar 2, 2015

As it's a behaviour change, I'd like to see a bit more than silence from the other devs... :-) Also, my comment above was meant to imply that I have no objections to someone doing the work to merge it (i.e., review the code, check the corner cases, ensure test coverage is OK, etc) not that I have done that work myself. I'll try to get some time to look at this a bit more deeply, but I don't have a need for it myself (I don't use pip freeze at all) so it may be a while before I get the chance.

@msabramo
Copy link
Contributor

msabramo commented Mar 5, 2015

Hmmm. Well I'd feel bad about making you take time to review something that you have no vested interest in. Maybe someone else is more interested in this feature?

@msabramo
Copy link
Contributor

Maybe a core contributor (other than @pfmoore who already looked a bit) look at what's proposed, if not the code? If the idea is not sound, then it can be closed and if it is, it can hopefully get reviewed and merged before it becomes outdated.

@dstufft dstufft closed this May 18, 2016
@dstufft
Copy link
Member

dstufft commented May 18, 2016

Accidentally closed this, reopening. Sorry!

@dstufft dstufft reopened this May 18, 2016
@BrownTruck
Copy link
Contributor

Hello!

As part of an effort to ease the contribution process and adopt a more standard workflow pip has switched to doing development on the master branch. However, this Pull Request was made against the develop branch so it will need to be resubmitted against master. Unfortunately, this pull request does not cleanly merge against the current master branch.

If you do nothing, this Pull Request will be automatically closed by @BrownTruck since it cannot be merged.

If this pull request is still valid, please rebase it against master (or merge master into it) and resubmit it against the master branch, closing and referencing the original Pull Request.

If you choose to rebase/merge and resubmit this Pull Request, here is an example message that you can copy and paste:

This pull-request is a proposal around "recursive dependencies listing":



pip freeze PKG outputs only version of PKG (a subset of pip freeze)

pip freeze --recursive PKG outputs versions of PKG and its (recursive) dependencies

pip show PKG also outputs "Require recursive: " which contains PKG's recursive dependencies (not PKG itself)


My motivation (i.e. my use case) is to get a known good set of versions for a project.
As a developer, in order to get the known good set of versions of a project,
Given a Python environment (typically a virtualenv) where my project is installed,
Given I made sure project works in this environment (i.e. validated the "known good" set of versions)
Given the environment contains other projects and developer tools (such as bpython, pytest, tox, ...)
I want to get the versions of PKG and its dependencies only, i.e. ignore everything in the environment not required by my project.

An example... Let's install bpython, Sphinx and Fabric:

$ pip install bpython Sphinx Fabric

pip freeze works as always:

$ pip freeze
bpython==0.13.1
docutils==0.12
ecdsa==0.11
Fabric==1.9.0
Jinja2==2.7.3
MarkupSafe==0.23
paramiko==1.14.0
pycrypto==2.6.1
Pygments==1.6
Sphinx==1.2.2

pip freeze bpython shows only versions of bpython:

$ pip freeze bpython
bpython==0.13.1

pip freeze --recursive bpython and its recursive dependencies, a.k.a. versions of everything related to bpython in the current Python environment:

$ pip freeze --recursive bpython
bpython==0.13.1
Pygments==1.6

Same idea for pip freeze Sphinx and pip freeze --recursive Sphinx:

$ pip freeze Sphinx
Sphinx==1.2.2

$ pip freeze --recursive Sphinx
docutils==0.12
Jinja2==2.7.3
MarkupSafe==0.23
Pygments==1.6
Sphinx==1.2.2


pip freeze bpython Sphinx displays frozen versions for both bpython and Sphinx:

$ pip freeze bpython Sphinx
bpython==0.13.1
Sphinx==1.2.2

$ pip freeze --recursive bpython Sphinx
bpython==0.13.1
docutils==0.12
Jinja2==2.7.3
MarkupSafe==0.23
Pygments==1.6
Sphinx==1.2.2

pip show bpython Sphinx has additional "Requires recursive: " items:

$ pip show bpython Sphinx
---
Name: bpython
Version: 0.13.1
Location: /mnt/data/web/django-generic-filters/env/pip/lib/python2.7/site-packages
Requires: pygments
Requires recursive: pygments
---
Name: Sphinx
Version: 1.2.2
Location: /mnt/data/web/django-generic-filters/env/pip/lib/python2.7/site-packages
Requires: Jinja2, Pygments, docutils
Requires recursive: markupsafe, Pygments, Jinja2, docutils

---

*This was migrated from pypa/pip#1946 to reparent it to the ``master`` branch. Please see original pull request for any previous discussion.*

@BrownTruck BrownTruck added asked to reparent auto-bitrotten PRs that died because they weren't updated labels May 19, 2016
@BrownTruck
Copy link
Contributor

This Pull Request was closed because it cannot be automatically reparented to the master branch and it appears to have bit rotted.

Please feel free to re-open it or re-submit it if it is still valid and you have rebased it onto master or merged master into it.

@msabramo
Copy link
Contributor

msabramo commented Jun 2, 2016

Too bad. This seems useful.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-bitrotten PRs that died because they weren't updated auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants