homebrew-core/Formula/pipenv.rb

105 lines
4.8 KiB
Ruby

class Pipenv < Formula
include Language::Python::Virtualenv
desc "Python dependency management tool"
homepage "https://github.com/pypa/pipenv"
url "https://files.pythonhosted.org/packages/74/4f/22ef1aace6d703a7b5bf80d09b8ca3315fd68bcba89bf2d625d8b330310b/pipenv-2022.9.24.tar.gz"
sha256 "d682375d6a6edd2f1ed2f76085b7191de149ff8381bce6c1aaf7f55061b04457"
license "MIT"
bottle do
rebuild 2
sha256 cellar: :any_skip_relocation, arm64_ventura: "5feb4b172f502861488ae34cfbb2b9ddfa3cc05a1f2ee1801930747025fac424"
sha256 cellar: :any_skip_relocation, arm64_monterey: "bff34499e6f5386f79d5f3fee666895e5662045d1465eb4795736e2fa063e576"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "af6a0fe6859e36fe4acfc9aa4ed02eac081de51ea501e9316c714c06becef748"
sha256 cellar: :any_skip_relocation, ventura: "ca9884b23a6ae5df06f6dd72ff1c3462e8649027939da0dec8c5e28f01729943"
sha256 cellar: :any_skip_relocation, monterey: "936de89f25774427c285ac88fd3ed82f08e8914ee25b29c911393d1b72f04d7b"
sha256 cellar: :any_skip_relocation, big_sur: "373876aa766fee3f99d7967f520a51e3cda11e2e8096d397ef1ed11e125d74ce"
sha256 cellar: :any_skip_relocation, catalina: "5f725141ac7eff2955a582ac891533ab79f5b165cdecfcfbde4290d6fe6629f9"
sha256 cellar: :any_skip_relocation, x86_64_linux: "a49a0e52fe4c5716991d7cb61afe75ffe6dd17b26d862843ee30853afa3d4721"
end
depends_on "python@3.11"
resource "certifi" do
url "https://files.pythonhosted.org/packages/cb/a4/7de7cd59e429bd0ee6521ba58a75adaec136d32f91a761b28a11d8088d44/certifi-2022.9.24.tar.gz"
sha256 "0d9c601124e5a6ba9712dbc60d9c53c21e34f5f641fe83002317394311bdce14"
end
resource "distlib" do
url "https://files.pythonhosted.org/packages/58/07/815476ae605bcc5f95c87a62b95e74a1bce0878bc7a3119bc2bf4178f175/distlib-0.3.6.tar.gz"
sha256 "14bad2d9b04d3a36127ac97f30b12a19268f211063d8f8ee4f47108896e11b46"
end
resource "filelock" do
url "https://files.pythonhosted.org/packages/95/55/b897882bffb8213456363e646bf9e9fa704ffda5a7d140edf935a9e02c7b/filelock-3.8.0.tar.gz"
sha256 "55447caa666f2198c5b6b13a26d2084d26fa5b115c00d065664b2124680c4edc"
end
resource "platformdirs" do
url "https://files.pythonhosted.org/packages/ff/7b/3613df51e6afbf2306fc2465671c03390229b55e3ef3ab9dd3f846a53be6/platformdirs-2.5.2.tar.gz"
sha256 "58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"
end
resource "virtualenv" do
url "https://files.pythonhosted.org/packages/b4/27/b71df0a723d879baa0af1ad897b2498ad78f284ae668b4420092e44c05fa/virtualenv-20.16.6.tar.gz"
sha256 "530b850b523c6449406dfba859d6345e48ef19b8439606c5d74d7d3c9e14d76e"
end
resource "virtualenv-clone" do
url "https://files.pythonhosted.org/packages/85/76/49120db3bb8de4073ac199a08dc7f11255af8968e1e14038aee95043fafa/virtualenv-clone-0.5.7.tar.gz"
sha256 "418ee935c36152f8f153c79824bb93eaf6f0f7984bae31d3f48f350b9183501a"
end
def python3
"python3.11"
end
def install
# Using the virtualenv DSL here because the alternative of using
# write_env_script to set a PYTHONPATH breaks things.
# https://github.com/Homebrew/homebrew-core/pull/19060#issuecomment-338397417
venv = virtualenv_create(libexec, python3)
venv.pip_install resources
venv.pip_install buildpath
# `pipenv` needs to be able to find `virtualenv` on PATH. So we
# install symlinks for those scripts in `#{libexec}/tools` and create a
# wrapper script for `pipenv` which adds `#{libexec}/tools` to PATH.
(libexec/"tools").install_symlink libexec/"bin/pip", libexec/"bin/virtualenv"
env = {
PATH: "#{libexec}/tools:$PATH",
}
(bin/"pipenv").write_env_script(libexec/"bin/pipenv", env)
(zsh_completion/"_pipenv").write Utils.safe_popen_read({ "_PIPENV_COMPLETE" => "zsh_source" },
libexec/"bin/pipenv", { err: :err })
(fish_completion/"pipenv.fish").write Utils.safe_popen_read({ "_PIPENV_COMPLETE" => "fish_source" },
libexec/"bin/pipenv", { err: :err })
end
# Avoid relative paths
def post_install
lib_python_path = Pathname.glob(libexec/"lib/python*").first
lib_python_path.each_child do |f|
next unless f.symlink?
realpath = f.realpath
rm f
ln_s realpath, f
end
end
test do
ENV["LC_ALL"] = "en_US.UTF-8"
assert_match "Commands", shell_output("#{bin}/pipenv")
system "#{bin}/pipenv", "--python", which(python3)
system "#{bin}/pipenv", "install", "requests"
system "#{bin}/pipenv", "install", "boto3"
assert_predicate testpath/"Pipfile", :exist?
assert_predicate testpath/"Pipfile.lock", :exist?
assert_match "requests", (testpath/"Pipfile").read
assert_match "boto3", (testpath/"Pipfile").read
end
end