Skip to content

Homebrew formula template generator for simple Python projects

License

Notifications You must be signed in to change notification settings

thanethomson/python-brewer

Repository files navigation

python-brewer

PyPI PyPI

Overview

python-brewer is a command-line utility (written in Python) to help with generating formula templates for Homebrew from installed Python packages. The aim is not to generate perfect, ready-to-go Homebrew formulae out of the box: the aim is to generate a template for you, taking some of the harder slog work out of the process.

Primarily, it takes an installed package, finds all of its installed dependencies, and generates a template containing resource references to all of these dependencies (as per the installed versions). It also automatically computes the SHA256 hashes of all of the packages by downloading their source distributions from PyPI.

See Homebrew's Python for Formula Authors guide for more details on submitting Python-based formulae for Homebrew.

Requirements

In order to install python-brewer, you will need:

  • Python 2.7+ or Python 3.5+
  • pip

Installation

Installing via PyPI (install into a virtual environment please):

> pip install python-brewer

Basic Usage

As a simple example, we'll generate a base template for Statik - the static web site generator. The first step is to install the package into your virtual environment:

> pip install -U statik

The next step is to use the pybrew command, provided by python-brewer, to generate the Homebrew formula template. In this case, at the time of this writing, I was generating the formula for v0.14.2 of Statik.

> pybrew \
    # The name of the formula
    -n "Statik" \
    # A description for the formula
    -d "Python-based, generic static web site generator aimed at developers" \
    # Project homepage
    -H https://getstatik.com \
    # HEAD of Git repo
    -g https://github.com/thanethomson/statik.git \
    # Latest release of the package
    -r https://github.com/thanethomson/statik/archive/v0.14.2.tar.gz \
    # Name of the Python package
    statik \
    # Output file to which to write the template
    statik.rb

