Skip to content

Conversation

@Rylan12
Copy link
Member

@Rylan12 Rylan12 commented Dec 4, 2025

This PR adds a new FormulaStruct to serve as an intermediary between the API and the formula loading in Formulary.

Eventually, this will be able to load from the internal API as well.

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.

Looks great so far! Goal here would be to simplify the formulary logic as much as possible while still making it responsible for actually calling the relevant DSL methods.

Feel free to punt on the map comments etc.: that could be instead done in another, later PR/pass.

@Rylan12
Copy link
Member Author

Rylan12 commented Dec 8, 2025

This is still in-progress, but here's a different approach that makes Formulary much cleaner

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.

Yeh, this looks really great!

@Rylan12 Rylan12 force-pushed the use-formula-struct branch 3 times, most recently from a9e7907 to 3428b31 Compare December 9, 2025 04:17
@Rylan12
Copy link
Member Author

Rylan12 commented Dec 9, 2025

This is mostly there, but the service blocks don't quite work yet

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 is looking so good!

@Rylan12
Copy link
Member Author

Rylan12 commented Dec 9, 2025

Oh, another comment while I'm thinking about it:

I removed a few lines that existed for backward compatibility with previous iterations of the api (e.g. ruby_source_checksum used to be called ruby_source_sha256)

I don't think we ever attempt to load old JSON data, so this seems like it should be okay. I think in the future: the only backward compatibility we should need here is between the latest release and now, right?

@MikeMcQuaid
Copy link
Member

I don't think we ever attempt to load old JSON data, so this seems like it should be okay. I think in the future: the only backward compatibility we should need here is between the latest release and now, right?

Agreed.

@Rylan12 Rylan12 force-pushed the use-formula-struct branch 5 times, most recently from 2ba81da to c341fe8 Compare December 10, 2025 02:54
@Rylan12 Rylan12 marked this pull request as ready for review December 10, 2025 03:09
Copilot AI review requested due to automatic review settings December 10, 2025 03:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new FormulaStruct class that serves as an intermediary data structure between the Homebrew JSON API and formula instantiation in Formulary. The refactoring extracts complex formula parsing logic from Formulary.load_formula_from_json! into a dedicated struct and helper method, improving code organization and maintainability. This abstraction also sets the groundwork for loading formulae from an internal API in the future.

Key changes:

  • Introduces Homebrew::API::FormulaStruct with typed fields and predicate methods for all formula properties
  • Adds Homebrew::API::Formula.generate_formula_struct_hash to transform API JSON into struct-compatible format
  • Simplifies Formulary.load_formula_from_json! by delegating to the struct for data access
  • Creates SPDX::LicenseExpression type alias for improved type clarity

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
Library/Homebrew/api/formula_struct.rb New struct class defining typed fields for all formula properties with predicate methods and dependency/requirement parsing logic
Library/Homebrew/api/formula.rb Adds generate_formula_struct_hash method to transform JSON API responses into FormulaStruct-compatible format
Library/Homebrew/formulary.rb Refactored to use FormulaStruct for cleaner, more maintainable formula loading from API
Library/Homebrew/utils/spdx.rb Introduces LicenseExpression type alias to replace verbose inline type definitions
Library/Homebrew/formula.rb Updates type signatures to use new SPDX::LicenseExpression type alias
Library/Homebrew/dependency_collector.rb Updates comment referencing moved API_SUPPORTED_REQUIREMENTS constant
Library/Homebrew/api.rb Adds require for new formula_struct file
Library/Homebrew/test/formulary_spec.rb Updates test data to include new required fields (specs, tap_git_head, expanded deprecation/disable fields)
Library/Homebrew/sorbet/tapioca/compilers/api_structs.rb New Tapioca compiler for generating RBI signatures for FormulaStruct predicate methods
Library/Homebrew/sorbet/rbi/dsl/homebrew/api/formula_struct.rbi Generated RBI file with predicate method signatures for FormulaStruct
Files not reviewed (1)
  • Library/Homebrew/sorbet/rbi/dsl/homebrew/api/formula_struct.rbi: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

@Rylan12 Great work here. Happy for you to merge this whenever it's 🟢 and you're happy with it. Any changes/cleanup could be made in a follow-up.

@Rylan12 Rylan12 enabled auto-merge December 10, 2025 15:53
@Rylan12 Rylan12 added this pull request to the merge queue Dec 10, 2025
Merged via the queue into main with commit 9c04f34 Dec 10, 2025
39 checks passed
@Rylan12 Rylan12 deleted the use-formula-struct branch December 10, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants