Skip to content

Commit

Permalink
- add hagrid quickstart art
Browse files Browse the repository at this point in the history
- add animation to track package installation in quickstart
- improve UX for quickstart setup
  • Loading branch information
shubham3121 committed Sep 21, 2022
1 parent 79a5ea8 commit 921b8f5
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 41 deletions.
15 changes: 15 additions & 0 deletions packages/hagrid/hagrid/art.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# third party
import ascii_magic
import rich

# relative
from .lib import asset_path
Expand Down Expand Up @@ -109,6 +110,20 @@ def hagrid2() -> None:
pass


def quickstart_art() -> None:
console = rich.get_console()
console.print(
"""
▒█░▒█ ░█▀▀█ ▒█▀▀█ █▀▀█ ░▀░ █▀▀▄   ▒█▀▀█ █░░█ ░▀░ █▀▀ █░█ █▀▀ ▀▀█▀▀ █▀▀█ █▀▀█ ▀▀█▀▀
▒█▀▀█ ▒█▄▄█ ▒█░▄▄ █▄▄▀ ▀█▀ █░░█   ▒█░▒█ █░░█ ▀█▀ █░░ █▀▄ ▀▀█ ░░█░░ █▄▄█ █▄▄▀ ░░█░░
▒█░▒█ ▒█░▒█ ▒█▄▄█ ▀░▀▀ ▀▀▀ ▀▀▀░   ░▀▀█▄ ░▀▀▀ ▀▀▀ ▀▀▀ ▀░▀ ▀▀▀ ░░▀░░ ▀░░▀ ▀░▀▀ ░░▀░░
""",
style="bold",
justify="center",
new_line_start=True,
)


def hagrid() -> None:
"""Print a random hagrid image with the caption "hold on tight harry" """
options = [motorcycle, hagrid1, hagrid2]
Expand Down
106 changes: 66 additions & 40 deletions packages/hagrid/hagrid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

# relative
from .art import hagrid
from .art import quickstart_art
from .auth import AuthCredentials
from .cache import DEFAULT_BRANCH
from .cache import DEFAULT_REPO
Expand Down Expand Up @@ -2570,6 +2571,7 @@ def run_quickstart(
python: Optional[str] = None,
) -> None:
try:
quickstart_art()
directory = os.path.expanduser("~/.hagrid/quickstart/")
confirm_reset = None
if reset:
Expand Down Expand Up @@ -2782,7 +2784,7 @@ def display_jupyter_url(url_parts: Tuple[str, str, int]) -> None:
console = rich.get_console()

console.print(
f"[bold white]Jupyter Server is running at:\n:link: [bold blue]{url}\n"
f"[bold white]:white_heavy_check_mark: Jupyter Server is running at:\n:link: [bold blue]{url}\n"
+ "[bold white]Use Control-C to stop this server and shut down all kernels.",
new_line_start=True,
)
Expand Down Expand Up @@ -2821,49 +2823,73 @@ def quickstart_setup(
pre: bool = False,
python: Optional[str] = None,
) -> None:
try:
os.makedirs(directory, exist_ok=True)
virtual_env_dir = os.path.abspath(directory + ".venv/")
if reset and os.path.exists(virtual_env_dir):
shutil.rmtree(virtual_env_dir)
env = VirtualEnvironment(virtual_env_dir, python=python)

# upgrade pip
env.install("pip", options=["-U"])
env.install("packaging", options=["-U"])
console = rich.get_console()

print("Installing Jupyter Labs")
env.install("jupyterlab")
env.install("ipywidgets")
try:
with console.status(
"[bold blue]Setting up Quickstart Environment :evergreen_tree:"
) as console_status:
os.makedirs(directory, exist_ok=True)
virtual_env_dir = os.path.abspath(directory + ".venv/")
if reset and os.path.exists(virtual_env_dir):
shutil.rmtree(virtual_env_dir)
env = VirtualEnvironment(virtual_env_dir, python=python)
console.print(
":white_heavy_check_mark: Created Virtual Environment :evergreen_tree:"
)

if EDITABLE_MODE:
# local_syft_dir = Path(os.path.abspath(Path(hagrid_root()) / "../syft"))
# print("Installing Syft in Editable Mode")
# env.install("-e " + str(local_syft_dir))
local_hagrid_dir = Path(os.path.abspath(Path(hagrid_root()) / "../hagrid"))
print("Installing HAGrid in Editable Mode", str(local_hagrid_dir))
env.install("-e " + str(local_hagrid_dir))
else:
# options = []
# options.append("--force")
# if syft_version == "latest":
# syft_version = LATEST_STABLE_SYFT
# package = f"syft>={syft_version}"
# if pre:
# package = f"{package}.dev0" # force pre release
# else:
# package = f"syft=={syft_version}"

# if pre:
# options.append("--pre")
# print(f"Installing {package} --pre")
# else:
# print(f"Installing {package}")
# env.install(package, options=options)
print("Installing hagrid")
env.install("hagrid", options=["-U"])
# upgrade pip
console_status.update("[bold blue]Installing pip :fish:")
env.install("pip", options=["-U"])
console.print(":white_heavy_check_mark: pip")

# upgrade packaging
console_status.update("[bold blue] Installing packaging")
env.install("packaging", options=["-U"])
console.print(":white_heavy_check_mark: packaging")

console_status.update("[bold blue]Installing Jupyter Labs")
env.install("jupyterlab")
env.install("ipywidgets")
console.print(":white_heavy_check_mark: Jupyter Labs")

if EDITABLE_MODE:
# local_syft_dir = Path(os.path.abspath(Path(hagrid_root()) / "../syft"))
# print("Installing Syft in Editable Mode")
# env.install("-e " + str(local_syft_dir))
local_hagrid_dir = Path(
os.path.abspath(Path(hagrid_root()) / "../hagrid")
)
console_status.update(
f"[bold blue]Installing HAGrid in Editable Mode: {str(local_hagrid_dir)}"
)
env.install("-e " + str(local_hagrid_dir))
console.print(
f":white_heavy_check_mark: HAGrid in Editable Mode: {str(local_hagrid_dir)}"
)
else:
# options = []
# options.append("--force")
# if syft_version == "latest":
# syft_version = LATEST_STABLE_SYFT
# package = f"syft>={syft_version}"
# if pre:
# package = f"{package}.dev0" # force pre release
# else:
# package = f"syft=={syft_version}"

# if pre:
# options.append("--pre")
# print(f"Installing {package} --pre")
# else:
# print(f"Installing {package}")
# env.install(package, options=options)
console_status.update("[bold blue]Installing hagrid :hagrid:")
env.install("hagrid", options=["-U"])
console.print(":white_heavy_check_mark: HAGrid")
except Exception as e:
print("failed", e)
console.print_exception(word_wrap=True)
raise e


Expand Down
3 changes: 2 additions & 1 deletion packages/hagrid/hagrid/quickstart_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# third party
import click
import requests
from tqdm import tqdm

# relative
from .cache import DEFAULT_BRANCH
Expand Down Expand Up @@ -96,7 +97,7 @@ def fetch_notebooks_for_url(
print(nb)

overwrite_all = False
for notebook_url in notebooks:
for notebook_url in tqdm(notebooks):
file_path, _, overwrite_all = quickstart_download_notebook(
url=notebook_url,
directory=directory + os.sep + url_dir + os.sep,
Expand Down

0 comments on commit 921b8f5

Please sign in to comment.