Skip to content

feat(operations.brew, facts.brew): add support for brew trust#1836

Open
morrison12 wants to merge 14 commits into
pyinfra-dev:3.xfrom
morrison12:feature-brew-trust
Open

feat(operations.brew, facts.brew): add support for brew trust#1836
morrison12 wants to merge 14 commits into
pyinfra-dev:3.xfrom
morrison12:feature-brew-trust

Conversation

@morrison12

Copy link
Copy Markdown
Contributor

Added support for the brew trust that is now mandatory with Homebrew 6.0 (and beyond) as noted in #1828.

Support is:

  1. a new parameter to brew.tap as it seems unlikely one would want add a tap without trusting it
  2. a new brew.trust operation given one can choose to trust narrower scopes than the full tap, e.g. a specific cask.
  3. the related fact: brew.BrewTrusted.

The diffs are rather noisy given the changes required to appease the static checkers and my choice to change brew.tap to use StringCommand et al.

  • Pull request is based on the default branch (3.x at this time)
  • Pull request includes tests for any new/updated operations/facts
  • Pull request includes documentation for any new/updated operations/facts
  • Tests pass (see scripts/dev-test.sh)
  • Type checking & code style passes (see scripts/dev-lint.sh)
  • Pull request title follows the
    conventional commits format

ps ignore the mess from committing in the wrong place; I (think) I fixed that.

@wowi42 wowi42 added new feature facts Issues with facts. operations Issues with operations. documentation Issues with docs/examples/docstrings. labels Jun 16, 2026
@morrison12

Copy link
Copy Markdown
Contributor Author

Ugh.. Forgot about python 3.10. Back in a bit.

- change from StrEnum to plain Enum to make work with python 3.10 (and later)

- rename to BrewItemKind for clarity
- brew.trust tests not needed in brew.tap
@morrison12 morrison12 changed the title feat(operations, facts): add support for brew trust feat(operations.brew, facts.brew): add support for brew trust Jun 18, 2026

@wowi42 wowi42 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Issues

  • trust() docstring example uses wrong parameter names. The example passes item= (singular) but the parameter is items= (plural), and trust=True but the parameter is trusted. Copy-pasting the example would fail with TypeError. The + item: docstring line also needs to become + items:.

  • raise OperationValueError from None has no message. When kind is an invalid string, the error is raised with no description. The user sees a bare OperationValueError with no clue what went wrong.

  • brew trust --json v1 uses space instead of =. The documented flag is --json=v1 (Homebrew 6.0.0 release notes). The canonical = form is safer and matches the upstream docs.

Notes

  • trusted parameter docstring says "Default False" but the Python default is None. The trusted = trusted or False line makes it behave as documented, but the docstring and signature are inconsistent.

Comment thread src/pyinfra/operations/brew.py Outdated

brew.trust(
name="Mark magic tap as trusted",
item="includeos/includeos",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The docstring example uses item= (singular) but the parameter is items= (plural), and trust=True but the parameter is trusted. Copy-pasting this example would fail with TypeError. The + item: docstring line above the example also needs to become + items:.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Comment thread src/pyinfra/operations/brew.py Outdated
try:
kind = BrewItemKind(kind)
except (TypeError, ValueError):
raise OperationValueError from None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

raise OperationValueError from None has no message argument. When kind is an invalid string, the user sees a bare OperationValueError with no clue what went wrong. Add a descriptive message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the best course of action for this one is to wait until #1841 is merged and then I can update the tests and remove this per the TODO above it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

code now removed.

Comment thread src/pyinfra/facts/brew.py Outdated

@override
def command(self) -> str:
return "brew trust --json v1"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The documented flag is --json=v1 (Homebrew 6.0.0 release notes, man page). While Homebrew may accept the space form, the canonical = form is safer and matches upstream docs.

- i.e. --json=v1 not json v1
- for brew.trusted, use items vs. item and use trusted vs. trust
- for brew.tap set default for trust to False in param def; still need or False in body for when it is omitted
@morrison12

Copy link
Copy Markdown
Contributor Author
  • trusted parameter docstring says "Default False" but the Python default is None. The trusted = trusted or False line makes it behave as documented, but the docstring and signature are inconsistent.

Also fixed.. The line in the body of the function is still required for the case where the parameter is not provided (needed for backwards compatibility).

- remove extraneous commas added by ruff
- remove extraneous commas added by ruff
- remove kludge allowing string values
- update tests to use enum:BrewKind:<enum-value>
@morrison12 morrison12 requested a review from wowi42 July 10, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Issues with docs/examples/docstrings. facts Issues with facts. new feature operations Issues with operations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants