Skip to content

Commit

Permalink
add coding
Browse files Browse the repository at this point in the history
init
  • Loading branch information
shangfr committed Oct 20, 2022
1 parent e5bf6c3 commit 9a33689
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 55 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2022 Fengrui Shang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
82 changes: 46 additions & 36 deletions README.en.md
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

47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
# PyDepGraph

#### 介绍
PyDepGraph-Python项目依赖树可视化工具

PyDepGraph is a utility for displaying the installed python packages in form of a dependency tree.

PyDepGraph-Python项目依赖树可视化工具

PyDepGraph is a utility for displaying the installed python packages in form of a dependency tree.

![pic](picture/pic1.png)

#### 软件架构

软件架构说明

- **Pipdeptree** Python项目依赖数据获取
- **Streamlit** Web应用程序框架
- **Echarts** Graph可视化

#### 安装教程

1. xxxx
2. xxxx
3. xxxx
1. $ git clone https://gitee.com/vencen/py-dep-graph.git

#### 使用说明

1. xxxx
2. xxxx
3. xxxx
1. $ cd py-dep-graph
2. $ streamlit run app.py

##### 上传本地项目依赖json文件

**查看所有包及其依赖**

1. 安装 $ pip install pipdeptree
2. 执行 $ pipdeptree --json > pkg.json

**查看指定包,其需要的依赖**

3. 执行 $ pipdeptree --json -p xxx包名 > xxxpkg.json

**查看哪些其它包,依赖于此指定包**

4. 执行 $ pipdeptree --json -p xxx包名 -r > xxxpkg.json



#### 参与贡献

Expand All @@ -29,12 +49,3 @@ PyDepGraph is a utility for displaying the installed python packages in form of
3. 提交代码
4. 新建 Pull Request


#### 特技

1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
136 changes: 136 additions & 0 deletions app.py
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)
43 changes: 43 additions & 0 deletions charts.py
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 added data/pkg.json
Binary file not shown.
26 changes: 26 additions & 0 deletions language.py
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"
}

Binary file added picture/pic1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions requirements.txt
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
10 changes: 10 additions & 0 deletions test.py
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())
Loading

0 comments on commit 9a33689

Please sign in to comment.