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

add --why option to poetry show #5444

Merged
merged 6 commits into from
May 10, 2022
Merged

Conversation

tgolsson
Copy link
Contributor

@tgolsson tgolsson commented Apr 12, 2022

Pull Request Check List

Resolves: #5396

  • Added tests for changed code.
  • Updated documentation for changed code. (none found for poetry show)

This adds a --why option which when combined with --tree and a single package starts the tree at the parent level to show why a specific dependency is included. Optimally this'd walk the tree to the root; but that requires a graph-like structure to easily do/filter, and feels out of scope for this PR.

Example output

Without --why:

$ poetry show requests --tree
requests 2.27.1 Python HTTP for Humans.
├── certifi >=2017.4.17
├── charset-normalizer >=2.0.0,<2.1.0
├── idna >=2.5,<4
└── urllib3 >=1.21.1,<1.27

With --why:

$ poetry show requests --tree --why
cachecontrol 0.12.10 httplib2 caching for requests
└── requests *
    ├── certifi >=2017.4.17
    ├── charset-normalizer >=2.0.0,<2.1.0
    ├── idna >=2.5,<4
    └── urllib3 >=1.21.1,<1.27
requests-toolbelt 0.9.1 A utility belt for advanced users of python-requests
└── requests >=2.0.1,<3.0.0
    ├── certifi >=2017.4.17
    ├── charset-normalizer >=2.0.0,<2.1.0
    ├── idna >=2.5,<4
    └── urllib3 >=1.21.1,<1.27

On a package with no parent:

$ poetry show --tree cachy --why
Package cachy is a direct dependency.
cachy 0.3.0 Cachy provides a simple yet effective caching library.

Forgetting to specify package:

$ poetry show --tree --why
Error: --why requires specifying a package name.

@abn
Copy link
Member

abn commented Apr 12, 2022

@tgolsson can you also update doc?

In general, I like the idea. I'd use it. Would it be feasible to use --why without --tree as well?

@tgolsson
Copy link
Contributor Author

tgolsson commented Apr 13, 2022

@abn Found the docs in cli.md, is there any other spot? Also added an extra test, and added a column with --why for lists:

$ poetry show --why
attrs              21.4.0    from pytest                                                      Classes Without Boilerplate
cachecontrol       0.12.10                                                                    httplib2 caching for requests
cachy              0.3.0                                                                      Cachy provides a simple yet effective caching library.
certifi            2021.10.8 from requests                                                    Python package for providing Mozilla's CA Bundle.
importlib-metadata 4.11.2    from keyring,pluggy,poetry-core,pre-commit,pytest,tox,virtualenv Read metadata from Python packages
...

It won't accept --why for a single package still since it includes that info by default:

$ poetry show --why requests
Error: --why cannot be used when displaying a single package.

It will as before accept --why for a tree for a specific package:

$ poetry show --why --tree requests
cachecontrol 0.12.10 httplib2 caching for requests
└── requests *
    ├── certifi >=2017.4.17
    ├── charset-normalizer >=2.0.0,<2.1.0
    ├── idna >=2.5,<4
    └── urllib3 >=1.21.1,<1.27
requests-toolbelt 0.9.1 A utility belt for advanced users of python-requests
└── requests >=2.0.1,<3.0.0
    ├── certifi >=2017.4.17
    ├── charset-normalizer >=2.0.0,<2.1.0
    ├── idna >=2.5,<4
    └── urllib3 >=1.21.1,<1.27

But not for the global tree listing, since again it contains all info, and --why would add nothing.

Error: --why requires a package when combined with --tree.

@jacopok
Copy link

jacopok commented Apr 21, 2022

Thanks for this implementation! --why is very idiomatic 👍

@tgolsson tgolsson changed the title add --why option to poetry show --tree pkg add --why option to poetry show Apr 22, 2022
@tgolsson
Copy link
Contributor Author

Gentle poke @abn :-)

@abn
Copy link
Member

abn commented May 9, 2022

@tgolsson consider me poked :)

@tgolsson
Copy link
Contributor Author

tgolsson commented May 9, 2022

@abn Good ;-) are there any other blockers or steps in order to get this merged? I can rebase it tomorrow.

Copy link
Member

@abn abn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment. Otherwise looks good to rebase.

src/poetry/console/commands/show.py Outdated Show resolved Hide resolved
@abn abn merged commit d22c5a7 into python-poetry:master May 10, 2022
@tgolsson tgolsson deleted the ts/add-why-option branch May 10, 2022 09:59
@kasteph kasteph mentioned this pull request May 30, 2022
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make poetry show <package> --tree show who requires <package> as well
3 participants