Skip to content

Commit

Permalink
Merge pull request #51 from eduNEXT/dsg/new-project-command
Browse files Browse the repository at this point in the history
DS-220 Tener un comando para dar start a un nuevo proyecto
  • Loading branch information
danielsgz committed Sep 22, 2022
2 parents 83ca5a8 + c2b9545 commit 3482404
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tvm install v<tutor-version>
2. Create a new project with tutor environment manager

```bash
tvm project <project-name> v<tutor-version>
tvm project init <project-name> v<tutor-version>
```

3. Open the project folder
Expand Down
36 changes: 26 additions & 10 deletions tvm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3482404

Please sign in to comment.