cli autocomplete and defered imports
This commit is contained in:
parent
2f2da60626
commit
4580f67920
46
caliGraph.py
46
caliGraph.py
@ -1,22 +1,34 @@
|
|||||||
#!./.venv/bin/python3.10
|
#!./.venv/bin/python3.10
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import copy
|
import copy
|
||||||
import random
|
import random
|
||||||
import requests
|
|
||||||
|
|
||||||
import numpy as np
|
import argcomplete, pyzshcomplete
|
||||||
import pandas as pd
|
# Enable autocomplete in global completion mode for bash & zsh:
|
||||||
from scipy.stats import norm
|
# PYTHON_ARGCOMPLETE_OK
|
||||||
|
# PYZSHCOMPLETE_OK
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
# performance hack; only load these after validating cmd args
|
||||||
import networkx as nx
|
def defered_imports():
|
||||||
from pyvis.network import Network
|
global re, requests
|
||||||
import plotly.graph_objects as go
|
import re
|
||||||
|
import requests
|
||||||
|
|
||||||
import wikipedia
|
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
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
@ -771,7 +783,6 @@ def graphAddTopLists(G, books, darkMode=False):
|
|||||||
book, top), color=readColor(book))
|
book, top), color=readColor(book))
|
||||||
return G
|
return G
|
||||||
|
|
||||||
|
|
||||||
def graphAddSeries(G, books, darkMode=False):
|
def graphAddSeries(G, books, darkMode=False):
|
||||||
for series in getAllSeries(books):
|
for series in getAllSeries(books):
|
||||||
G.add_node('s/'+series, color='red', t='series',
|
G.add_node('s/'+series, color='red', t='series',
|
||||||
@ -1536,6 +1547,7 @@ def loadWeights():
|
|||||||
|
|
||||||
def cliInterface(imgDef=False):
|
def cliInterface(imgDef=False):
|
||||||
import argparse
|
import argparse
|
||||||
|
import argcomplete
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='TODO: Write Description.')
|
parser = argparse.ArgumentParser(description='TODO: Write Description.')
|
||||||
parser.add_argument('--keep-priv', action="store_true")
|
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=[])
|
p_full = cmds.add_parser('full', description="TODO", aliases=[])
|
||||||
|
|
||||||
|
pyzshcomplete.autocomplete(parser)
|
||||||
|
argcomplete.autocomplete(parser)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if imgDef:
|
if imgDef:
|
||||||
@ -1642,6 +1656,10 @@ def perfTestCLI(args):
|
|||||||
|
|
||||||
|
|
||||||
def mainCLI(args):
|
def mainCLI(args):
|
||||||
|
global weights
|
||||||
|
defered_imports()
|
||||||
|
weights = loadWeights()
|
||||||
|
|
||||||
if args.cmd == "train":
|
if args.cmd == "train":
|
||||||
train(args.g, args.full)
|
train(args.g, args.full)
|
||||||
exit()
|
exit()
|
||||||
@ -1738,9 +1756,13 @@ def mainCLI(args):
|
|||||||
genAndShowHTML(G, darkMode=args.dark)
|
genAndShowHTML(G, darkMode=args.dark)
|
||||||
|
|
||||||
|
|
||||||
weights = loadWeights()
|
#weights = loadWeights()
|
||||||
|
weights = None
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
cliInterface(imgDef=True)
|
cliInterface(imgDef=True)
|
||||||
except Error as e:
|
except Error as e:
|
||||||
print("[!] {0}".format(e))
|
print("[!] {0}".format(e))
|
||||||
|
else:
|
||||||
|
weights = loadWeights()
|
||||||
|
defered_imports()
|
||||||
|
@ -10,3 +10,5 @@ requests
|
|||||||
pandas
|
pandas
|
||||||
plotly
|
plotly
|
||||||
wikipedia
|
wikipedia
|
||||||
|
argcomplete
|
||||||
|
pyzshcomplete
|
||||||
|
Loading…
Reference in New Issue
Block a user