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

poetry show <package> now also shows which packages depend on it #2351

Merged
merged 6 commits into from
Sep 19, 2021

Conversation

snejus
Copy link
Contributor

@snejus snejus commented Apr 26, 2020

Pull Request Check List

Partly resolves: #1906

  • Added tests for changed code.
  • Updated documentation for changed code.

#1906 Requested an ability to know why packages are required. Even though the suggestion outlined a reverse-tree based approach, I believe that this can also be solved using a more simple approach: by providing the required by information in the poetry show <package> output - done with just 15 lines of code.

I had this patch applied locally since a couple of weeks ago and I found it extremely useful - there's no need to do poetry show --tree | ag <package> -C 20 anymore just to find out where some 3rd party dependencies come from.

Summary of what's been done:

  • 15 lines of business logic in commands/show.py
  • A test for poetry show <package> command - realised a test for this command didn't exist, so it tests both the default output and my changes
  • Documentation update and a little typo fix, where dependencies isn't supposed to have a colon at the end.

Please see the screenshot below for a little teaser:
image

@snejus
Copy link
Contributor Author

snejus commented Apr 26, 2020

image

Can include this as an extra if anyone's keen ;)

@snejus snejus mentioned this pull request Apr 26, 2020
2 tasks
@seansfkelley
Copy link

Looks neat! Does this traverse the ancestry all the way to the root pyproject.toml, or just one level up from the specified package?

@snejus
Copy link
Contributor Author

snejus commented Apr 26, 2020

@seansfkelley - it's the latter, it only specifies direct dependencies.

I guess the reverse-tree approach would be more suitable for the traversal, which personally I find a bit too noisy, at least for the workflow I'm used to (maybe I just haven't tried a good solution though) - there's actually a PR open that aims to do it: #2086, though it has been stale for a while, so it'd be great if people could have a look at it since it looks quite promising.

The required by in poetry show removes the noise and simply tells the dev hey, that's the list of libraries that use it and they specify these constraints - and yeah, now you see which one of those constraints restricts you from bringing that new feature in. I find it very useful whenever I need to integrate a minor/major bump coming from 3rd party dependency - I see whether it's supported or blocked in a simple way. I found that I'm usually aware of my project dependencies enough to kind of know where they're coming from considering higher levels - it's the versions that cause pain :) There's always an extra pip show <parent-package> command available otherwise.

The reverse-tree, I guess, has a different use case. One I could think of would be analysing bigger open source projects that devs are new to. poetry install -vvv -> sees a dodgy package -> ah where did this come from? -> runs poetry show --tree --reverse <dodgy-package> (or --why, as in the PR above) -> sees a nice overview of what's going on.

Actually, pipdeptree has implemented it in a way, see a screenshot below for six usage within poetry:
image

And then poetry show six - obviously it's an unfair comparison considering the looks 😅
image

@snejus
Copy link
Contributor Author

snejus commented Apr 26, 2020

image
Forgot to mention - pip implements the show command too - though since good looking or dependency management aren't exactly the keywords usually associated with pip, it's only useful as a backup.

@seansfkelley
Copy link

Great, thank you for the explanation! pipdeptree looks quite handy.

My usual use-case for needing to answer this question is that I've traced an issue through debugging to a particular package, and I want to know which of the dependencies I've declared is bringing it in so I can take (indirect) action to resolve the problem, usually by picking a better version for my dependency or seeing if I can just remove it. All that is to say -- it doesn't come up during version upgrades, so I don't have anything else to narrow down which packages are suspicious.

In any case, this change would already make my life easier, even if it's not exactly what I'm looking for.

@snejus
Copy link
Contributor Author

snejus commented Sep 13, 2020

@sdispater could this by any chance go in, considering that it's very small and has virtually no impact on the rest of the codebase? It's been a couple of months now that me and most of the people around who use Poetry, patching the releases with this - I even have a little bash function that does it. It's extremely useful for bigger projects.

@finswimmer finswimmer added area/cli Related to the command line kind/feature Feature requests/implementations area/ux Features and improvements related to the user experience labels Sep 15, 2020
@finswimmer finswimmer requested a review from a team September 15, 2020 18:13
@K900
Copy link
Contributor

K900 commented Jan 28, 2021

Just another bump/upvote for this. Very interested in this.

@finswimmer
Copy link
Member

Hello @snejus,

I really like this one. Would you find some time to rebase your PR onto master?

fin swimmer

@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2021

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
9.6% 9.6% Duplication

@finswimmer finswimmer changed the base branch from develop to master July 7, 2021 04:31
@finswimmer finswimmer requested review from a team and removed request for a team July 7, 2021 04:32
@snejus
Copy link
Contributor Author

snejus commented Jul 12, 2021

@finswimmer sorry, was a bit in a rush and forgot to switch the base branch. Is there anything else that's required from my side?

@finswimmer
Copy link
Member

I'm very sorry to ping you again @snejus. For some reasons the SonarCloud Code Analysis failed. We removed this check for now. So could you rebase once more?

@snejus
Copy link
Contributor Author

snejus commented Sep 15, 2021

of course! :)

Copy link
Member

@finswimmer finswimmer left a comment

Choose a reason for hiding this comment

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

Great 👍

@finswimmer finswimmer merged commit 3519d2b into python-poetry:master Sep 19, 2021
@spirit-q2
Copy link
Contributor

@snejus, @finswimmer, I wonder, what are the reasons for not putting this feature into 1.1.11?

1nF0rmed pushed a commit to 1nF0rmed/poetry that referenced this pull request Nov 15, 2021
…hon-poetry#2351)

* Add required_by list to pip show <package> command

* Update poetry show pendulum documentation

* Handle package name discrepancies

* Lets not force typing then

* issue-1906 Add the test back after rebase

* issue-1906 Ignore trailing spaces in the tests
edvardm pushed a commit to edvardm/poetry that referenced this pull request Nov 24, 2021
…hon-poetry#2351)

* Add required_by list to pip show <package> command

* Update poetry show pendulum documentation

* Handle package name discrepancies

* Lets not force typing then

* issue-1906 Add the test back after rebase

* issue-1906 Ignore trailing spaces in the tests
@snejus snejus deleted the fix-issue-1906 branch November 27, 2021 02:34
@finswimmer finswimmer mentioned this pull request Mar 6, 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
area/cli Related to the command line area/ux Features and improvements related to the user experience kind/feature Feature requests/implementations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display why package was installed
5 participants