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

Fix brew formulae and brew casks when the API is used #15471

Merged
merged 2 commits into from May 25, 2023

Conversation

Omoeba
Copy link
Contributor

@Omoeba Omoeba commented May 20, 2023

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 whether homebrew/core or homebrew/cask are tapped. Feel free to make any improvements.

Closes #15229

  • 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 typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Copy link
Contributor

@apainintheneck apainintheneck left a 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 Show resolved Hide resolved
Library/Homebrew/cmd/casks.sh Outdated Show resolved Hide resolved
cat "${HOMEBREW_CACHE}/api/cask_names.txt"
echo
homebrew-items '*/Casks/*\.rb' '' 's|/Casks/|/|' '^homebrew/cask'
} | sort -u
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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.

@Omoeba
Copy link
Contributor Author

Omoeba commented May 23, 2023

Switching to regex needed a few more changes than I expected due to the different find on macOS and Linux having different ways to turn on extended regex. sort -u is also replaced by sort -f because-u is now unnecessary thanks to the core taps being filtered out and -f is added to maintain a consistent order with sort -uf in items.sh. One interesting thing to note though is brew formulae returns an extra newline with the API enabled but brew casks doesn't. I'm not sure what causes it, whether it is dependent on the specific taps I have, or what negative effects it may cause for things like tab completion (if any). As always, feel free to make any edits.

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.

Makes sense to me so far but interested in thoughts from @apainintheneck!

Copy link
Contributor

@apainintheneck apainintheneck left a 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.

echo
else
homebrew-items '*\.rb' 'Casks' 's|/Formula/|/|' '^homebrew/core'
homebrew-items '*\.rb' '.*Casks.*' 's|/Formula/|/|' '^homebrew/core'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

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'm not sure why but adding slashes breaks the filtering and no longer excludes casks.

Copy link
Contributor

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.

Suggested change
homebrew-items '*\.rb' '.*Casks.*' 's|/Formula/|/|' '^homebrew/core'
homebrew-items '*\.rb' '.*/Casks(/.*|$)' 's|/Formula/|/|' '^homebrew/core'

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've implemented the changes and removed an unnecessary echo in formulae.sh that caused the extra blank line which I somehow missed.

@Omoeba
Copy link
Contributor Author

Omoeba commented May 24, 2023

sort -f was changed to sort -uf to maintain the existing behavior of removing duplicate short names when there are formulae with the same name in homebrew/core and a custom tap.

@MikeMcQuaid
Copy link
Member

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!

@MikeMcQuaid MikeMcQuaid merged commit 2f63d26 into Homebrew:master May 25, 2023
24 checks passed
@Omoeba Omoeba deleted the fix-noncore branch May 25, 2023 11:20
@github-actions github-actions bot added the outdated PR was locked due to age label Jun 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2023
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.

brew casks does not show casks from external taps unless HOMEBREW_NO_INSTALL_FROM_API is set
3 participants