From 01366993b88434ed36565bb02464b23e45e8c265 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Thu, 22 Sep 2022 09:00:47 -0500 Subject: [PATCH 1/4] feat: init command creates new project with global tvm or latest tvm if machine lacks of one Signed-off-by: Daniel Sanchez --- tvm/cli.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tvm/cli.py b/tvm/cli.py index 1f9a239..7e708e0 100644 --- a/tvm/cli.py +++ b/tvm/cli.py @@ -361,11 +361,18 @@ def projects() -> None: @click.argument('version', required=False) def init(name: str = None, version: str = None): """Configure a new tvm project in the current path.""" + current_version = version_manager.current_version(f"{TVM_PATH}") + if not version: - version = get_active_version() + version = current_version + + if not current_version and not version: + lister = TutorVersionLister(repository=version_manager) + version = lister(limit=1)[0] - if not version_is_installed(version): - raise click.UsageError(f'Could not find target: {version}') + if not current_version: + subprocess.run(f"tvm install {version}", shell=True, check=True) + subprocess.run(f"tvm use {version}", shell=True, check=True) if name: tvm_project_folder = pathlib.Path().resolve() / name From 8d204d175c572cd5183362022017dbec9882eccd Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Tue, 20 Sep 2022 09:55:39 -0500 Subject: [PATCH 2/4] refactor: fixed logic style Signed-off-by: Daniel Sanchez --- tvm/cli.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/tvm/cli.py b/tvm/cli.py index 7e708e0..ca18fde 100644 --- a/tvm/cli.py +++ b/tvm/cli.py @@ -157,10 +157,7 @@ def list_versions(limit: int): click.echo(click.style(name, fg=color)) -@click.command(name="install") -@click.argument('version', required=True) -def install(version: str): - """Install the given VERSION of tutor in the .tvm directory.""" +def install_tutor_version(version: str) -> None: finder = TutorVersionFinder(repository=version_manager) tutor_version = finder(version=version) try: @@ -173,6 +170,13 @@ def install(version: str): installer = TutorVersionInstaller(repository=version_manager) installer(version=tutor_version) + + +@click.command(name="install") +@click.argument('version', required=True) +def install(version: str): + """Install the given VERSION of tutor in the .tvm directory.""" + install_tutor_version(version=version) @click.command(name="uninstall") @@ -261,10 +265,7 @@ def set_switch_from_file(file: str = None) -> None: os.chmod(switcher_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH) -@click.command(name="use") -@click.argument('version', required=True) -def use(version: str): - """Configure the path to use VERSION.""" +def use_version(version: str) -> None: enabler = TutorVersionEnabler(repository=version_manager) try: if not version_manager.version_is_installed(version=version): @@ -276,6 +277,12 @@ def use(version: str): raise click.ClickException(f'The version {version} is not installed you should install it before using it.\n' f'You could run the command `tvm install {version}` to install it.') from exc +@click.command(name="use") +@click.argument('version', required=True) +def use(version: str): + """Configure the path to use VERSION.""" + use_version(version=version) + def get_env_by_tutor_version(version): """Get virtual environment by tutor version.""" @@ -371,8 +378,8 @@ def init(name: str = None, version: str = None): version = lister(limit=1)[0] if not current_version: - subprocess.run(f"tvm install {version}", shell=True, check=True) - subprocess.run(f"tvm use {version}", shell=True, check=True) + install_tutor_version(version=version) + use_version(version=version) if name: tvm_project_folder = pathlib.Path().resolve() / name @@ -485,7 +492,6 @@ def clear(): cli.add_command(projects) projects.add_command(init) cli.add_command(plugins) -plugins.add_command(list_plugins) plugins.add_command(install_plugin) plugins.add_command(uninstall_plugin) cli.add_command(config) From 5f14fe61e5183bfc77ea5e266bcb5aadd5a734e6 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Tue, 20 Sep 2022 10:06:56 -0500 Subject: [PATCH 3/4] style: solve styling issues Signed-off-by: Daniel Sanchez --- tvm/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tvm/cli.py b/tvm/cli.py index ca18fde..6b97a27 100644 --- a/tvm/cli.py +++ b/tvm/cli.py @@ -158,6 +158,7 @@ def list_versions(limit: int): def install_tutor_version(version: str) -> None: + """Install the given VERSION of tutor in the .tvm directory.""" finder = TutorVersionFinder(repository=version_manager) tutor_version = finder(version=version) try: @@ -170,7 +171,7 @@ def install_tutor_version(version: str) -> None: installer = TutorVersionInstaller(repository=version_manager) installer(version=tutor_version) - + @click.command(name="install") @click.argument('version', required=True) @@ -266,6 +267,7 @@ def set_switch_from_file(file: str = None) -> None: def use_version(version: str) -> None: + """Configure the path to use VERSION.""" enabler = TutorVersionEnabler(repository=version_manager) try: if not version_manager.version_is_installed(version=version): @@ -277,6 +279,7 @@ def use_version(version: str) -> None: raise click.ClickException(f'The version {version} is not installed you should install it before using it.\n' f'You could run the command `tvm install {version}` to install it.') from exc + @click.command(name="use") @click.argument('version', required=True) def use(version: str): From c2b9545ac144b3c65d62a4c8eed06717b93cab38 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Thu, 22 Sep 2022 07:49:08 -0500 Subject: [PATCH 4/4] docs: correct quickstart command tvm project init Signed-off-by: Daniel Sanchez --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64939f7..b95a86d 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ tvm install v 2. Create a new project with tutor environment manager ```bash -tvm project v +tvm project init v ``` 3. Open the project folder