From 2533140a66d32964c8d6f692d1d67c25e9611b49 Mon Sep 17 00:00:00 2001 From: Alejandro Cardenas Date: Tue, 17 May 2022 11:14:14 -0500 Subject: [PATCH] perf: remove setup command and set user home as TVM_PATH --- tests/test_cli.py | 3 ++- tvm/cli.py | 47 +++++++++++------------------------------------ 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 820baf9..5f96da7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,8 +14,9 @@ def test_should_return_all_tvm_cli_commands(): assert ' install ' in result.output assert ' uninstall ' in result.output assert ' list ' in result.output - assert ' setup ' in result.output assert ' use ' in result.output + assert ' pip ' in result.output + assert ' plugins ' in result.output def test_should_fail_if_format_version_is_not_valid(): diff --git a/tvm/cli.py b/tvm/cli.py index bc7383d..322bbcc 100644 --- a/tvm/cli.py +++ b/tvm/cli.py @@ -19,7 +19,7 @@ from tvm.templates.tutor_switcher import TUTOR_SWITCHER_TEMPLATE VERSIONS_URL = "https://api.github.com/repos/overhangio/tutor/tags" -TVM_PATH = pathlib.Path().resolve() / '.tvm' +TVM_PATH = pathlib.Path.home() / '.tvm' def main() -> None: @@ -96,6 +96,16 @@ def setup_tvm(): with open(info_file_path, 'w', encoding='utf-8') as info_file: json.dump(data, info_file, indent=4) + set_switch_from_file() + + tutor_switcher = f'{TVM_PATH}/tutor_switcher' + try: + os.symlink(tutor_switcher, '/usr/local/bin/tutor') + except PermissionError: + subprocess.call(['sudo', 'ln', '-s', tutor_switcher, '/usr/local/bin/tutor']) + except FileExistsError: + pass + @click.command(name="list") @click.option('-l', '--limit', default=10, help='number of `latest versions` to list') @@ -246,40 +256,6 @@ def set_switch_from_file() -> None: os.chmod(switcher_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH) -def install_venv() -> None: - """Make the switcher file available to the virtualenv path.""" - # link from the venv - venv_tutor = pathlib.Path(sys.executable).parent.joinpath('tutor').resolve() - try: - os.symlink(f'{TVM_PATH}/tutor_switcher', venv_tutor) - except FileExistsError: - pass - except PermissionError: - click.echo( - click.style('To set up tvm local is necessary that tvm had been installed in a virtualenv.', fg='red')) - else: - click.echo(click.style( - 'Re-activate your virtualenv for changes to take effect', fg='yellow')) - - -@click.command(name="setup") -@click.option('-g', '--global', 'make_global', is_flag=True, help='Make the tutor command available to the cli') -def install_global(make_global) -> None: - """Make the switcher file to anyone in the system.""" - setup_tvm() - set_switch_from_file() - - if not make_global: - install_venv() - else: - try: - os.symlink(f'{TVM_PATH}/tutor_switcher', '/usr/local/bin/tutor') - except PermissionError: - subprocess.call(['sudo', 'ln', '-s', f'{TVM_PATH}/tutor_switcher', '/usr/local/bin/tutor']) - except FileExistsError: - click.echo('There is already a file at: /usr/local/bin/tutor') - - @click.command(name="use") @click.argument('version', callback=validate_version_installed, type=TutorVersionType()) def use(version: str): @@ -363,7 +339,6 @@ def list_plugins(): cli.add_command(install) cli.add_command(uninstall) cli.add_command(use) -cli.add_command(install_global) cli.add_command(pip) cli.add_command(plugins) plugins.add_command(list_plugins)