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 diff --git a/tvm/cli.py b/tvm/cli.py index 1f9a239..6b97a27 100644 --- a/tvm/cli.py +++ b/tvm/cli.py @@ -157,9 +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): +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) @@ -175,6 +173,13 @@ def install(version: str): 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") @click.argument('version', required=True) def uninstall(version: str): @@ -261,9 +266,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): +def use_version(version: str) -> None: """Configure the path to use VERSION.""" enabler = TutorVersionEnabler(repository=version_manager) try: @@ -277,6 +280,13 @@ def use(version: str): 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.""" return f'{TVM_PATH}/{version}/venv' @@ -361,11 +371,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: + install_tutor_version(version=version) + use_version(version=version) if name: tvm_project_folder = pathlib.Path().resolve() / name @@ -478,7 +495,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)