Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Xircuits Entry Handler for Components + Submodule Components Download #152

Merged
merged 9 commits into from
Apr 25, 2022
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ jinja2>=3.0.3
y-py>=0.3.0,<0.4.0
jupyterlab>=3.0.0,<4.0.0
requests
gitpython
pygithub
tqdm
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
entry_points ={
'console_scripts': [
'xircuits = xircuits.start_xircuits:main',
'xircuits-examples = xircuits.start_xircuits:download_examples'
'xircuits-examples = xircuits.start_xircuits:download_examples',
'xircuits-components = xircuits.start_xircuits:download_component_library'
]}
)

Expand Down
45 changes: 45 additions & 0 deletions xircuits/handlers/request_submodule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from tqdm import tqdm
import os
from urllib import request, parse
from github import Github
from git import Repo
import sys

def get_submodule_config(user_query):

import configparser
config = configparser.ConfigParser()

config.read('.xircuits/.gitmodules')

submodule_keys = [submodule for submodule in config.sections() if user_query in submodule]
if len(submodule_keys) == 0:
print(user_query + " component library submodule not found.")
return

if len(submodule_keys) > 1:
print("Multiple '" + user_query + "' found. Returning first instance.")

submodule_key = submodule_keys.pop(0)

submodule_path = config[submodule_key]["path"]
submodule_url = config[submodule_key]["url"]

return submodule_path, submodule_url


def request_submodule_library(component_library_query):

module_url = "https://raw.githubusercontent.com/XpressAI/xircuits/master/.gitmodules"
request.urlretrieve(module_url, ".xircuits/.gitmodules")

# ensure syntax is as xai_components/xai_library_name
if "xai" not in component_library_query:
component_library_query = "xai_" + component_library_query

if "xai_components" not in component_library_query:
component_library_query = "xai_components/" + component_library_query

submodule_path, submodule_url = get_submodule_config(component_library_query)
Repo.clone_from(submodule_url, submodule_path)

80 changes: 47 additions & 33 deletions xircuits/start_xircuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,71 @@
import argparse

from .handlers.request_folder import request_folder
from .handlers.request_submodule import request_submodule_library

def init_xircuits():

url = "https://raw.githubusercontent.com/XpressAI/xircuits/master/.xircuits/config.ini"
path = ".xircuits"
os.mkdir(path)
request.urlretrieve(url, path+"/config.ini")

def start_xircuits(branch_name):
print(
'''
======================================
__ __ ___ _ _
\ \ \ \/ (_)_ __ ___ _ _(_) |_ ___
\ \ \ /| | '__/ __| | | | | __/ __|
/ / / \| | | | (__| |_| | | |_\__ \\
/_/ /_/\_\_|_| \___|\__,_|_|\__|___/

======================================
'''
)

config_path = Path(os.getcwd()) / ".xircuits"
component_library_path = Path(os.getcwd()) / "xai_components"
def download_examples():

parser = argparse.ArgumentParser()
parser.add_argument('--branch', nargs='?', default="master", help='pull files from a xircuits branch')

if not config_path.exists():
init_xircuits()
args = parser.parse_args()

if not component_library_path.exists():
val = input("Xircuits Component Library is not found. Would you like to load it in the current path (Y/N)? ")
if val.lower() == ("y" or "yes"):
request_folder("xai_components", branch=branch_name)

os.system("jupyter lab")
request_folder("examples", branch=args.branch)
request_folder("datasets", branch=args.branch)


def download_examples():
def download_component_library():

parser = argparse.ArgumentParser()
parser.add_argument('--branch', nargs='?', help='pull files from a xircuits branch')
parser.add_argument('--branch', nargs='?', default="master", help='pull files from a xircuits branch')
parser.add_argument('--sublib', nargs='*', help='pull component library from a xircuits submodule')

args = parser.parse_args()
branch_name = args.branch if args.branch else "master"
if not args.sublib:
request_folder("xai_components", branch=args.branch)
else:
for component_lib in args.sublib:
request_submodule_library(component_lib)

request_folder("examples", branch=branch_name)
request_folder("datasets", branch=branch_name)


def main(argv=None):
def main():

parser = argparse.ArgumentParser()
parser.add_argument('--branch', nargs='?', help='pull files from a xircuits branch')
parser.add_argument('--branch', nargs='?', default="master", help='pull files from a xircuits branch')

args = parser.parse_args()
branch_name = args.branch if args.branch else "master"
branch_name = args.branch

component_library_path = Path(os.getcwd()) / "xai_components"

if not component_library_path.exists():
val = input("Xircuits Component Library is not found. Would you like to load it in the current path (Y/N)? ")
if val.lower() == ("y" or "yes"):
request_folder("xai_components", branch=branch_name)

os.system("jupyter lab")

print(
'''
======================================
__ __ ___ _ _
\ \ \ \/ (_)_ __ ___ _ _(_) |_ ___
\ \ \ /| | '__/ __| | | | | __/ __|
/ / / \| | | | (__| |_| | | |_\__ \\
/_/ /_/\_\_|_| \___|\__,_|_|\__|___/

======================================
'''
)

start_xircuits(branch_name)
config_path = Path(os.getcwd()) / ".xircuits"
if not config_path.exists():
init_xircuits()