homebrew-core/Formula/linode-cli.rb

106 lines
4.8 KiB
Ruby

class LinodeCli < Formula
include Language::Python::Virtualenv
desc "CLI for the Linode API"
homepage "https://www.linode.com/products/cli/"
url "https://github.com/linode/linode-cli/archive/refs/tags/v5.27.2.tar.gz"
sha256 "2f16c5507d4a6673c3185d5ad3744d27448de25c96f32bd7ffa82e3647c0e898"
license "BSD-3-Clause"
head "https://github.com/linode/linode-cli.git", branch: "master"
bottle do
sha256 cellar: :any_skip_relocation, arm64_ventura: "f7aadeea34f7eeceaeb8bb1e189d15927223e50c373d58b5131ee4edfced34b2"
sha256 cellar: :any_skip_relocation, arm64_monterey: "b74c9c86c2a207ed86b1a4ac2f0902889e56de4abae159546a7a3546b90e6414"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "1e91e85145366255b0bca6c3865f7b48b054d113bae6f1a92c6c8ca5a3e1ca3d"
sha256 cellar: :any_skip_relocation, ventura: "9e655c1d7d302885dcab64f4558c55a097b3eaf5109cdbd1711b5c4746daddd1"
sha256 cellar: :any_skip_relocation, monterey: "4f3da1c90405695b16e04c279455e0f638def66fb9467b7772203391b2662691"
sha256 cellar: :any_skip_relocation, big_sur: "b304cdfe69965172d98c3c660c5047c228b31657549e5879fea3c3b3c6c1491f"
sha256 cellar: :any_skip_relocation, x86_64_linux: "427183c90166888476456b74f740845a2741e25504c8acf988fd9922802f4ef0"
end
depends_on "openssl@1.1"
depends_on "python@3.11"
depends_on "pyyaml"
resource "linode-api-spec" do
url "https://raw.githubusercontent.com/linode/linode-api-docs/refs/tags/v4.141.0/openapi.yaml"
sha256 "de09b02dd832b018293f277ac2035403f582c30ea256fbb7a0d97b947353adaa"
end
resource "certifi" do
url "https://files.pythonhosted.org/packages/cb/a4/7de7cd59e429bd0ee6521ba58a75adaec136d32f91a761b28a11d8088d44/certifi-2022.9.24.tar.gz"
sha256 "0d9c601124e5a6ba9712dbc60d9c53c21e34f5f641fe83002317394311bdce14"
end
resource "charset-normalizer" do
url "https://files.pythonhosted.org/packages/a1/34/44964211e5410b051e4b8d2869c470ae8a68ae274953b1c7de6d98bbcf94/charset-normalizer-2.1.1.tar.gz"
sha256 "5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845"
end
resource "idna" do
url "https://files.pythonhosted.org/packages/8b/e1/43beb3d38dba6cb420cefa297822eac205a277ab43e5ba5d5c46faf96438/idna-3.4.tar.gz"
sha256 "814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"
end
resource "requests" do
url "https://files.pythonhosted.org/packages/a5/61/a867851fd5ab77277495a8709ddda0861b28163c4613b011bc00228cc724/requests-2.28.1.tar.gz"
sha256 "7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"
end
resource "terminaltables" do
url "https://files.pythonhosted.org/packages/f5/fc/0b73d782f5ab7feba8d007573a3773c58255f223c5940a7b7085f02153c3/terminaltables-3.1.10.tar.gz"
sha256 "ba6eca5cb5ba02bba4c9f4f985af80c54ec3dccf94cfcd190154386255e47543"
end
resource "urllib3" do
url "https://files.pythonhosted.org/packages/c2/51/32da03cf19d17d46cce5c731967bf58de9bd71db3a379932f53b094deda4/urllib3-1.26.13.tar.gz"
sha256 "c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8"
end
def install
venv = virtualenv_create(libexec, "python3.11", system_site_packages: false)
non_pip_resources = %w[terminaltables linode-api-spec]
venv.pip_install resources.reject { |r| non_pip_resources.include? r.name }
# Switch build-system to poetry-core to avoid rust dependency on Linux.
# Remove on next release: https://github.com/matthewdeanmartin/terminaltables/commit/9e3dda0efb54fee6934c744a13a7336d24c6e9e9
resource("terminaltables").stage do
inreplace "pyproject.toml", 'requires = ["poetry>=0.12"]', 'requires = ["poetry-core>=1.0"]'
inreplace "pyproject.toml", 'build-backend = "poetry.masonry.api"', 'build-backend = "poetry.core.masonry.api"'
venv.pip_install_and_link Pathname.pwd
end
resource("linode-api-spec").stage do
buildpath.install "openapi.yaml"
end
# The bake command creates a pickled version of the linode-cli OpenAPI spec
system libexec/"bin/python3", "-m", "linodecli", "bake", "./openapi.yaml", "--skip-config"
# Distribute the pickled spec object with the module
cp "data-3", "linodecli"
inreplace "setup.py" do |s|
s.gsub! "version=get_version(),", "version='#{version}',"
# Prevent setup.py from installing the bash_completion script
s.gsub! "data_files=get_baked_files(),", ""
end
bash_completion.install "linode-cli.sh" => "linode-cli"
venv.pip_install_and_link buildpath
end
test do
require "securerandom"
random_token = SecureRandom.hex(32)
with_env(
LINODE_CLI_TOKEN: random_token,
) do
json_text = shell_output("#{bin}/linode-cli regions view --json us-east")
region = JSON.parse(json_text)[0]
assert_equal region["id"], "us-east"
assert_equal region["country"], "us"
end
end
end