At the time of this writing, the following file was generated by pybrew:

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

  desc "Python-based, generic static web site generator aimed at developers"
  homepage "https://getstatik.com"
  url "https://github.com/thanethomson/statik/archive/v0.14.2.tar.gz"
  sha256 "ef2e67ecf8a1a59b71b5c88b86c7335e32cc480d3156716c3b2e7691edab7620"
  head "https://github.com/thanethomson/statik.git"

  # TODO: If you're submitting an existing package, make sure you include your
  #       bottle block here.

  depends_on :python if MacOS.version <= :snow_leopard

  resource "future" do
    url "https://pypi.python.org/packages/00/2b/8d082ddfed935f3608cc61140df6dcbf0edea1bc3ab52fb6c29ae3e81e85/future-0.16.0.tar.gz"
    sha256 "e39ced1ab767b5936646cedba8bcce582398233d6a627067d4c6a454c90cfedb"
  end

  resource "tornado" do
    url "https://pypi.python.org/packages/1e/7c/ea047f7bbd1ff22a7f69fe55e7561040e3e54d6f31da6267ef9748321f98/tornado-4.4.2.tar.gz"
    sha256 "2898f992f898cd41eeb8d53b6df75495f2f423b6672890aadaf196ea1448edcc"
  end

  resource "argh" do
    url "https://pypi.python.org/packages/e3/75/1183b5d1663a66aebb2c184e0398724b624cecd4f4b679cb6e25de97ed15/argh-0.26.2.tar.gz"
    sha256 "e9535b8c84dc9571a48999094fda7f33e63c3f1b74f3e5f3ac0105a58405bb65"
  end

  resource "pathtools" do
    url "https://pypi.python.org/packages/e7/7f/470d6fcdf23f9f3518f6b0b76be9df16dcc8630ad409947f8be2eb0ed13a/pathtools-0.1.2.tar.gz"
    sha256 "7c35c5421a39bb82e58018febd90e3b6e5db34c5443aaaf742b3f33d4655f1c0"
  end

  resource "PyYAML" do
    url "https://pypi.python.org/packages/4a/85/db5a2df477072b2902b0eb892feb37d88ac635d36245a72a6a69b23b383a/PyYAML-3.12.tar.gz"
    sha256 "592766c6303207a20efc445587778322d7f73b161bd994f227adaa341ba212ab"
  end

  resource "watchdog" do
    url "https://pypi.python.org/packages/54/7d/c7c0ad1e32b9f132075967fc353a244eb2b375a3d2f5b0ce612fd96e107e/watchdog-0.8.3.tar.gz"
    sha256 "7e65882adb7746039b6f3876ee174952f8eaaa34491ba34333ddf1fe35de4162"
  end

  resource "httpwatcher" do
    url "https://pypi.python.org/packages/02/97/055185c6a54e470ef943556b613bc56975e82da3f456bdd08f036cf7cae8/httpwatcher-0.4.0.tar.gz"
    sha256 "2f84c93a3766a11a69f2d339f143889558bd5eccee77574593c39111a3202645"
  end

  resource "MarkupSafe" do
    url "https://pypi.python.org/packages/c0/41/bae1254e0396c0cc8cf1751cb7d9afc90a602353695af5952530482c963f/MarkupSafe-0.23.tar.gz"
    sha256 "a4ec1aff59b95a14b45eb2e23761a0179e98319da5a7eb76b56ea8cdc7b871c3"
  end

  resource "jinja2" do
    url "https://pypi.python.org/packages/f4/3f/28387a5bbc6883082c16784c6135440b94f9d5938fb156ff579798e18eda/Jinja2-2.9.4.tar.gz"
    sha256 "aab8d8ca9f45624f1e77f2844bf3c144d180e97da8824c2a6d7552ad039b5442"
  end

  resource "lipsum" do
    url "https://pypi.python.org/packages/59/97/00636d64bc77dc173d782995de1b56dde39c70bb97112964452709b4d9aa/lipsum-0.1.2.tar.gz"
    sha256 "ba5f46cef19104c07f889b14486a3772845fc25afa1eb5e2eee1f2d9badcb8ab"
  end

  resource "markdown" do
    url "https://pypi.python.org/packages/d4/32/642bd580c577af37b00a1eb59b0eaa996f2d11dfe394f3dd0c7a8a2de81a/Markdown-2.6.7.tar.gz"
    sha256 "daebf24846efa7ff269cfde8c41a48bb2303920c7b2c7c5e04fa82e6282d05c0"
  end

  resource "Unidecode" do
    url "https://pypi.python.org/packages/ba/64/410af95d27f2a8824112d17ed41ea7ce6d2cbc8a4832c2e548d3408fad0a/Unidecode-0.04.20.tar.gz"
    sha256 "ed4418b4b1b190487753f1cca6299e8076079258647284414e6d607d1f8a00e0"
  end

  resource "python-slugify" do
    url "https://pypi.python.org/packages/63/86/ecf7b570089d794a9476c7411a06a329eb8e386f3407576640ccbe7a4698/python-slugify-1.2.1.tar.gz"
    sha256 "501182ec738cc8b743ae5c76c183f4427187ef016257f062b3fa594f60916e34"
  end

  resource "six" do
    url "https://pypi.python.org/packages/b3/b2/238e2590826bfdd113244a40d9d3eb26918bd798fc187e2360a8367068db/six-1.10.0.tar.gz"
    sha256 "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a"
  end

  resource "SQLAlchemy" do
    url "https://pypi.python.org/packages/da/04/8048a5075d6e29235bbd6f1ea092a38dbe2630c670e73d4aa923a4e5521c/SQLAlchemy-1.1.5.tar.gz"
    sha256 "68fb40049690e567ebda7b270176f5abf0d53d9fbd515fec4e43326f601119b6"
  end

  def install
    virtualenv_install_with_resources
  end

  # TODO: Add your package's tests here
end

Of course, I've since added the original bottle block for the script and the package's unit tests. See this commit and statik.rb in homebrew-core for more details.

Python 2 or 3?

While python-brewer runs well on Python 2.7+ and Python 3.5+, it's important to note that sometimes your dependencies will be different based on which Python version you're running, and based on the nature of your dependencies. Sometimes, certain packages include different dependencies when running Python 3, e.g. Tornado.

As such, python-brewer automatically changes the Python dependency based on the detected Python version. In the above package for Statik, I ran pybrew with Python 2 and, as such, automatically added the line:

  depends_on :python if MacOS.version <= :snow_leopard

If I had run it with Python 3, it would have added the following line instead:

  depends_on :python3

This will, of course, cause Homebrew to attempt to install its own Python 3 distribution for your package.

Contributing

Please feel free to contribute! If you want to add or fix something in python-brewer, please:

  1. Fork the project
  2. Make your changes in a feature branch
  3. Submit a pull request

License

The MIT License (MIT)

Copyright (c) 2017 Thane Thomson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Homebrew formula template generator for simple Python projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published