homebrew-core/Formula/pyenv.rb

80 lines
3.0 KiB
Ruby

class Pyenv < Formula
desc "Python version management"
homepage "https://github.com/pyenv/pyenv"
url "https://github.com/pyenv/pyenv/archive/refs/tags/v2.3.5.tar.gz"
sha256 "075e530afe352d112a23d46ba1a3358090bb9e31e47b5caa4ab1a1f32df0cfb0"
license "MIT"
version_scheme 1
head "https://github.com/pyenv/pyenv.git", branch: "master"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+(-\d+)?)$/i)
end
bottle do
sha256 cellar: :any, arm64_monterey: "70c0c86cac3343593fc470a13f5e906cbf605189226e981fb6f709ba2b4620e4"
sha256 cellar: :any, arm64_big_sur: "984c150a4d9340c688c215f325c839ec5100489445ebc7eb318b4a5a08e5f4b2"
sha256 cellar: :any, monterey: "e5c592a2aecc7fc19766d801b98b82919aa954889949e4ad68e6f0f2b1b8e530"
sha256 cellar: :any, big_sur: "44da2df9b0f397c4f76671b5d732d1c4bca562b88b5e43e6a4e3cbb156e20de0"
sha256 cellar: :any, catalina: "e767977d9b1456bebe983c426f31ba213b323a43b17e849c0779245d99b4a8c9"
sha256 cellar: :any_skip_relocation, x86_64_linux: "2682a35e90ca23ac5d8f598d38465236dfc3ae1a2932c6b8bed71b51bd89e49e"
end
depends_on "autoconf"
depends_on "openssl@1.1"
depends_on "pkg-config"
depends_on "readline"
uses_from_macos "python" => :test
uses_from_macos "bzip2"
uses_from_macos "libffi"
uses_from_macos "ncurses"
uses_from_macos "xz"
uses_from_macos "zlib"
def install
inreplace "libexec/pyenv", "/usr/local", HOMEBREW_PREFIX
inreplace "libexec/pyenv-rehash", "$(command -v pyenv)", opt_bin/"pyenv"
inreplace "pyenv.d/rehash/source.bash", "$(command -v pyenv)", opt_bin/"pyenv"
system "src/configure"
system "make", "-C", "src"
prefix.install Dir["*"]
%w[pyenv-install pyenv-uninstall python-build].each do |cmd|
bin.install_symlink "#{prefix}/plugins/python-build/bin/#{cmd}"
end
share.install prefix/"man"
# Do not manually install shell completions. See:
# - https://github.com/pyenv/pyenv/issues/1056#issuecomment-356818337
# - https://github.com/Homebrew/homebrew-core/pull/22727
end
test do
# Create a fake python version and executable.
pyenv_root = Pathname(shell_output("pyenv root").strip)
python_bin = pyenv_root/"versions/1.2.3/bin"
foo_script = python_bin/"foo"
foo_script.write "echo hello"
chmod "+x", foo_script
# Test versions.
versions = shell_output("eval \"$(#{bin}/pyenv init --path)\" " \
"&& eval \"$(#{bin}/pyenv init -)\" " \
"&& pyenv versions").split("\n")
assert_equal 2, versions.length
assert_match(/\* system/, versions[0])
assert_equal(" 1.2.3", versions[1])
# Test rehash.
system "pyenv", "rehash"
refute_match "Cellar", (pyenv_root/"shims/foo").read
assert_equal "hello", shell_output("eval \"$(#{bin}/pyenv init --path)\" " \
"&& eval \"$(#{bin}/pyenv init -)\" " \
"&& PYENV_VERSION='1.2.3' foo").chomp
end
end