Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
Move install-toolkit-pro to install-pro command
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Oct 14, 2024
1 parent eadd324 commit b951b8f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 62 deletions.
2 changes: 2 additions & 0 deletions labelme_toolkit/_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .. import __version__
from ._ai_annotate_rectangles import ai_annotate_rectangles
from ._extract_image import extract_image
from ._install_pro import install_pro
from ._install_toolkit_pro import install_toolkit_pro
from ._json_to_mask import json_to_mask
from ._json_to_visualization import json_to_visualization
Expand All @@ -23,6 +24,7 @@ def cli():

cli.add_command(ai_annotate_rectangles)
cli.add_command(extract_image)
cli.add_command(install_pro)
cli.add_command(install_toolkit_pro)
cli.add_command(json_to_mask)
cli.add_command(json_to_visualization)
Expand Down
91 changes: 91 additions & 0 deletions labelme_toolkit/_cli/_install_pro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import hashlib
import subprocess
import sys
import urllib.request
from typing import Optional

import click
from loguru import logger


@click.command()
@click.option(
"--access-key",
help="access key to install",
)
@click.option(
"--version",
default="latest",
help="version to install",
)
@click.option(
"--yes",
is_flag=True,
help="install without confirmation",
)
@click.option(
"--list-versions",
is_flag=True,
help="list available versions",
)
def install_pro(
access_key: Optional[str], version: str, yes: bool, list_versions: bool
):
"""Install Toolkit Pro.
Examples:
\b
$ labelmetk install-pro # install latest
$ labelmetk install-pro --version 1.0.0
$ labelmetk install-pro --access-key xxxxxxxx
"""
logger.info("Installing labelme-toolkit-pro...")

url_path = "https://labelme.io/pro/install"

with urllib.request.urlopen(f"{url_path}/versions") as response:
data = response.read()
versions = [version.strip() for version in data.decode("utf-8").splitlines()]

if list_versions:
for i, version in enumerate(versions):
click.echo(version)
return

logger.info(f"Available versions: {versions}")

if version == "latest":
version = versions[-1]
logger.info(f"Installing version: {version} (latest)")
elif version not in versions:
logger.error(f"Version {version} is not available")
return
else:
logger.info(f"Installing version: {version}")

if access_key is None:
access_key = click.prompt("Enter access key")

access_token: str = hashlib.sha256(access_key.encode()).hexdigest().upper()

cmd = [
sys.executable,
"-m",
"pip",
"install",
f"{url_path}/files/labelme_toolkit_pro-{version}-py3-none-any.whl?token={access_token}",
]
logger.info("Running command: {}", " ".join(cmd))

if not yes:
if not click.confirm("Do you want to install?"):
click.echo("Installation is canceled.")
return

try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
logger.error("Failed to install. Is the access key correct?")
return
65 changes: 3 additions & 62 deletions labelme_toolkit/_cli/_install_toolkit_pro.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import hashlib
import subprocess
import sys
import urllib.request
from typing import Optional

import click
Expand Down Expand Up @@ -31,61 +27,6 @@
def install_toolkit_pro(
access_key: Optional[str], version: str, yes: bool, list_versions: bool
):
"""Install Toolkit Pro.
Examples:
\b
$ labelmetk install-toolkit-pro # install latest
$ labelmetk install-toolkit-pro --version 1.0.0
$ labelmetk install-toolkit-pro --access-key xxxxxxxx
"""
logger.info("Installing the Labelme Toolkit Pro...")

url_path = "https://labelme.io/pro/install"

with urllib.request.urlopen(f"{url_path}/versions") as response:
data = response.read()
versions = [version.strip() for version in data.decode("utf-8").splitlines()]

if list_versions:
for i, version in enumerate(versions):
click.echo(version)
return

logger.info(f"Available versions: {versions}")

if version == "latest":
version = versions[-1]
logger.info(f"Installing version: {version} (latest)")
elif version not in versions:
logger.error(f"Version {version} is not available")
return
else:
logger.info(f"Installing version: {version}")

if access_key is None:
access_key = click.prompt("Enter access key")

access_token: str = hashlib.sha256(access_key.encode()).hexdigest().upper()

cmd = [
sys.executable,
"-m",
"pip",
"install",
f"{url_path}/files/labelme_toolkit_pro-{version}-py3-none-any.whl?token={access_token}",
]
logger.info("Running command: {}", " ".join(cmd))

if not yes:
if not click.confirm("Do you want to install?"):
click.echo("Installation is canceled.")
return

try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
logger.error("Failed to install. Is the access key correct?")
return
"""DEPRECATED: Use `labelmetk install-pro` instead."""
logger.error("Deprecated command, please use `labelmetk install-pro` instead.")
return 1

0 comments on commit b951b8f

Please sign in to comment.