Spaces:
Runtime error
Runtime error
format
Browse files- .env.example +2 -1
- app.py +9 -5
- utils.py +10 -0
.env.example
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
USER=
|
2 |
-
PERSONAL_ACCESS_TOKEN=
|
|
|
|
1 |
USER=
|
2 |
+
PERSONAL_ACCESS_TOKEN=
|
3 |
+
DEV=
|
app.py
CHANGED
@@ -1,8 +1,12 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import streamlit.components.v1 as components
|
3 |
|
4 |
from py_code_analyzer import CodeFetcher, CodeImportsAnalyzer, ImportsGraphVisualizer
|
5 |
-
from utils import time_function
|
|
|
|
|
6 |
|
7 |
TITLE = "Python Code Analyzer"
|
8 |
st.set_page_config(page_title=TITLE, layout="wide")
|
@@ -27,22 +31,22 @@ clicked_ok_button = st.button("OK")
|
|
27 |
st.markdown("---")
|
28 |
|
29 |
|
30 |
-
@time_function
|
31 |
def get_python_files(owner, repo, path, ref=""):
|
32 |
return CodeFetcher().get_python_files(owner, repo, path, ref=ref)
|
33 |
|
34 |
|
35 |
-
@time_function
|
36 |
def generate_imports_graph(python_files):
|
37 |
return CodeImportsAnalyzer(python_files).analyze().generate_imports_graph()
|
38 |
|
39 |
|
40 |
-
@time_function
|
41 |
def generate_graph_visualization_file(imports_graph):
|
42 |
ImportsGraphVisualizer().visualize(imports_graph)
|
43 |
|
44 |
|
45 |
-
@time_function
|
46 |
def read_graph_visualization_file():
|
47 |
return open("nx.html", "r", encoding="utf-8").read()
|
48 |
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
import streamlit as st
|
4 |
import streamlit.components.v1 as components
|
5 |
|
6 |
from py_code_analyzer import CodeFetcher, CodeImportsAnalyzer, ImportsGraphVisualizer
|
7 |
+
from utils import conditonal_decorator, time_function
|
8 |
+
|
9 |
+
DEV = int(os.environ.get("DEV", "1"))
|
10 |
|
11 |
TITLE = "Python Code Analyzer"
|
12 |
st.set_page_config(page_title=TITLE, layout="wide")
|
|
|
31 |
st.markdown("---")
|
32 |
|
33 |
|
34 |
+
@conditonal_decorator(time_function, DEV)
|
35 |
def get_python_files(owner, repo, path, ref=""):
|
36 |
return CodeFetcher().get_python_files(owner, repo, path, ref=ref)
|
37 |
|
38 |
|
39 |
+
@conditonal_decorator(time_function, DEV)
|
40 |
def generate_imports_graph(python_files):
|
41 |
return CodeImportsAnalyzer(python_files).analyze().generate_imports_graph()
|
42 |
|
43 |
|
44 |
+
@conditonal_decorator(time_function, DEV)
|
45 |
def generate_graph_visualization_file(imports_graph):
|
46 |
ImportsGraphVisualizer().visualize(imports_graph)
|
47 |
|
48 |
|
49 |
+
@conditonal_decorator(time_function, DEV)
|
50 |
def read_graph_visualization_file():
|
51 |
return open("nx.html", "r", encoding="utf-8").read()
|
52 |
|
utils.py
CHANGED
@@ -1,6 +1,16 @@
|
|
1 |
import time
|
2 |
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def time_function(f):
|
5 |
def wrapper(*args, **kwargs):
|
6 |
begin = time.time()
|
|
|
1 |
import time
|
2 |
|
3 |
|
4 |
+
def conditonal_decorator(dec, condition):
|
5 |
+
def decorator(func):
|
6 |
+
if not condition:
|
7 |
+
return func
|
8 |
+
|
9 |
+
return dec(func)
|
10 |
+
|
11 |
+
return decorator
|
12 |
+
|
13 |
+
|
14 |
def time_function(f):
|
15 |
def wrapper(*args, **kwargs):
|
16 |
begin = time.time()
|