Skip to content

brew Operations

Manage brew packages on mac/OSX. See https://brew.sh/

Facts used in these operations: brew.BrewCasks, brew.BrewPackages, brew.BrewTaps, brew.BrewTrusted, brew.BrewVersion.

brew.cask_upgrade

Stateless operation

This operation will always execute commands and is not idempotent.

Upgrades all brew casks.

brew.cask_upgrade(**kwargs)

Global arguments

This operation also inherits all global arguments.

brew.casks

Add/remove/update brew casks.

brew.casks(casks: 'str | list[str] | None' = None, present=True, latest=False, upgrade=False,
         **kwargs,
    )
  • casks: list of casks to ensure
  • present: whether the casks should be installed
  • latest: whether to upgrade casks without a specified version
  • upgrade: run brew cask upgrade before installing casks

Versions: Cask versions can be pinned like brew: <pkg>@<version>.

Example:

brew.casks(
    name='Upgrade and install the latest cask',
    casks=["godot"],
    upgrade=True,
    latest=True,
)

Global arguments

This operation also inherits all global arguments.

brew.packages

Add/remove/update brew packages.

brew.packages(
         packages: 'str | list[str] | None' = None,
         present=True,
         latest=False,
         update=False,
         upgrade=False,
         **kwargs,
    )
  • packages: list of packages to ensure
  • present: whether the packages should be installed
  • latest: whether to upgrade packages without a specified version
  • update: run brew update before installing packages
  • upgrade: run brew upgrade before installing packages

Note

Homebrew maintains separate versions of certain formulae (e.g. python, postgres and node) and multiple versions of these formulae can be installed at the same time (e.g. python@3.15 and python@3.10) but Homebrew does not otherwise support installing a specific version of a formula (e.g. rclone@1.75). When one adds one of these specific packages with package@X.Y.Z, brew will drop the Z (if it was supplied) and install the latest sub-version of X.Y of package.

Examples:

from pyinfra.operations import brew
# Update package list and install packages
brew.packages(
    name='Install Vim and vimpager',
    packages=["vimpager", "vim"],
    update=True,
)

# Install the latest versions of packages (always check)
brew.packages(
    name="Install latest Vim",
    packages=["vim"],
    latest=True,
)

Global arguments

This operation also inherits all global arguments.

brew.tap

Add/remove brew taps.

brew.tap(
         src: 'str | None' = None,
         present: 'bool' = True,
         trusted: 'bool | None' = False,
         url: 'str | None' = None,
         **kwargs,
    )
  • src: the name of the tap
  • present: whether this tap should be present or not. Default True.
  • trusted: whether or not this tap should be trusted. Default False.
  • url: the url of the tap. See https://docs.brew.sh/Taps

Examples:

brew.tap(
    name="Add a brew tap",
    src="includeos/includeos",
    trusted=True,
)

# Just url is equivalent to
# `brew tap kptdev/kpt https://github.com/kptdev/kpt`
brew.tap(
    url="https://github.com/kptdev/kpt",
    trusted=True,
)

# src and url is equivalent to
# `brew tap example/project https://github.example.com/project`
brew.tap(
    src="example/project",
    url="https://github.example.com/project",
    trusted=True,
)

# Multiple taps
for tap in ["includeos/includeos", "ktr0731/evans"]:
    brew.tap(
        name={f"Add brew tap {tap}"},
        src=tap,
        trusted=True,
    )

Global arguments

This operation also inherits all global arguments.

brew.trust

Trust/untrust brew casks, commands, formulae and/or taps (see https://docs.brew.sh/Tap-Trust)

brew.trust(items: 'str | list[str]', kind: 'BrewItemKind', trusted: 'bool',
         **kwargs,
    )
  • items: the cask, command, formula or tap to be trusted or untrusted
  • kind: whether the item is a CASK, COMMAND, FORMULA or TAP (using BrewItemKind enum)
  • trusted: whether this item should be trusted or not. no default, must be specified

Examples:

brew.trust(
    name="Mark magic tap as trusted",
    items="includeos/includeos",
    kind=BrewItemKind.TAP,
    trusted=True
)

Global arguments

This operation also inherits all global arguments.

brew.update

Stateless operation

This operation will always execute commands and is not idempotent.

Updates brew repositories.

brew.update(**kwargs)

Global arguments

This operation also inherits all global arguments.

brew.upgrade

Stateless operation

This operation will always execute commands and is not idempotent.

Upgrades all brew packages.

brew.upgrade(**kwargs)

Global arguments

This operation also inherits all global arguments.