跳转到主要内容

为Poetry项目生成Homebrew公式

项目描述

poetry-homebrew-formula — Poetry插件用于Homebrew公式

version python downloads

Tests pre-commit.ci status

Maintainability codecov

ruff poetry pre-commit

这是一个Poetry插件,可以将指定Python项目的依赖项渲染为Homebrew公式。

本项目受poetry-brew的启发,旨在解决相同问题,但采用不同的方法。

设置

  • 如果您通过pipx安装了poetry(推荐)

    pipx inject poetry poetry-homebrew-formula
    
  • 如果您以其他方式安装了poetry,大多数情况下这也将适用

    poetry self add poetry-homebrew-formula
    

    有关使用插件的更多信息,请参阅poetry文档

用法

运行poetry homebrew-formula --help以获取如何使用它的详细信息

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

自定义模板

此插件允许使用基于Jinja的自定义模板来渲染公式。这对于需要比默认模板更复杂的“打包配方”的软件特别有用。在自定义模板中,一些常见组件作为“简码”模板标签提供

  • {{ PACKAGE_URL }}:将被替换为项目的源URL和校验和。
  • {{ RESOURCES }}:将被替换为项目的依赖项。

考虑到这一点,以下用途成为可能

预填充公式

如果您想自己定义整个公式,并通过poetry-homebrew-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

{{ 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
渲染示例公式
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 }}

这实际上是在复制homebrew-pypi-poet的行为,即它仅发出依赖资源

渲染示例
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

来自stdin的模板

该插件支持通过stdin进行模板定义,以及通过使用-作为选项参数将它们输出到stdout

$ 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

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

poetry_homebrew_formula-0.3.0.tar.gz (10.1 kB 查看哈希值)

上传时间:

构建分发

poetry_homebrew_formula-0.3.0-py3-none-any.whl (9.8 kB 查看哈希值)

上传时间: Python 3

由以下支持