Skip to content

Commit

Permalink
add path command and function
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgard Marx committed Apr 10, 2024
1 parent 09c3bb9 commit 455f279
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
14 changes: 14 additions & 0 deletions imr/imr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def rm(self, package: str, version: str = "latest") -> None:
if path.exists():
path.unlink()

def path(self, package: str, version: str = "latest") -> Path:
"""Return the path to the model."""
artefact = self.repo + "/" + package
if version is not None:
artefact += "/" + version
return ArtifactoryPath(artefact, auth=(self.user, self.password), auth_type=HTTPBasicAuth)


class IMRLocal:
"""Local repository class."""
Expand Down Expand Up @@ -92,3 +99,10 @@ def rm(self, package: str, version: str = "latest") -> None:
shutil.rmtree(self.repo / package)
else:
shutil.rmtree(self.repo / package / version)

def path(self, package: str, version: str = "latest") -> Path:
"""Return the path to the model."""
path = self.repo / package
if version is not None:
path = self.repo / package / version
return path
39 changes: 25 additions & 14 deletions imr/imr_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,43 @@ class Context:
imr_local: IMRLocal = IMRLocal(str(imr_dir))
imr_remote: IMRRemote


@click.group()
@click.pass_context
def cli(ctx: click.Context) -> None:
"""Get the cli command options."""
ctx.obj = Context()
# add loadParams() later


@cli.group()
def local() -> None:
"""Get local command options."""


@local.command("list")
@click.pass_obj
def list_local(obj: Context) -> None:
"""List local packages."""
for package in obj.imr_local.list():
click.echo(package)


@local.command()
@local.command("rm")
@click.argument("package")
@click.option(
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
@click.pass_obj
def remove(obj: Context, package: str, version: str) -> None:
def rm_local(obj: Context, package: str, version: str) -> None:
"""Remove local packages."""
obj.imr_local.rm(package, version)

@local.command("path")
@click.argument("package")
@click.option(
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
@click.pass_obj
def path_local(obj: Context, package: str, version: str) -> None:
"""Get remote model path."""
click.echo(obj.imr_local.path(package, version))

@cli.group()
@click.argument("host")
Expand All @@ -60,7 +65,6 @@ def remote(obj: Context, host: str, user: str, password: str) -> None:
"""Get remote command cli options."""
obj.imr_remote = IMRRemote(host, user, password)


@remote.command("list")
@click.pass_obj
def list_remote(obj: Context) -> None:
Expand All @@ -69,30 +73,27 @@ def list_remote(obj: Context) -> None:
for p in packages:
click.echo(p)


@remote.command()
@remote.command("rm")
@click.argument("package")
@click.option(
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
@click.pass_obj
def rm(obj: Context, package: str, version: str) -> None:
def rm_remote(obj: Context, package: str, version: str) -> None:
"""Remove remote package."""
obj.imr_remote.rm(package, version)


@remote.command()
@remote.command("push")
@click.argument("model_dir")
@click.argument("package")
@click.option(
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
@click.pass_obj
def push(obj: Context, model_dir: str, package: str, version: str) -> None:
def push_remote(obj: Context, model_dir: str, package: str, version: str) -> None:
"""Push model to remote repository."""
obj.imr_remote.push(model_dir, package, version)


@remote.command()
@click.argument("package")
@click.option(
Expand All @@ -109,3 +110,13 @@ def push(obj: Context, model_dir: str, package: str, version: str) -> None:
def pull(obj: Context, package: str, model_dir: str, version: str) -> None:
"""Pull model from remote repository."""
obj.imr_remote.pull(model_dir, package, version)

@remote.command("path")
@click.argument("package")
@click.option(
"-v", "--version", type=str, default="latest", help="version of the model.", show_default=True
)
@click.pass_obj
def path_remote(obj: Context, package: str, version: str) -> None:
"""Get remote model path."""
click.echo(obj.imr_remote.path(package, version))

0 comments on commit 455f279

Please sign in to comment.