Skip to main content

poetry-homebrew-formula — Poetry Plugin for Homebrew Formulae

version python downloads

Tests pre-commit.ci status

Maintainability codecov

ruff poetry pre-commit

A plugin for Poetry that renders the dependencies of a given python project into a Homebrew formula.

This project was inspired by poetry-brew that aims to solve the same problem but with a different approach.

Setup

  • If you installed poetry via pipx (preferred):

    pipx inject poetry poetry-homebrew-formula
    
  • If you installed poetry a different way, most likely this will work, too:

    poetry self add poetry-homebrew-formula
    

    Please consult the poetry docs on using plugins for more details.

Usage

Run poetry homebrew-formula --help for details on how to use it:

poetry run poetry homebrew-formula --help --ansi

Custom templates

The plugin allows for the use of custom Jinja-based templates to be used when rendering the formula. This is particularly useful for software that requires more a elaborate "packaging recipe" than what the default template can offer. In custom templates, some common components are offered as "shortcode" template tags:

  • {{ PACKAGE_URL }}: will be replaced with the project own source URL and checksum.
  • {{ RESOURCES }}: will be replaced with the project's dependencies.

With that in mind, the following uses become possible:

Prepopulated formula

If you want to define the entire formula yourself and populate only the dynamic components via poetry-homebrew-formula, you may use both shortcodes like so:

class MySoftwareProject < Formula
  include Language::Python::Virtualenv

  desc "This is a software project that has its formula prepopulated with most details"
  homepage "https://mysoftwareproject.invalid"
  license "MIT

{{ PACKAGE_URL }}

  depends_on "python3"
  depends_on "rust" => >:build

{{ RESOURCES }}

  def install
    virtualenv_create(libexec, "python3")
    virtualenv_install_with_resources

    doing_something_here
    generate_completions_from_executable(bin/"my-software", shells: [:bash, :zsh, :fish], shell_parameter_format: :click)
  end

  test do
    false
  end
end
Rendered example formula
class MySoftwareProject < Formula
  include Language::Python::Virtualenv

  desc "This is a software project that has its formula prepopulated with most details"
  homepage "https://mysoftwareproject.invalid"
  license "MIT

  url "https://files.pythonhosted.org/packages/cd/28/fa4281532b4eeb28ba5ead093d24d553ee93861df0f743cad37e01ed6bc6/mysoftwareproject-0.1.0a1.tar.gz"
  sha256 "7158b7e86e9b1399a7aae6a169fd8a4716636284b74870a352f268f852098e2c"

  depends_on "python3"
  depends_on "rust" => >:build

  resource "click" do
    url "https://files.pythonhosted.org/packages/96/d3/f04c7bfcf5c1862a2a5b845c6b2b360488cf47af55dfa79c98f6a6bf98b5/click-8.1.7.tar.gz"
    sha256 "ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"
  end

  resource "pydantic" do
    url "https://files.pythonhosted.org/packages/aa/3f/56142232152145ecbee663d70a19a45d078180633321efb3847d2562b490/pydantic-2.5.3.tar.gz"
    sha256 "b3ef57c62535b0941697cce638c08900d87fcb67e29cfa99e8a68f747f393f7a"
  end

  resource "pydantic-core" do
    url "https://files.pythonhosted.org/packages/b2/7d/8304d8471cfe4288f95a3065ebda56f9790d087edc356ad5bd83c89e2d79/pydantic_core-2.14.6.tar.gz"
    sha256 "1fd0c1d395372843fba13a51c28e3bb9d59bd7aebfeb17358ffaaa1e4dbbe948"
  end

  def install
    virtualenv_create(libexec, "python3")
    virtualenv_install_with_resources

    doing_something_here
    generate_completions_from_executable(bin/"fancy-software", shells: [:bash, :zsh, :fish], shell_parameter_format: :click)
  end

  test do
    false
  end
end

Resources only

If you have other plans and only need the resources to be rendered, your template can also look like this:

{{ RESOURCES }}

This is effectively replicating the behavior of homebrew-pypi-poet in that it only emits the dependency resources:

Rendered example
resource "click" do
  url "https://files.pythonhosted.org/packages/96/d3/f04c7bfcf5c1862a2a5b845c6b2b360488cf47af55dfa79c98f6a6bf98b5/click-8.1.7.tar.gz"
  sha256 "ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"
end

resource "pydantic" do
  url "https://files.pythonhosted.org/packages/aa/3f/56142232152145ecbee663d70a19a45d078180633321efb3847d2562b490/pydantic-2.5.3.tar.gz"
  sha256 "b3ef57c62535b0941697cce638c08900d87fcb67e29cfa99e8a68f747f393f7a"
end

resource "pydantic-core" do
  url "https://files.pythonhosted.org/packages/b2/7d/8304d8471cfe4288f95a3065ebda56f9790d087edc356ad5bd83c89e2d79/pydantic_core-2.14.6.tar.gz"
  sha256 "1fd0c1d395372843fba13a51c28e3bb9d59bd7aebfeb17358ffaaa1e4dbbe948"
end

Templates from stdin

The plugin supports template definitions via stdin, as well as emitting them to stdout by using - as the option argument:

$ echo '{{RESOURCES}}' | poetry homebrew-formula -t- -o- | tee my-formula.rb

resource "click" do
  url "https://files.pythonhosted.org/packages/96/d3/f04c7bfcf5c1862a2a5b845c6b2b360488cf47af55dfa79c98f6a6bf98b5/click-8.1.7.tar.gz"
  sha256 "ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"
end

resource "pydantic" do
…

Metadata

Release files for poetry-homebrew-formula 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for poetry-homebrew-formula 0.3.0
File Size Uploaded Provenance
poetry_homebrew_formula-0.3.0.tar.gz 10.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for poetry-homebrew-formula 0.3.0
File Interpreter ABI Platform
poetry_homebrew_formula-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / poetry_homebrew_formula-0.3.0.tar.gz

Download URL poetry_homebrew_formula-0.3.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8a9f1b81b02dbd0899ba6e89f022bad4fa9e94dc6df07fdc1ca37825aa47874b
BLAKE2b-256 checksum
How to use checksums
b2c76b62c4e2ed396c9ab64d5afb81e98349364093509e2af82e491c975ec512
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / poetry_homebrew_formula-0.3.0-py3-none-any.whl

Download URL poetry_homebrew_formula-0.3.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ddc38f1afc274b62d16a3f0af20f7e8b05119038c07ef4d61ef2a8c80e7801b
BLAKE2b-256 checksum
How to use checksums
fc6d26af71c28e5a7ff0602513273c33d5257c33a338ed5fb9b8cb76412988a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Security for poetry-homebrew-formula 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page