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

items.sh: return early when no Taps directory #14259

Merged
merged 2 commits into from Dec 27, 2022

Conversation

cho-m
Copy link
Member

@cho-m cho-m commented Dec 16, 2022

  • 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?

Workaround for removing errors output in #14254. Will need API usage for actual completion support, but haven't had chance to look into this.

EDIT: Updated to allow completion from cached JSON to fix #14254

Haven't tested on HOMEBREW_INSTALL_FROM_API setup, but seemed to work when I changed Taps in following line to invalid directory:

find "${HOMEBREW_REPOSITORY}/Library/Taps" \


e.g. changing above to Taps2 and trying without this PR:

brew formulae
find: /opt/homebrew/Library/Taps2: No such file or directorybrew info find: /opt/homebrew/Library/Taps2: No such file or directory
find: /opt/homebrew/Library/Taps2: No such file or directory
brew

with PR:

brew formulaebrew info <TAB>
<NOTHING>

@BrewTestBot
Copy link
Member

Review period will end on 2022-12-19 at 21:44:38 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 16, 2022
@cho-m cho-m changed the title items.sh: hide find stderr items.sh: return early when no Taps directory Dec 19, 2022
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Dec 20, 2022
@BrewTestBot
Copy link
Member

Review period ended.

Comment on lines 18 to 20
local api_formulae
api_formulae="$(ruby -e "require 'json'; JSON.parse(File.read('${HOMEBREW_CACHE}/api/formula.json')).each { |f| puts f['name'] }")"
formulae=$(echo -e "${formulae}\n${api_formulae}" | sort -uf | grep .)
Copy link
Member Author

@cho-m cho-m Dec 20, 2022

Choose a reason for hiding this comment

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

Concept idea for reading cached JSON using ruby without brew libraries.

This currently doesn't handle any error inside Ruby. Particularly, a corrupt JSON file ends up dumping the entire contents of formula.json to terminal which can be quite lengthy. EDIT: hiding stderr should be enough for this.

I had added grep . since ${formulae} can be "" so it leads to blank line. Not sure if there is better way to handle this.

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.

This makes sense! Happy to try it out.

if [[ -n "${HOMEBREW_INSTALL_FROM_API}" && -f "${HOMEBREW_CACHE}/api/formula.json" ]]
then
local api_formulae
api_formulae="$(ruby -e "require 'json'; JSON.parse(File.read('${HOMEBREW_CACHE}/api/formula.json')).each { |f| puts f['name'] }" 2>/dev/null)"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should do this calculation when we download HOMEBREW_CACHE/api/formula.json, instead. That way we only need to do it once per unique cache file (I'm assuming this line is relatively slow)

Copy link
Member

Choose a reason for hiding this comment

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

@Rylan12 That seems like a good idea! Let's merge as-is for now and iterate to improve performance here 💪🏻

@MikeMcQuaid MikeMcQuaid merged commit b2173e6 into Homebrew:master Dec 27, 2022
@MikeMcQuaid
Copy link
Member

Thanks again @cho-m!

@github-actions github-actions bot added the outdated PR was locked due to age label Jan 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2023
@cho-m cho-m deleted the items-find-devnull branch March 5, 2024 02:06
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 info [TAB] completion in ZSH prints errors but suggests nothing
4 participants