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
Fix brew formulae
and brew casks
when the API is used
#15471
Conversation
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.
Nice work so far. I left some comments about excluding the default cask and formula taps if they exist locally because they might be out-of-date.
It would also be nice to see some benchmarks here comparing what we have now with after this change since we're kind of combining the two current methods. I don't expect it to be slow but we might as well double check.
Library/Homebrew/cmd/casks.sh
Outdated
cat "${HOMEBREW_CACHE}/api/cask_names.txt" | ||
echo | ||
homebrew-items '*/Casks/*\.rb' '' 's|/Casks/|/|' '^homebrew/cask' | ||
} | sort -u |
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 we're repeating this sort -u
in both places: perhaps it should be part of homebrew-items
or homebrew-items-unique
or something?
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.
The sort -u
is used here to sort the names again because combining the 2 lists messes up the sorting. The -u
can probably be removed once the core taps are filtered out though because there should be no more duplicates.
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 can still be duplicates with the short names, right? It should be possible for two formulas to exist with the same name as long as they're in different taps. Not sure how big of a deal any duplication would be though.
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.
It should be possible for two formulas to exist with the same name as long as they're in different taps.
Yes, this is definitely a thing that happens and is OK.
Switching to regex needed a few more changes than I expected due to the different |
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.
Makes sense to me so far but interested in thoughts from @apainintheneck!
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 this looks really good. The blank line seems to be a part of the formula_names.txt
file as far as I can tell so that probably needs to get fixed somewhere else. Other than that I left a nit but I think this ready to merge as is.
Library/Homebrew/cmd/formulae.sh
Outdated
echo | ||
else | ||
homebrew-items '*\.rb' 'Casks' 's|/Formula/|/|' '^homebrew/core' | ||
homebrew-items '*\.rb' '.*Casks.*' 's|/Formula/|/|' '^homebrew/core' |
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.
homebrew-items '*\.rb' '.*Casks.*' 's|/Formula/|/|' '^homebrew/core' | |
homebrew-items '*\.rb' '.*/Casks/.*' 's|/Formula/|/|' '^homebrew/core' |
Nit: It might be nice to be a little more defensive here and with the regex above it too.
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.
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'm not sure why but adding slashes breaks the filtering and no longer excludes 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.
It seems to be because we're not filtering by file but directory instead and the final slash is omitted. The following works for me locally. If I remember correctly, we don't currently use nesting but it will probably get added to the core repos in the future for git performance reasons.
homebrew-items '*\.rb' '.*Casks.*' 's|/Formula/|/|' '^homebrew/core' | |
homebrew-items '*\.rb' '.*/Casks(/.*|$)' 's|/Formula/|/|' '^homebrew/core' |
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 implemented the changes and removed an unnecessary echo
in formulae.sh
that caused the extra blank line which I somehow missed.
|
Thanks so much for your first contribution (hopefully of many)! Without people like you submitting PRs we couldn't run this project. You rock, @Omoeba! |
I'm not sure if this is an elegant solution but it gives an identical output to when
HOMEBREW_NO_INSTALL_FROM_API
is set, regardless of whetherhomebrew/core
orhomebrew/cask
are tapped. Feel free to make any improvements.Closes #15229
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?