Publish your own Python library with Homebrew

For some reason

** When installing with pip **

$ pyenv install 3.9.0
$ pyenv virtualenv 3.9.0 venv4myapp
$ pyenv activate venv4myapp
(venv4myapp) $ pip install myapp
(venv4myapp) $ myapp --option veryBadMan
(venv4myapp) $ deactivate

** When installing with Homebrew **

$ brew tap SoHappyMan/myapp
$ brew install myapp
$ myapp --option veryHappyHeyMaaaaaan

How to publish a Python library in Homebrew if you have dependent libraries. Link Collection.

To install with Homebrew, you need to write a Ruby script called Formula that describes the "installation procedure". Basically, you need to install the dependent libraries in it.

When using Pyinstaller

Homebrew's dependent library installation is troublesome as it is, so let's make it a single file. It was easy, but it was late. With this, there is no need to install dependent libraries. This article is detailed.

Make Python self-made tools installable with Homebrew

Formula looks like this.

class Mlkokuji < Formula
  desc "Command line script to search and display notifications from the Ministry of Land, Infrastructure, Transport and Tourism website ⛱⛱⛱"
  homepage "https://github.com/ryuhey0123/mlit-kokuji"
  url "https://github.com/ryuhey0123/mlit-kokuji/releases/download/v1.1/mlkokuji-v1.1.tar.gz"
  sha256 "78380cc079a812cd359dbfb27b7af40f15792d27b090858df21a71d95d9a09dd"
  license "MIT"

  def install
    bin.install 'mlkokuji'
  end

end

Like this. In the above example, you would create a single file called mlkokuji and install it in bin.

Install dependent libraries in virtual environment for Homebrew

I was wondering why Python works with Homebrew and where the dependent libraries are installed, but Homebrew seems to have its own virtual environment and it seems to install the dependent libraries there. This article is detailed.

Be careful when creating a Python app Formula with Homebrew

Formula looks like this.

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

  desc "Add page number to some PDF files and merge it → PERFECT DOCUMENT! ⭐️"
  homepage "https://github.com/ryuhey0123/pdf2doc"
  url "https://github.com/ryuhey0123/pdf2doc/archive/v1.2.0.tar.gz"
  sha256 "6dc9f92b1a0b43d05957d8a8b6c59d52d22808029c826cf60ace20e06d991d52"
  license "MIT"

  depends_on "[email protected]"

  resource "click" do
    url "https://files.pythonhosted.org/packages/27/6f/be940c8b1f1d69daceeb0032fee6c34d7bd70e3e649ccac0951500b4720e/click-7.1.2.tar.gz"
    sha256 "d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"
  end

  resource "crayons" do
    url "https://files.pythonhosted.org/packages/b8/6b/12a1dea724c82f1c19f410365d3e25356625b48e8009a7c3c9ec4c42488d/crayons-0.4.0.tar.gz"
    sha256 "bd33b7547800f2cfbd26b38431f9e64b487a7de74a947b0fafc89b45a601813f"
  end

  resource "colorama" do
    url "https://files.pythonhosted.org/packages/1f/bb/5d3246097ab77fa083a61bd8d3d527b7ae063c7d8e8671b1cf8c4ec10cbe/colorama-0.4.4.tar.gz"
    sha256 "5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"
  end

  resource "fpdf" do
    url "https://files.pythonhosted.org/packages/37/c6/608a9e6c172bf9124aa687ec8b9f0e8e5d697d59a5f4fad0e2d5ec2a7556/fpdf-1.7.2.tar.gz"
    sha256 "125840783289e7d12552b1e86ab692c37322e7a65b96a99e0ea86cca041b6779"
  end

  resource "PyPDF2" do
    url "https://files.pythonhosted.org/packages/b4/01/68fcc0d43daf4c6bdbc6b33cc3f77bda531c86b174cac56ef0ffdb96faab/PyPDF2-1.26.0.tar.gz"
    sha256 "e28f902f2f0a1603ea95ebe21dff311ef09be3d0f0ef29a3e44a932729564385"
  end

  resource "Send2Trash" do
    url "https://files.pythonhosted.org/packages/13/2e/ea40de0304bb1dc4eb309de90aeec39871b9b7c4bd30f1a3cdcb3496f5c0/Send2Trash-1.5.0.tar.gz"
    sha256 "60001cc07d707fe247c94f74ca6ac0d3255aabcb930529690897ca2a39db28b2"
  end

  resource "yaspin" do
    url "https://files.pythonhosted.org/packages/f8/6d/7d5d081db3f399f5e345ad5107fa015f84a0c0dd62f1c9deb277ba83774e/yaspin-1.2.0.tar.gz"
    sha256 "72e9cdbc0e797ef886c373fef2bcd6526a704a470696f9d78d0bb27951fe659a"
  end

  def install
    virtualenv_install_with_resources
  end

end

As a caveat, ** Dependent libraries will not be installed automatically **, so you need to write them here. In the above example, the library crayons that colors the CLI output depends on a library called colorama. pip install will do a good job in this area, but it's manual.

virtualenv_install_with_resources contains a function that looks for and executes setup.py, so you need ** setup.py even if you don't publish it to pypi! !! ** **

Embed other libraries in the library in the first place

I noticed this while looking at the pipenv repository. Formula was simple, although there should be some dependent packages. Is a library that is version-independent built into the repository?

Github: pipenv/pipenv/vendor/

Impressions

I wonder if there is a guy who will do it automatically from PipFile ~ ~ Pipenv is the best ~~

Recommended Posts

Publish your own Python library with Homebrew
Until you can install your own Python library with pip
Run the intellisense of your own python library with VScode.
[Reinforcement learning] DQN with your own library
[Python] Register your own library on PyPI
Until you install your own Python library
Make your own module quickly with setuptools (python)
Steps to install your own library with pip
Memo to create your own Box with Pepper's Python
Call your own C library with Go using cgo
Try sorting your own objects with priority queue in Python
[Python] Make your own LINE bot
[Python] logging in your own module
Setup modern Python environment with Homebrew
I made my own Python library
Solve your own maze with Q-learning
[Hyperledger Iroha] Query with Python library
Manage each Python version with Homebrew
Train UGATIT with your own dataset
Solve your own maze with DQN
Call your own C language shared library from Python using ctypes
Your own Twitter client made with Django
Create your own Linux commands in Python
Create wordcloud from your tweet with python3
[LLDB] Create your own command in Python
Easily use your own functions in Python
Create your own DNS server with Twisted
[Python] Package and distribute your own modules
Create your own Composite Value with SQLAlchemy
HTML document your Python program with Sphinx
Use cryptography library cryptography with Docker Python image
To import your own module with jupyter
Publish your website with responder + Gunicorn + Apache
Get your own IP address in Python
Create your own virtual camera with Python + OpenCV and apply original effects
How to access data with object ['key'] for your own Python class
Python 3.6 email library
Try to make your own AWS-SDK with bash
[Personal memo] julia --Using Python library with julia using PyCall
FizzBuzz with Python3
Scraping with Python
Library comparison summary to generate PDF with Python
[Python] Implement your own list-like class using collections.UserList
Python ast library
Statistics with python
Linux C / C ++ Build your own library creation environment
Create polka dot wallpaper with Python Image Library
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
I wanted to install Python 3.4.3 with Homebrew + pyenv
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
Manage AWS nicely with the Python library Boto
with syntax (Python)
Python Library notes
Import your own modules in Grasshopper's Python development
Zundokokiyoshi with python