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

List cask full-names #2878

Merged
merged 1 commit into from
Sep 17, 2017
Merged

Conversation

wendorf
Copy link
Contributor

@wendorf wendorf commented Jul 9, 2017

brew cask list supports the --full-name flag which will include the tap name for casks not part of the core caskroom/cask tap. For example, if cask "foo-beta" is installed from the caskroom/versions cask, brew cask list --full-name will report the name as "caskroom/versions/foo-beta".

This will be especially helpful with brew bundle cleanup, which currently cannot correctly identify a cask installed from a non-core tap.

@@ -14,6 +14,22 @@
EOS
end

it "lists full names" do
casks = %w[local-caffeine external-caskroom/spec/external-cask local-transmission].map { |c| Hbc::CaskLoader.load(c) }
Copy link
Member

Choose a reason for hiding this comment

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

Make this multiple lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the latest commit

@@ -1364,6 +1364,18 @@ def self.clear_installed_formulae_cache
@installed = nil
end

def self.comparison
Copy link
Member

Choose a reason for hiding this comment

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

Since this is used for both Formulae and Casks, this should live somewhere else, and have a self-explanatory name.

Also, maybe add a test for this. This could even be simplified to ->(a) { [a.include?("/"), a] } I think, but I'm not sure without a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no location that jumps out to me as more appropriate. My first thought is to add formula_comparer.rb, but this still suffers from the "this is used by formulae and casks" issue and I'm hesitant to add another file to ./Library/Homebrew. Do you have a location in mind? Is there a common name for "formulae and casks"? Maybe "token_comparer.rb" or "full_token_comparer.rb"?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed this should live elsewhere and additionally a more descriptive name would be good (tap_and_name_comparison or similar)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the thoughts! I've moved this to utils/comparer.rb as Comparer.tap_and_name and tested it.

Copy link
Member

Choose a reason for hiding this comment

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

I think Comparer is too generic a class name and it doesn't make sense having a single method there. tap_and_name_comparison in Utils makes more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. It's now in utils/comparison.rb, but extends Utils instead of creating a new module.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry to not be clearer: please put it in utils.rb, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, sorry about this misunderstanding. Just pushed out another change to move it there as a global method.

@@ -18,6 +18,7 @@

RSpec.shared_context "Homebrew-Cask" do
around(:each) do |example|
external_caskroom_tap = Tap.fetch("external-caskroom", "spec")
Copy link
Member

Choose a reason for hiding this comment

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

I'd name this third-party instead of external-caskroom.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the latest commit

Hbc.default_tap
elsif @sourcefile_path.to_s =~ HOMEBREW_TAP_PATH_REGEX
Tap.fetch(Regexp.last_match(1), Regexp.last_match(2))
end
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this will ever work this way with brew cask list. For installed Casks, the sourcefile_path will always be the one in the Caskroom metadata directory, hence will never contain any information about the Tap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found this to be required and correct for third-party taps. For example, the sourcefile_path for caskroom/homebrew-versions/microsoft-remote-desktop-beta is "/usr/local/Homebrew/Library/Taps/caskroom/homebrew-versions/Casks/microsoft-remote-desktop-beta.rb" in my environment. Regexp.last_match(1) is "caskroom" and Regexp.last_match(2) is "homebrew-versions".

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be set from CaskLoader instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing—just pushed that change. It's a little funky to me now that the cask_spec is also testing CaskLoader logic, but it was doing that before so I think it's fine.

@wendorf wendorf force-pushed the brew_cask_list_full-name branch 5 times, most recently from 9b1a022 to 0a6d0a3 Compare July 10, 2017 14:45
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.

LGTM once @reitermarkus has 👍d Cask bits.

@wendorf wendorf force-pushed the brew_cask_list_full-name branch from 0a6d0a3 to fa7819f Compare July 13, 2017 01:32
@@ -31,6 +31,12 @@ def initialize(path)

@token = path.basename(".rb").to_s
@path = path

@tap ||= if @path == CaskLoader.default_path(@token)
Copy link
Member

Choose a reason for hiding this comment

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

What I meant here was that it should only be set by the FromTapLoader, since this is the only case where we can be sure of the Tap. And Cask#full_name will still default to Hbc.default_tap if it is nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this would make --full-name not work, since the locally-installed casks are not loaded with FromTapLoader.

The two conditionals use full paths (default_path resolves to something like /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/Casks/foo.rb, and HOMEBREW_TAP_PATH_REGEX to something like (?-mix:\\/usr\\/local\\/Homebrew\\/Library\\/Taps\\/([\\w-]+)\\/([\\w-]+)\\/(.*))), so I believe we can be quite confident that this is the correct tap. This is the same logic that is used in Formula#initialize, which is why I originally felt comfortable putting it directly in Hbc::Cask#initialize instead of FromPathLoader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried out changing Hbc::Scopes::installed (used by the brew cask list command) to fetch casks by tap path, thus using FromTapLoader (see the patch), but failed the rspec ./test/cask/scopes_spec.rb:21 # Hbc::Scopes installed optimizes performance by resolving to a fully qualified path before calling Hbc::CaskLoader.load test. It looks like this optimization was put there for good reason, so I'm hesitant to change that behavior.

@reitermarkus Is there another option you think I should consider? Or do you think my existing approach is okay since the path checking is checking explicitly for the Homebrew tap install locations? I think path checking is the only way to do it without making seemingly-undesirable changes to how brew cask list gets its casks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@reitermarkus Thanks for your work on #2965 , which makes this part unnecessary. I've rebased and removed the unneeded code, so now this doesn't need to touch CaskLoader or the Cask constructor at all.

@wendorf wendorf force-pushed the brew_cask_list_full-name branch from fa7819f to d3cab95 Compare July 20, 2017 03:24
@reitermarkus reitermarkus mentioned this pull request Jul 29, 2017
5 tasks
@wendorf wendorf force-pushed the brew_cask_list_full-name branch from d3cab95 to 12a4d34 Compare August 5, 2017 18:09
@stale stale bot added the stale No recent activity label Aug 26, 2017
@stale
Copy link

stale bot commented Aug 26, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@@ -18,6 +18,7 @@

RSpec.shared_context "Homebrew-Cask" do
around(:each) do |example|
third_party_tap = Tap.fetch("third-party", "spec")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call this "tap" instead of "spec".

@stale stale bot removed the stale No recent activity label Aug 27, 2017
@reitermarkus
Copy link
Member

@wendorf, one small change, and this should be good to go.

`brew cask list` supports the `--full-name` flag which will include the tap
name for casks not part of the core caskroom/cask tap. For example, if
cask "foo-beta" is installed from the caskroom/versions cask, `brew cask
list --full-name` will report the name as "caskroom/versions/foo-beta".
@wendorf wendorf force-pushed the brew_cask_list_full-name branch from 12a4d34 to acf1b27 Compare September 16, 2017 17:00
@wendorf
Copy link
Contributor Author

wendorf commented Sep 16, 2017

@reitermarkus Thanks for the additional feedback. Just did another rebase and push, so hopefully this is ready to be merged!

@reitermarkus reitermarkus merged commit dbc4a38 into Homebrew:master Sep 17, 2017
@reitermarkus
Copy link
Member

Thanks, @wendorf!

@Homebrew Homebrew locked and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants