Remove API placeholders in FormulaStruct and CaskStruct#21656
Merged
MikeMcQuaid merged 1 commit intomainfrom Mar 3, 2026
Merged
Remove API placeholders in FormulaStruct and CaskStruct#21656MikeMcQuaid merged 1 commit intomainfrom
FormulaStruct and CaskStruct#21656MikeMcQuaid merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to ensure API path placeholders (e.g., $HOMEBREW_PREFIX, /$HOME) are replaced with real local values when API data is loaded into FormulaStruct/CaskStruct, by centralizing placeholder-removal logic in APIHashable.
Changes:
- Add
APIHashable#deep_remove_placeholdersto recursively replace API placeholders in hashes/arrays/strings. - Call placeholder removal during
Homebrew::API::FormulaStruct.from_hashandHomebrew::API::CaskStruct.from_hash. - Add a temporary-looking filter in
generate-formula-api.rbthat limits generation toredis.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Library/Homebrew/dev-cmd/generate-formula-api.rb | Adds a per-formula filter (currently hardcoded to only generate redis). |
| Library/Homebrew/api_hashable.rb | Introduces recursive placeholder removal helper in APIHashable. |
| Library/Homebrew/api/formula_struct.rb | Applies placeholder removal when constructing FormulaStruct from a hash. |
| Library/Homebrew/api/cask_struct.rb | Applies placeholder removal when constructing CaskStruct from a hash. |
Comments suppressed due to low confidence (2)
Library/Homebrew/api/formula_struct.rb:16
- This change adds new behavior (placeholder replacement) to
FormulaStruct.from_hash, but there are no tests covering placeholder removal when constructing/deserialize-ing aHomebrew::API::FormulaStruct. Adding a spec that passes a hash containing$HOMEBREW_PREFIX//$HOME/$HOMEBREW_CELLARand asserts the resulting struct contains real paths would help prevent regressions.
def self.from_hash(formula_hash)
formula_hash = ::Formula.deep_remove_placeholders(formula_hash)
formula_hash = formula_hash.transform_keys(&:to_sym)
.slice(*decorator.all_props)
.compact_blank
new(**formula_hash)
Library/Homebrew/api/cask_struct.rb:15
- This change adds new behavior (placeholder replacement) to
CaskStruct.from_hash, but the existingapi/cask_struct_spec.rbcoverage for::from_hashdoesn’t assert placeholder removal. Add a test case that includes$HOMEBREW_PREFIX//$HOME/$HOMEBREW_CELLARinraw_caveatsorraw_artifactsand verifies the struct (or#caveats/#artifacts) resolves them correctly.
def self.from_hash(cask_hash, ignore_types: false)
return super(cask_hash) if ignore_types
cask_hash = ::Cask::Cask.deep_remove_placeholders(cask_hash)
cask_hash = cask_hash.transform_keys(&:to_sym)
.slice(*decorator.all_props)
.compact_blank
new(**cask_hash)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
53c8c72 to
c2ac70b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When generating the API, we replace
HOMEBREW_PREFIXandDir.homewith placeholder values, but we don't actually replace the placeholders with the real values when loading fromFormulaStruct(orCaskStruct). This PR adds the replacement logic to theAPIHashablemodule so it's included by default anywhere the module is used.