** 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.
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
.
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! !! ** **
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/
I wonder if there is a guy who will do it automatically from PipFile ~ ~ Pipenv is the best ~~
Recommended Posts