-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init
- Loading branch information
Showing
11 changed files
with
308 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,49 @@ | ||
# PyDepGraph | ||
|
||
#### Description | ||
# PyDepGraph | ||
|
||
#### Description | ||
|
||
PyDepGraph-Python项目依赖树可视化工具 | ||
|
||
PyDepGraph is a utility for displaying the installed python packages in form of a dependency tree. | ||
|
||
|
||
#### Software Architecture | ||
Software architecture description | ||
|
||
#### Installation | ||
|
||
1. xxxx | ||
2. xxxx | ||
3. xxxx | ||
|
||
#### Instructions | ||
|
||
1. xxxx | ||
2. xxxx | ||
3. xxxx | ||
|
||
#### Contribution | ||
|
||
1. Fork the repository | ||
2. Create Feat_xxx branch | ||
3. Commit your code | ||
4. Create Pull Request | ||
|
||
|
||
#### Gitee Feature | ||
|
||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md | ||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com) | ||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) | ||
4. The most valuable open source project [GVP](https://gitee.com/gvp) | ||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) | ||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) | ||
|
||
![pic](picture/pic1.png) | ||
|
||
#### Software Architecture | ||
|
||
Software architecture description | ||
|
||
- **Pipdeptree** Python项目依赖数据获取 | ||
- **Streamlit** Web应用程序框架 | ||
- **Echarts** Graph可视化 | ||
|
||
#### Installation | ||
|
||
1. $ git clone https://gitee.com/vencen/py-dep-graph.git | ||
|
||
#### Instructions | ||
|
||
1. $ cd py-dep-graph | ||
2. $ streamlit run app.py | ||
|
||
##### Uploading the Local Dependency Graph | ||
|
||
**shows the local python packages** | ||
|
||
1. $ pip install pipdeptree | ||
2. $ pipdeptree --json > pkg.json | ||
|
||
**shows a particular package** | ||
|
||
3. $ pipdeptree --json -p xxxpkg > xxxpkg.json | ||
|
||
**shows a particular package is installed** | ||
|
||
4. $ pipdeptree --json -p xxxpkg -r > xxxpkg.json | ||
|
||
#### Contribution | ||
|
||
1. Fork the repository | ||
2. Create Feat_xxx branch | ||
3. Commit your code | ||
4. Create Pull Request | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Wed Oct 19 14:34:26 2022 | ||
@author: shangfr | ||
""" | ||
|
||
import streamlit as st | ||
from pipdeptree import get_installed_distributions, PackageDAG | ||
from language import chinese_dict | ||
from charts import render_graph | ||
|
||
st.set_page_config(page_title='PyDepGraph', page_icon='🌐', layout="wide") | ||
st.sidebar.title('🌐 PyDepGraph') | ||
st.header('PackagesGraph 👇 ') | ||
|
||
lang = st.sidebar.select_slider( | ||
'💬 Select a Language of The App', | ||
options=['English', '中文']) | ||
|
||
if lang == '中文': | ||
lang_dict = chinese_dict | ||
else: | ||
lang_dict = {k: k for k, v in chinese_dict.items()} | ||
|
||
|
||
with st.sidebar: | ||
st.write(f"#### {lang_dict['Upload your own data']}") | ||
uploaded_file = st.file_uploader( | ||
lang_dict["the streamlit data default"], type=['json']) | ||
|
||
col3, col4 = st.columns(2) | ||
with st.expander(lang_dict['Color Setting']): | ||
col5, col6, col7, col8 = st.columns(4) | ||
|
||
with st.expander(lang_dict['Nodes Setting']): | ||
col9, col10 = st.columns(2) | ||
col11, col12 = st.columns(2) | ||
col13, col14 = st.columns(2) | ||
|
||
st.markdown('---') | ||
|
||
|
||
node_color = col5.color_picker(lang_dict['Node Color'], '#00F9F5') | ||
links_color = col6.color_picker(lang_dict['Links Color'], '#F90023') | ||
border_color = col7.color_picker(lang_dict['Border Color'], '#146B6B') | ||
shadow_color = col8.color_picker(lang_dict['Shadow Color'], '#00F9C9') | ||
|
||
|
||
node_size = col9.slider(lang_dict["Nodes SymbolSize"], 5, 50, 20) | ||
border_width = col10.slider(lang_dict["Border Width"], 0, 10, 2) | ||
shadow_blur = col11.slider(lang_dict["Shadow Blur"], 0, 50, 10) | ||
nodes_font_size = col12.slider(lang_dict["Nodes FontSize"], 5, 50, 12) | ||
label_font_size = col13.slider(lang_dict["Label FontSize"], 5, 50, 10) | ||
|
||
|
||
@st.cache(allow_output_mutation=True) | ||
def read_pkgs(local_only=True, user_only=False): | ||
pkgs = get_installed_distributions(local_only, user_only) | ||
tree = PackageDAG.from_pkgs(pkgs) | ||
return tree | ||
|
||
|
||
if uploaded_file is None: | ||
local_only = True | ||
user_only = False | ||
tree = read_pkgs(local_only, user_only) | ||
packages = col3.text_input(lang_dict['Packages'], value='streamlit') | ||
exclude = col4.text_input(lang_dict['Exclude'], value='') | ||
|
||
show_only = set(packages.split(",")) if packages else None | ||
exclude = set(exclude.split(",")) if exclude else None | ||
|
||
if show_only is not None or exclude is not None: | ||
tree = tree.filter(show_only, exclude) | ||
|
||
data = [{"package": k.as_dict(), "dependencies": [v.as_dict() for v in vs]} | ||
for k, vs in tree.items()] | ||
else: | ||
from utils import extract_graph_data | ||
bytes_data = uploaded_file.getvalue() | ||
data = extract_graph_data(bytes_data) | ||
|
||
|
||
item_style = {"normal": { | ||
"borderColor": border_color, | ||
"borderWidth": border_width, | ||
"shadowBlur": shadow_blur, | ||
"shadowColor": shadow_color, | ||
"color": node_color | ||
}} | ||
|
||
nodes = [] | ||
links = [] | ||
categories = [] | ||
|
||
|
||
def node_check(node_d, item_style=item_style): | ||
node_n = node_d['key'] | ||
nn = [n for n in nodes if n.get('name') == node_n] | ||
if len(nn) == 0: | ||
node = {} | ||
node_id = str(len(nodes)) | ||
node['id'] = node_id | ||
node['name'] = node_d['key'] | ||
node['value'] = node_d['installed_version'] | ||
node['itemStyle'] = item_style | ||
nodes.append(node) | ||
else: | ||
node_id = nn[0]['id'] | ||
return node_id | ||
|
||
|
||
for d in data: | ||
node_id_s = node_check(d['package']) | ||
if d['dependencies']: | ||
for dd in d['dependencies']: | ||
node_id_t = node_check(dd, item_style) | ||
link = {} | ||
link["source"] = node_id_s | ||
link["target"] = node_id_t | ||
link["label"] = { | ||
"show": True, "formatter": dd['required_version'], "fontSize": label_font_size} | ||
links.append(link) | ||
|
||
|
||
graph = {"nodes": nodes, "links": links, "categories": categories} | ||
|
||
|
||
for idx, _ in enumerate(graph["nodes"]): | ||
graph["nodes"][idx]["symbolSize"] = node_size | ||
|
||
graph["links_color"] = links_color | ||
graph["nodes_font_size"] = nodes_font_size | ||
|
||
render_graph(graph) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Thu Oct 20 10:23:44 2022 | ||
@author: shangfr | ||
""" | ||
from streamlit_echarts import st_echarts | ||
|
||
def render_graph(graph): | ||
option = { | ||
"title": { | ||
"text": "Packages", | ||
"subtext": "Default layout", | ||
"top": "bottom", | ||
"left": "right", | ||
}, | ||
"tooltip": {}, | ||
"legend": [{"data": [a["name"] for a in graph["categories"]]}], | ||
"series": [ | ||
{ | ||
"name": "Packages", | ||
"type": "graph", | ||
"layout": "force", | ||
"data": graph["nodes"], | ||
"links": graph["links"], | ||
"categories": graph["categories"], | ||
"lineStyle": {"color": graph["links_color"]}, | ||
"roam": True, | ||
#"label": {"position": "right"}, | ||
"label": {"show": True,"fontSize": graph["nodes_font_size"]}, | ||
"edgeSymbol": ["none", "arrow"], | ||
"draggable": True, | ||
"force": {"repulsion": 100}, | ||
} | ||
], | ||
} | ||
st_echarts(option, height="500px") | ||
|
||
|
||
|
||
|
||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 语言包 | ||
chinese_dict = { | ||
'Local Only':'仅限本地Python环境', | ||
'User Only':'仅限当前用户', | ||
'Packages':'包名', | ||
'Exclude':'不含', | ||
'Color Setting':'颜色设置', | ||
'Node Color':'节点', | ||
'Border Color':'边框', | ||
'Shadow Color':'阴影', | ||
'Links Color':'连接', | ||
|
||
'Nodes Setting':'节点设置', | ||
"Nodes SymbolSize": '节点大小', | ||
"Border Width":'边框宽度', | ||
"Shadow Blur": '阴影模糊', | ||
"Nodes FontSize":'节点字体大小', | ||
"Label FontSize": '标签字体大小', | ||
|
||
'Upload your own data': "上传你的数据", | ||
'Download Sample Data':"下载样例数据", | ||
|
||
'the streamlit data default':'默认显示streamlit数据', | ||
'Donate':"赞赏 / Donate" | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Automatically generated by https://github.com/damnever/pigar. | ||
|
||
pipdeptree == 2.3.1 | ||
streamlit == 1.12.2 | ||
streamlit_echarts == 0.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Thu Oct 20 10:21:50 2022 | ||
@author: shangfr | ||
""" | ||
|
||
import json | ||
with open("data/pkg.json", "rb") as f: | ||
data = json.loads(f.read()) |
Oops, something went wrong.