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

cmd/list: support listing formulae installed on request or automatically #17125

Merged
merged 12 commits into from Apr 23, 2024

Conversation

ZhongRuoyu
Copy link
Member

@ZhongRuoyu ZhongRuoyu commented Apr 22, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Sample usage:

$ brew ls --installed-on-request
gcc
llvm
[...]
$ brew ls --installed-as-dependency
grpc
protobuf
[...]
$ brew ls --installed-on-request --installed-as-dependency
gcc: installed on request
grpc: installed as dependency
llvm: installed on request
protobuf: installed as dependency
[...]

Resolves #17117.

Sample usage:

    $ brew ls --manual
    gcc
    llvm
    [...]
    $ brew ls --auto
    grpc
    protobuf
    [...]
    $ brew ls --manual --auto
    gcc: manual
    grpc: auto
    llvm: manual
    protobuf: auto
    [...]

Resolves #17117.
@ZhongRuoyu ZhongRuoyu added the features New features label Apr 22, 2024
@ZhongRuoyu
Copy link
Member Author

On a related note, this logic is extracted from a local command brew mark that I wrote some time ago but haven't had a chance to consider contributing yet. It marks a formula as installed on request or automatically, and is analogous to apt-mark, dnf mark, port {,un}setrequested, etc.

The reason I wrote it is mainly because brew upgrade and brew reinstall can change a formula's status from automatically installed to installed on request, which is not always desired. Sometimes I do brew reinstall to work around the tab bug (#16032) so that I can safely use brew autoremove to prune the dependencies that are actually not needed anymore. But as an unintended consequence (to me), the formula itself becomes installed on request, so it can no longer be autoremoved later. brew mark --auto <formula> became a solution for me.

After a quick search I do see previous request for such functionality (e.g., #10754), but that was not implemented in the end. I'd like to raise this to see if there is still interest in this; if so, I can prepare a PR for that.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @ZhongRuoyu! Happy to be self-merged once the naming is updated (or we can discuss more)

Library/Homebrew/cmd/list.rb Outdated Show resolved Hide resolved
@@ -18,4 +34,25 @@
.and not_to_output.to_stderr
.and be_a_success
end

it "lists the formulae installed on request or automatically",
:integration_test do
Copy link
Member

Choose a reason for hiding this comment

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

Don't think it's worth adding another (slow, sadly) integration test for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tangential: Now that each command is a separate class, do you think it'd be possible to create integration-like tests that don't require spinning up a new Ruby process? It might have been possible before but now it seems like a more viable option. Most of the slowness has to do with shelling out to a new Ruby process, right?

CC: @dduugg

Copy link
Member

Choose a reason for hiding this comment

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

@apainintheneck Yeh, I think this would be nice.

We still want to make sure we have some proper/slow integration coverage because it catches when the issues are in bin/brew or bin/brew.rb but that could be a smaller subset of critical commands e.g. brew install/brew upgrade/etc.

@MikeMcQuaid
Copy link
Member

I'd like to raise this to see if there is still interest in this; if so, I can prepare a PR for that.

Yeh, seems like a good idea. Not sure brew mark is the best name but I think having functionality to set/unset "installed on request" state would be desirable.

Library/Homebrew/cmd/list.rb Outdated Show resolved Hide resolved
@@ -18,4 +34,25 @@
.and not_to_output.to_stderr
.and be_a_success
end

it "lists the formulae installed on request or automatically",
:integration_test do
Copy link
Contributor

Choose a reason for hiding this comment

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

Tangential: Now that each command is a separate class, do you think it'd be possible to create integration-like tests that don't require spinning up a new Ruby process? It might have been possible before but now it seems like a more viable option. Most of the slowness has to do with shelling out to a new Ruby process, right?

CC: @dduugg

Comment on lines 14 to 18
tab = Tab.new(
"installed_on_request" => installed_on_request,
"tabfile" => keg_dir/Tab::FILENAME,
)
tab.write
Copy link
Contributor

Choose a reason for hiding this comment

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

Tangential: This is starting to crop up in the test code a bit more and I'm wondering if it'd be better to just add an option to setup_test_formula that facilitates that like with_tab: { "installed_on_request" => true }.

CC: @reitermarkus because we've talked about this a bit before

Copy link
Member

Choose a reason for hiding this comment

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

@apainintheneck good idea 👍🏻

@ZhongRuoyu ZhongRuoyu force-pushed the brew-list-manual-auto branch 2 times, most recently from 3735761 to 3e57a49 Compare April 23, 2024 07:53
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Thanks again @ZhongRuoyu!

@MikeMcQuaid MikeMcQuaid merged commit 966454c into master Apr 23, 2024
26 checks passed
@MikeMcQuaid MikeMcQuaid deleted the brew-list-manual-auto branch April 23, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
features New features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

simple command to list all user installed items (not installed only as dependency)
6 participants