diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2e65c70..3445793 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,7 +12,8 @@ jobs: uses: actions/checkout@v4 - name: Install formula run: | - brew install -s Formula/snowcli.rb + brew install --formula -s Formula/snowcli.rb + brew install --formula -s Formula/snowflake-cli.rb - name: Check snow commands run: | snow --help diff --git a/Formula/snowcli.rb b/Formula/snowcli.rb index 7fecbd2..1b915cb 100644 --- a/Formula/snowcli.rb +++ b/Formula/snowcli.rb @@ -1,7 +1,7 @@ class Snowcli < Formula include Language::Python::Virtualenv desc "A CLI for Snowflake development" - homepage "https://github.com/snowflake-labs/snowcli" + homepage "https://github.com/snowflake-labs/snowflake-cli" url "https://files.pythonhosted.org/packages/03/69/b508427075311424de383944ecdd484918516e67081bda932779ef5360e5/snowflake_cli_labs-2.0.0.tar.gz" sha256 "28ba342cf7b55a4d7aebb97bc1da4cd3ba7b05cd247dee11f52f80a1234ffdda" diff --git a/Formula/snowcli.tmpl.rb b/Formula/snowcli.tmpl.rb index 4db5d41..b0de85d 100644 --- a/Formula/snowcli.tmpl.rb +++ b/Formula/snowcli.tmpl.rb @@ -1,7 +1,7 @@ class Snowcli < Formula include Language::Python::Virtualenv desc "A CLI for Snowflake development" - homepage "https://github.com/snowflake-labs/snowcli" + homepage "https://github.com/snowflake-labs/snowflake-cli" url "{{ sf_url }}" sha256 "{{ sf_sha }}" diff --git a/Formula/snowflake-cli.rb b/Formula/snowflake-cli.rb new file mode 100644 index 0000000..7bd1b28 --- /dev/null +++ b/Formula/snowflake-cli.rb @@ -0,0 +1,24 @@ + class SnowflakeCli < Formula + include Language::Python::Virtualenv + desc "A CLI for Snowflake development" + homepage "https://github.com/snowflake-labs/snowflake-cli" + url "https://files.pythonhosted.org/packages/03/69/b508427075311424de383944ecdd484918516e67081bda932779ef5360e5/snowflake_cli_labs-2.0.0.tar.gz" + sha256 "28ba342cf7b55a4d7aebb97bc1da4cd3ba7b05cd247dee11f52f80a1234ffdda" + + depends_on "python3" + + def install + ENV["CARGO_NET_GIT_FETCH_WITH_CLI"] = "true" + #without_pip=false because of https://github.com/Homebrew/brew/pull/15792 + venv = virtualenv_create(libexec, "python3", system_site_packages: false, without_pip: false) + venv.instance_variable_get(:@formula).system venv.instance_variable_get(:@venv_root)/"bin/python", + "-m", "pip", "install", "pip==22.3.1" + venv.instance_variable_get(:@formula).system venv.instance_variable_get(:@venv_root)/"bin/pip", + "install", "snowflake-cli-labs==2.0.0" + bin.install_symlink "#{libexec}/bin/snow" => "snow" + end + + test do + false + end + end \ No newline at end of file diff --git a/Formula/snowflake-cli.tmpl.rb b/Formula/snowflake-cli.tmpl.rb new file mode 100644 index 0000000..27071f5 --- /dev/null +++ b/Formula/snowflake-cli.tmpl.rb @@ -0,0 +1,24 @@ + class SnowflakeCli < Formula + include Language::Python::Virtualenv + desc "A CLI for Snowflake development" + homepage "https://github.com/snowflake-labs/snowflake-cli" + url "{{ sf_url }}" + sha256 "{{ sf_sha }}" + + depends_on "python3" + + def install + ENV["CARGO_NET_GIT_FETCH_WITH_CLI"] = "true" + #without_pip=false because of https://github.com/Homebrew/brew/pull/15792 + venv = virtualenv_create(libexec, "python3", system_site_packages: false, without_pip: false) + venv.instance_variable_get(:@formula).system venv.instance_variable_get(:@venv_root)/"bin/python", + "-m", "pip", "install", "pip==22.3.1" + venv.instance_variable_get(:@formula).system venv.instance_variable_get(:@venv_root)/"bin/pip", + "install", "snowflake-cli-labs=={{ version }}" + bin.install_symlink "#{libexec}/bin/snow" => "snow" + end + + test do + false + end + end \ No newline at end of file diff --git a/README.md b/README.md index 138776b..e223f02 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# homebrew-snowcli +# homebrew-snowflake-cli Homebrew formula allowing for installation of Snowflake CLI using homebrew tap. diff --git a/update-snowcli.py b/update-snowcli.py new file mode 100644 index 0000000..93c2bfe --- /dev/null +++ b/update-snowcli.py @@ -0,0 +1,33 @@ +import re +import subprocess +from pathlib import Path +from textwrap import indent + +import jinja2 + + +def main(): + env = jinja2.Environment( + loader=jinja2.loaders.FileSystemLoader(Path(__file__).parent) + ) + template = env.get_template("Formula/snowflake.tmpl.rb") + packages = subprocess.check_output(["poet", "snowflake-cli-labs"], encoding="utf-8") + + sf_pattern = r'\s+resource \"snowflake-cli-labs\" do\s+url \"(.+)\"\s+sha256 \"(\w+)\"\s+end\n' + match = re.findall(sf_pattern, packages) + if not match: + raise ValueError("snowflake dependency not present in deps") + sf_url, sf_sha = match[0] + + version = subprocess.check_output(["snow", "--version"], encoding="utf-8").split()[-1] + + with open("Formula/snowcli.rb", "w+") as fh: + fh.write(template.render( + sf_url=sf_url, + sf_sha=sf_sha, + version=version, + )) + + +if __name__ == '__main__': + main() diff --git a/update.py b/update.py index ba61cd5..85f0697 100644 --- a/update.py +++ b/update.py @@ -10,7 +10,7 @@ def main(): env = jinja2.Environment( loader=jinja2.loaders.FileSystemLoader(Path(__file__).parent) ) - template = env.get_template("Formula/snowcli.tmpl.rb") + template = env.get_template("Formula/snowflake-cli.tmpl.rb") packages = subprocess.check_output(["poet", "snowflake-cli-labs"], encoding="utf-8") sf_pattern = r'\s+resource \"snowflake-cli-labs\" do\s+url \"(.+)\"\s+sha256 \"(\w+)\"\s+end\n' @@ -21,7 +21,7 @@ def main(): version = subprocess.check_output(["snow", "--version"], encoding="utf-8").split()[-1] - with open("Formula/snowcli.rb", "w+") as fh: + with open("Formula/snowflake-cli.rb", "w+") as fh: fh.write(template.render( sf_url=sf_url, sf_sha=sf_sha,