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/deps: add args to filter output #17129
base: master
Are you sure you want to change the base?
Conversation
* `--direct-build` to only show direct build dependencies, which gives information on what formulae are needed when `--build-from-source`. * `--direct-test` to only show direct test dependencies when outputting in `--tree` or `--graph` format * `--skip` to prune parts of dependency tree * `--level` to limit recursion depth. For now, only added to `--tree` as the support there is simple and idea for arg is similar to what the `tree` & `eza` formula provide. Signed-off-by: Michael Cho <[email protected]>
I'm against adding more specific options to The
|
❯ brew deps --direct --include-build --tree ruby --annotate
ruby
├── autoconf [build]
├── pkg-config [build]
├── rust [build]
├── libyaml
└── openssl@3 This is not the full set of formulae installed when you run ❯ brew deps --include-build --tree ruby --annotate --direct-build
ruby
├── autoconf [build]
│ └── m4
├── pkg-config [build]
├── rust [build]
│ ├── libgit2
│ │ ├── libssh2
│ │ │ └── openssl@3
│ │ │ └── ca-certificates
│ │ └── openssl@3
│ │ └── ca-certificates
│ ├── libssh2
│ │ └── openssl@3
│ │ └── ca-certificates
│ ├── llvm@17
│ │ └── zstd
│ │ ├── lz4
│ │ └── xz
│ ├── openssl@3
│ │ └── ca-certificates
│ └── pkg-config
├── libyaml
└── openssl@3
└── ca-certificates The usage of this is analyzing problems that occur when particular formulae are installed in build environment, which often happens in Homebrew/core. In most cases, I've fallen back to grepping and scripting as this doesn't seem possible in current
I don't mind either way. I went with option I was used to using for directory tree printing, e.g. ❯ tree --help | rg ' -L'
-L level Descend only level directories deep.
❯ eza --help | rg ' -L'
-L, --level DEPTH limit the depth of recursion |
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.
If you, @cho-m, personally need all of these flags doing the Homebrew CI analysis you've mentioned: I'm 👍🏻 to adding it.
If you don't need any of these: let's hold off adding them.
Code-wise: I'm 👍🏻 bar the one suggestion I've made, this can be merged with no re-review after that.
@@ -88,6 +102,9 @@ class Deps < AbstractCommand | |||
def run | |||
raise UsageError, "`brew deps --os=all` is not supported" if args.os == "all" | |||
raise UsageError, "`brew deps --arch=all` is not supported" if args.arch == "all" | |||
if (level = args.level) && !level.match?(/^[1-9][0-9]*$/) |
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.
if (level = args.level) && !level.match?(/^[1-9][0-9]*$/) | |
if (level = args.level) && level.to_i > 0 |
maybe with exception rescue
required
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.
Doing some basic testing: it doesn't look like a rescue
is required as invalid input will just end up being 0
from to_i
.
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.
Using String#to_i
is slightly more permissive of garbage input but probably fine for this use case.
irb(main):001:0> "skdfjsdklj100".to_i
=> 0
irb(main):002:0> "100alskdfsdkjfs".to_i
=> 100
In that case, maybe |
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.
Another option would be to have --direct
take a list of dependencies types. That would allow you to run brew deps --include-build --direct=build NAME
to get the build from source dependencies.
@@ -88,6 +102,9 @@ class Deps < AbstractCommand | |||
def run | |||
raise UsageError, "`brew deps --os=all` is not supported" if args.os == "all" | |||
raise UsageError, "`brew deps --arch=all` is not supported" if args.arch == "all" | |||
if (level = args.level) && !level.match?(/^[1-9][0-9]*$/) |
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.
Using String#to_i
is slightly more permissive of garbage input but probably fine for this use case.
irb(main):001:0> "skdfjsdklj100".to_i
=> 0
irb(main):002:0> "100alskdfsdkjfs".to_i
=> 100
switch "--include-test", | ||
description: "Include `:test` dependencies for <formula> (non-recursive)." | ||
description: "Include `:test` dependencies for <formula> (non-recursive for flat output)." | ||
switch "--direct-test", | ||
depends_on: "--include-test", | ||
description: "Only include `:test` dependencies that are direct dependencies declared " \ | ||
"in the formula when showing non-flat output like `--tree` or `--graph`." |
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.
Maybe we'd be better off just making the --direct-test
behavior the default for the --include-test
option instead. It's always been a bit weird that the output is different depending on whether you're using the tree, graph or flat output.
Yeh, I really like this idea, nice one @apainintheneck 💡 |
--direct-build
to only show direct build dependencies, which gives information on what formulae are needed when--build-from-source
.--direct-test
to only show direct test dependencies when outputting in--tree
or--graph
format--skip
to prune parts of dependency tree--level
to limit recursion depth. For now, only added to--tree
as the support there is simple and idea for arg is similar to what thetree
&eza
formula provide.brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Example: