cli autocomplete and defered imports

This commit is contained in:
Dominik Moritz Roth 2023-01-17 23:18:26 +01:00
parent 2f2da60626
commit 4580f67920
2 changed files with 36 additions and 12 deletions

View File

@ -1,21 +1,33 @@
#!./.venv/bin/python3.10
import os
import re
import json
import math
import copy
import random
import argcomplete, pyzshcomplete
# Enable autocomplete in global completion mode for bash & zsh:
# PYTHON_ARGCOMPLETE_OK
# PYZSHCOMPLETE_OK
# performance hack; only load these after validating cmd args
def defered_imports():
global re, requests
import re
import requests
global np, pd, norm
import numpy as np
import pandas as pd
from scipy.stats import norm
global plt, nx, Network, go
import matplotlib.pyplot as plt
import networkx as nx
from pyvis.network import Network
import plotly.graph_objects as go
global wikipedia
import wikipedia
@ -771,7 +783,6 @@ def graphAddTopLists(G, books, darkMode=False):
book, top), color=readColor(book))
return G
def graphAddSeries(G, books, darkMode=False):
for series in getAllSeries(books):
G.add_node('s/'+series, color='red', t='series',
@ -1536,6 +1547,7 @@ def loadWeights():
def cliInterface(imgDef=False):
import argparse
import argcomplete
parser = argparse.ArgumentParser(description='TODO: Write Description.')
parser.add_argument('--keep-priv', action="store_true")
@ -1615,6 +1627,8 @@ def cliInterface(imgDef=False):
p_full = cmds.add_parser('full', description="TODO", aliases=[])
pyzshcomplete.autocomplete(parser)
argcomplete.autocomplete(parser)
args = parser.parse_args()
if imgDef:
@ -1642,6 +1656,10 @@ def perfTestCLI(args):
def mainCLI(args):
global weights
defered_imports()
weights = loadWeights()
if args.cmd == "train":
train(args.g, args.full)
exit()
@ -1738,9 +1756,13 @@ def mainCLI(args):
genAndShowHTML(G, darkMode=args.dark)
weights = loadWeights()
#weights = loadWeights()
weights = None
if __name__ == "__main__":
try:
cliInterface(imgDef=True)
except Error as e:
print("[!] {0}".format(e))
else:
weights = loadWeights()
defered_imports()

View File

@ -10,3 +10,5 @@ requests
pandas
plotly
wikipedia
argcomplete
pyzshcomplete