Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: install vyper CLI using CLI #146

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions ape_vyper/_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sys
from pathlib import Path

import ape
import click
from ape.cli.options import ape_cli_context, project_option
from vvm import get_installed_vyper_versions, get_vvm_install_folder, install_vyper # type: ignore


@click.group
Expand All @@ -26,3 +28,41 @@ def flatten(cli_ctx, project, contract: Path, outfile: Path):
project=project,
)
fout.write(str(content))


@cli.group
def vvm():
"""`vvm` command group"""


@vvm.command("list", short_help="List vyper installed versions")
def _list():
versions = get_installed_vyper_versions()
if len(versions) > 10:
click.echo_via_pager(versions)
else:
for version in get_installed_vyper_versions():
click.echo(version)


@vvm.command(short_help="Install vyper")
@click.argument("versions", nargs=-1)
@click.option("--vvm-binary-path", help="The path to Vyper binaries")
@click.option("--hide-progress", is_flag=True)
def install(versions, vvm_binary_path, hide_progress):
"""
Install Vyper
"""
if versions:
for version in versions:
base_path = get_vvm_install_folder(vvm_binary_path=vvm_binary_path)
if (base_path / f"vyper-{version}").exists():
click.echo(f"Vyper version '{version}' already installed.")
continue

click.echo(f"Installing Vyper '{version}'.")
install_vyper(version, show_progress=not hide_progress, vvm_binary_path=vvm_binary_path)

else:
click.echo("No version given.", err=True)
sys.exit(1)
10 changes: 10 additions & 0 deletions tests/functional/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ def test_compile():
output = completed_process.stdout.decode(encoding="utf8")
assert "SUCCESS" in output
assert "zero_four_in_subdir.vy" in output


def test_vvm_list(cli_runner):
result = cli_runner.invoke(cli, ["vvm", "list"])
assert result.exit_code == 0


def test_vvm_install(cli_runner):
result = cli_runner.invoke(cli, ["vvm", "install", "0.4.0"])
assert result.exit_code == 0
Loading