Skip to content

bundle: add base class helpers and DRY up extension executable handling#21854

Open
costajohnt wants to merge 3 commits intoHomebrew:mainfrom
costajohnt:feat/bundle-extension-dry-helpers
Open

bundle: add base class helpers and DRY up extension executable handling#21854
costajohnt wants to merge 3 commits intoHomebrew:mainfrom
costajohnt:feat/bundle-extension-dry-helpers

Conversation

@costajohnt
Copy link
Copy Markdown
Contributor

Follow-up to #21802 as requested in review feedback.

Adds two helpers to the Extension base class and refactors all extensions to use them:

  • package_manager_executable! — returns Pathname or raises with a clear error message, eliminating the repeated exe = package_manager_executable; return false if exe.nil? pattern across all extensions
  • with_package_manager_env — block helper that gets the executable, sets up the PATH env, and yields the executable, DRYing up the get-executable + set-env + run-command pattern

Extensions refactored: cargo, go, uv, krew, npm, vscode, mac_app_store, flatpak

  • 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 (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Claude was used to scaffold the refactoring following the existing extension patterns. All code was manually reviewed and tested. Style, typechecking (brew typecheck), and tests (brew tests --only=bundle) pass locally.

Add `package_manager_executable!` and `with_package_manager_env` helpers
to the Extension base class. Refactor all extensions to use them,
eliminating repeated nil-check boilerplate and inline env setup.
Rename &blk to &_blk to satisfy RuboCop Lint/UnusedMethodArgument
while keeping yield for Performance/RedundantBlockCall.
Copy link
Copy Markdown
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.

Much nicer thanks! One thought.

{ "PATH" => "#{executable.dirname}:#{ORIGINAL_PATHS.join(":")}" }
end

sig { params(_blk: T.proc.params(executable: Pathname).returns(T.untyped)).returns(T.untyped) }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would be good to avoid T.untyped here. Ideally make this an actual type, if not make it T.anything if possible.

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.

2 participants