Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions deploifai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

from .auth.login import login
from .auth.logout import logout
from .project import project


@click.group()
commands = {"login": login, "logout": logout, "project": project}


@click.group(commands=commands)
@click.version_option(package_name="deploifai-cli", message="%(prog)s %(version)s")
@pass_deploifai_context_obj
@click.option("--debug", is_flag=True, help="Show debug logs")
Expand All @@ -16,19 +20,18 @@
default="info",
help="Set debugging level",
)
def cli_group(deploifai: DeploifaiContextObj, debug: bool, debug_level):
def cli(deploifai: DeploifaiContextObj, debug: bool, debug_level):
"""
Deploifai CLI
"""
deploifai.debug = debug
deploifai.debug_level = debug_level
deploifai.read_config()


cli_group.add_command(login)
cli_group.add_command(logout)


def cli():
cli_group(auto_envvar_prefix="DEPLOIFAI")
def main():
cli(auto_envvar_prefix="DEPLOIFAI")


if __name__ == "__main__":
cli()
main()
13 changes: 13 additions & 0 deletions deploifai/project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import click

from .init import init


@click.group()
def project():
"""
Initialise, manage, and deploy an ML project
"""


project.add_command(init)
43 changes: 43 additions & 0 deletions deploifai/project/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import io
import zipfile
import click
import requests

from ..context_obj import pass_deploifai_context_obj, DeploifaiContextObj


@click.command()
@pass_deploifai_context_obj
@click.argument("name")
def init(deploifai: DeploifaiContextObj, name: str):
'''
Initialise a new project called NAME
'''
url = "https://api.github.com/repos/deploifai/basic-starter-template/zipball/main"
r = requests.get(url)

with zipfile.ZipFile(io.BytesIO(r.content)) as zip_ref:
# create a new project directory
directory = os.path.join(os.getcwd(), name)
if not os.path.isdir(directory):
try:
os.makedirs(directory)
deploifai.debug_msg("Created new project directory")
except OSError:
deploifai.debug_msg("Error creating project directory", level="error")
return

deploifai.debug_msg(f"Zip file namelist: {zip_ref.namelist()}")

files_list = zip_ref.namelist()[1:]

for file in files_list:
filepath = directory + "/" + "/".join(file.split("/")[1:])
deploifai.debug_msg(f"Write to {filepath}")
with open(filepath, "wb") as new_file:
new_file.write(zip_ref.read(file))

deploifai.debug_msg(f"Extracted zip file contents to {directory}")

click.echo(f"Created a new project called {name}")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="deploifai-cli",
version="0.0.4",
version="0.0.5",
author="Deploifai Limited",
description="Deploifai CLI",
long_description=long_description,
Expand Down