-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
brew deps: add --include-requirements, plus some fixes #2996
brew deps: add --include-requirements, plus some fixes #2996
Conversation
Thanks for this PR @apjanke! It seems to work as expected in my testing.
It would be good if this were fixed before this goes in. (Also, it would be neat if --tree respected --1.) |
Added I see how to implement cycle detection to avoid the stack overflow. I'll add it. The |
Added circular-dependency detection. This fixes the stack overflow error. Now
and
|
A generic |
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.
Looks good! Some style pedantry (some of which isn't your fault) but: nice work!
Library/Homebrew/cmd/deps.rb
Outdated
@with_optional = ARGV.include?("--include-optional") | ||
@with_build = ARGV.include?("--include-build") | ||
@skip_recommended = ARGV.include?("--skip-recommended") | ||
@annotate = ARGV.include?("--annotate") |
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.
Feels weird to use class variables for some of ARGV
and not others. I'd lean on the side of never using them.
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.
So, I tried writing this to use function parameters for everything, and it got pretty hard to ready. Maybe it should fall back to using ARGV.include?
everywhere? Or a single class instance variable for all the options? My impression is we're trying to move away from scattering global ARGV
references everywhere.
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 it should fall back to using ARGV.include? everywhere?
Yeh, I agree.
My impression is we're trying to move away from scattering global ARGV references everywhere.
I think broadly but at this point it's probably reliant on having a decent Command DSL first.
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.
I've updated it to use direct ARGV
references everywhere, and removed the class instance variables.
Library/Homebrew/cmd/deps.rb
Outdated
if @with_reqs | ||
deps | ||
else | ||
deps.map do |d| |
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.
deps.map do |dep|
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.
Done.
Library/Homebrew/cmd/deps.rb
Outdated
end.compact | ||
end | ||
end | ||
|
||
def dep_display_name(d) |
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.
def dep_display_name(dep)
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.
Done.
Library/Homebrew/cmd/deps.rb
Outdated
prefix_ext = (i == max) ? " " : "│ " | ||
puts prefix + "#{chr} #{dep_display_name(dep)}" | ||
recursive_deps_tree(Formulary.factory(dep.name), prefix + prefix_ext) | ||
display_s = "#{chr} #{dep_display_name(dep)}" |
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.
Can we figure out a better name than chr
here? line
, 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.
how about tree_lines
, to distinguish the graphical lines of the tree structure from a "line" of text?
Library/Homebrew/cmd/deps.rb
Outdated
display_s = "#{chr} #{dep_display_name(dep)}" | ||
is_circular = @dep_stack.include?(dep.name) | ||
display_s = "#{display_s} (CIRCULAR DEPENDENCY)" if is_circular | ||
puts prefix + display_s |
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.
puts "#{prefix}#{display_s}
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.
Done.
Library/Homebrew/cmd/deps.rb
Outdated
display_s = "#{display_s} (CIRCULAR DEPENDENCY)" if is_circular | ||
puts prefix + display_s | ||
if recursive && !is_circular | ||
prefix_ext = (i == max) ? " " : "│ " |
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.
prefix_extension = if i == max
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.
Done.
Addressed most of the style pedantry, except for the use of class instance variables. Not sure what the right fix to do there is; using function parameters makes the code look pretty gross IMHO. I think class instance variables should be okay in the case of commands, since the modules are only loaded one per process, used once, and then the process ends. Deferring to the judgment of other maintainers here though. |
And, thanks! |
Updated the |
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.
Once brew style
passes 👍
Arg! |
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.
Looks good
Merged. Thanks for the feedback! |
I just tried |
brew tests
with your changes locally?Adds a
--include-requirements
option tobrew deps
, to display all requirements, including ones without a default formula. Ones with a default formula are displayed as a requirement, with the default formula noted in parentheses. Per a suggestion by @ilovezfs.Mostly useful in conjunction with
--tree
. This helps hunt down where a deeply-nested requirement is coming from. For example,octave
has an indirect dependency on:x11
, but it has so many dependencies it's hard to tell where they're coming from. Or it lets you determine where the MinimumMacOS requirement formytop
is coming from.Also fixes a bug in
--tree
where the dependencies of a Requirement's default formula were not recursed into.Also fixes a bug where the
--tree
mode ignored the--include-optional
,--include-build
, and--skip-recommended
filters, instead always displaying build and recommended dependencies, and never optionals.Also adds an
--annotate
option to the--tree
mode, marking up optional, recommended, and build dependencies as such in the display.Also adds an undocumented
--for-each
switch to help debug the--all
/--installed
display mode, which couldn't previously be gotten to for a list of specified formulae.Before:
After:
Removing the colon before the default formula when not doing
--include-requirements
makes the--tree
output more consistent with the non-tree output.Note that if you include all of
--tree --include-optional --include-build --include-requirements
on large formulae (likebrew deps octave --tree --include-optional --include-build --include-requirements
), you can get a stack overflow error. I suspect this is because there's a circular dependency in the formula definitions somewhere. This could be worked around by using a stack to detect circular dependencies inside the code here, but I haven't put it in yet.Test failure
I'm getting this failure when I run
brew tests
locally, but it's also happening for me onmaster
. Don't think it's introduced by this PR.