Skip to content

argv: move formulae to cli/args#6433

Merged
MikeMcQuaid merged 3 commits intoHomebrew:masterfrom
GauthamGoli:argv-cleanup-3
Dec 11, 2019
Merged

argv: move formulae to cli/args#6433
MikeMcQuaid merged 3 commits intoHomebrew:masterfrom
GauthamGoli:argv-cleanup-3

Conversation

@GauthamGoli
Copy link
Copy Markdown
Contributor

  • 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 tests with your changes locally?

#5730
Please do not merge until #6411 gets merged.

Comment thread Library/Homebrew/cli/args.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@resolved_formulae ||= (downcased_unique_named - casks).map do |name| and remove TODO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've already tried exactly this but it was breaking a lot of tests. Let me try again.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You may need to add a Homebrew.args.reset or similar which will reset the instance variables and have it in https://github.com/Homebrew/brew/blob/master/Library/Homebrew/test/spec_helper.rb#L135-L208

In general there's some ARGV stuff there that may need similar code for Homebrew.args

Copy link
Copy Markdown
Contributor Author

@GauthamGoli GauthamGoli Sep 26, 2019

Choose a reason for hiding this comment

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

I think we've hit a cyclic dependency here.
formula_options method is used to allow extra arguments for formulae see - deps.rb#L55 and install.rb#L90 but formula_options itself needs to know what is passed on command line to define what options can be allowed on command line!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In that case you might want to allow e.g. ARGV to be passed in in some circumstances for initialisation so it's not operating on itself? Would that work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, if we limit the usage of ARGV to this one method we could make this work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would suggest it's passed in as an argument (a default one if necessary) to make testing easier and just treated as an Array. The issue we're trying to address isn't so much the use of ARGV but removing our patches on ARGV.

Comment thread Library/Homebrew/cli/args.rb Outdated
Comment thread Library/Homebrew/cli/args.rb Outdated
Comment thread Library/Homebrew/cli/parser.rb Outdated
@GauthamGoli GauthamGoli force-pushed the argv-cleanup-3 branch 3 times, most recently from 34b8fe8 to 2cd58ca Compare September 10, 2019 20:18
@GauthamGoli GauthamGoli force-pushed the argv-cleanup-3 branch 3 times, most recently from 633383b to 2e3a7dc Compare September 11, 2019 06:07
@GauthamGoli
Copy link
Copy Markdown
Contributor Author

@MikeMcQuaid https://github.com/Homebrew/brew/runs/276504778#step:5:373
Its weird that --ignore-dependencies is being passed even without the changes in this PR, but its causing the test to fail here.

@MikeMcQuaid
Copy link
Copy Markdown
Member

@GauthamGoli Are you stuck/blocked on this now? If so, can take a look and try to fix the tests. If it's not being passed but showing up that sounds like something being cached between tests that needs reset.

@GauthamGoli
Copy link
Copy Markdown
Contributor Author

GauthamGoli commented Oct 28, 2019

--ignore-dependencies is being passed, but on master branch, the warning doesn't show up in the test. So its not something about cache.
Anyways, please take a look.

@MikeMcQuaid
Copy link
Copy Markdown
Member

--ignore-dependencies is being passed, but on master branch, the warning doesn't show up in the test. So its not something about cache.

@GauthamGoli Maybe this needs rebased on master? I've changed that code recently.

@GauthamGoli
Copy link
Copy Markdown
Contributor Author

GauthamGoli commented Oct 28, 2019

Tests fail even after rebase.

Comment thread Library/Homebrew/cli/args.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like this is not being detected properly.

@MikeMcQuaid
Copy link
Copy Markdown
Member

--ignore-dependencies is being passed, but on master branch, the warning doesn't show up in the test. So its not something about cache.

Had a look: the issue isn't that --ignore-dependencies is being passed but that the output is not matching Cloning into or testball1/HEAD because it's ignoring/filtering out --HEAD for some reason.

@GauthamGoli
Copy link
Copy Markdown
Contributor Author

Got it! Thanks. Its the chicken egg problem of args not being populated.

@GauthamGoli
Copy link
Copy Markdown
Contributor Author

Tests pass now.
@MikeMcQuaid I think the code might need a bit of cleanup/simplification; can you please review, thanks!

Copy link
Copy Markdown
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.

A few minor questions but looks really good, nice work @GauthamGoli!

Comment thread Library/Homebrew/cli/parser.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it would be good to handle both the above at once and perhaps even return @args, @args_parsed, @parser all from this method to be able to make these attr_reader instead of attr_accessor.

Copy link
Copy Markdown
Contributor Author

@GauthamGoli GauthamGoli Nov 10, 2019

Choose a reason for hiding this comment

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

I'm not sure I understand this completely. Could you please add in an example code snippet here. Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Homebrew.args.args_parsed = @args_parsed

Comment thread Library/Homebrew/cli/args.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should/could this logic live inside HEAD??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

HEAD? is one of the keys in OpenStruct, so I don't think so it possible.
We could extract this logic out to another private method named HEAD

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeh, a private method for this sounds good 👍

Comment thread Library/Homebrew/cli/args.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

@GauthamGoli GauthamGoli mentioned this pull request Nov 5, 2019
@zachauten
Copy link
Copy Markdown
Contributor

@GauthamGoli @MikeMcQuaid So I guess I didn't notice that this PR moved the kegs method to args.rb when I started on #6622, should I just close that one and suggest changes here for the files that use ARGV.kegs?

@GauthamGoli
Copy link
Copy Markdown
Contributor Author

@zachauten #6622 need not be closed, after this PR is merged, you can rebase on master.

Comment thread Library/Homebrew/cli/parser.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@args_parsed = true
@args.args_parsed = @args_parsed = true

Comment thread Library/Homebrew/cli/parser.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Homebrew.args.args_parsed = @args_parsed

Comment thread Library/Homebrew/cli/args.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
attr_accessor :processed_options, :args_parsed
attr_reader :processed_options, :args_parsed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok but I think it would be better to have a custom method that allows them to only be set once and then be frozen/not allow future changes to be made rather than using attr_accessor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@MikeMcQuaid What do you think about this approach?

Copy link
Copy Markdown
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.

Looking good! A couple of final tiny things then good to merge.

Another thing I noticed is that it'd be nice to have https://github.com/Homebrew/brew/blob/86607314eabc7ed11a1860c3f88c517d83f3d113/Library/Homebrew/cli/parser.rb#L143 (@args_parsed) moved until as late as possible in the method just so it isn't set prematurely if something fails.

Comment thread Library/Homebrew/cli/args.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like this a lot more 👍. How about making it freeze_processed_options!(processed_options) to make it clearer it can only be called once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, updated.

Comment thread Library/Homebrew/cli/args.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@processed_options.concat(processed_options)
@processed_options += processed_options

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

Comment thread Library/Homebrew/cli/args.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd suggest putting this last just to avoid it being set if e.g. the freeze fails.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@MikeMcQuaid MikeMcQuaid merged commit 277a8b2 into Homebrew:master Dec 11, 2019
@MikeMcQuaid
Copy link
Copy Markdown
Member

Thanks again for more great work @GauthamGoli 🎉

@GauthamGoli
Copy link
Copy Markdown
Contributor Author

We need to watch this closely for a few days for any bugs. I will be watching the issues 👍

@lock lock bot added the outdated PR was locked due to age label Jan 10, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated PR was locked due to age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants