-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
List cask full-names #2878
Conversation
@@ -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) } |
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.
Make this multiple lines.
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.
Addressed in the latest commit
Library/Homebrew/formula.rb
Outdated
@@ -1364,6 +1364,18 @@ def self.clear_installed_formulae_cache | |||
@installed = nil | |||
end | |||
|
|||
def self.comparison |
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.
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.
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.
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"?
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.
Agreed this should live elsewhere and additionally a more descriptive name would be good (tap_and_name_comparison
or similar)
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.
Thanks for the thoughts! I've moved this to utils/comparer.rb as Comparer.tap_and_name
and tested it.
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 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.
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.
Sounds good. It's now in utils/comparison.rb, but extends Utils
instead of creating a new module.
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.
Sorry to not be clearer: please put it in utils.rb
, thanks.
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.
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") |
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'd name this third-party
instead of external-caskroom
.
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.
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 |
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 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.
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 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".
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 this should be set from CaskLoader
instead.
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.
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.
9b1a022
to
0a6d0a3
Compare
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.
LGTM once @reitermarkus has 👍d Cask bits.
0a6d0a3
to
fa7819f
Compare
@@ -31,6 +31,12 @@ def initialize(path) | |||
|
|||
@token = path.basename(".rb").to_s | |||
@path = path | |||
|
|||
@tap ||= if @path == CaskLoader.default_path(@token) |
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.
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
.
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.
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
.
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 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.
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.
@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.
fa7819f
to
d3cab95
Compare
d3cab95
to
12a4d34
Compare
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") |
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 call this "tap"
instead of "spec"
.
@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".
12a4d34
to
acf1b27
Compare
@reitermarkus Thanks for the additional feedback. Just did another rebase and push, so hopefully this is ready to be merged! |
Thanks, @wendorf! |
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.