文章目录
- pylint
- pyreverse
pylint
- github : https://github.com/pylint-dev/pylint
- 官网:https://www.pylint.org
- 文档:https://pylint.readthedocs.io/en/latest/
Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的语法错误,是否遵守编码风格标准、潜在的问题等
相关教程可见:
https://zhuanlan.zhihu.com/p/364594654
pip install pylint
pylint 有两个附加工具
- pyreverse 生成包和类图
https://pylint.readthedocs.io/en/latest/pyreverse.html - symilar 代码查重
https://pylint.readthedocs.io/en/latest/symilar.html
pyreverse
支持生成到 .dot
/.gv
, .puml
/.plantuml
(PlantUML) and .mmd
/.html
(MermaidJS) 文件格式
如果安装了 Graphviz,也可以使用所有 Graphviz 支持的格式。
graphviz 安装使用:https://blog.csdn.net/lovechris00/article/details/113597376
输出示例
简单使用
参考教程:https://zhuanlan.zhihu.com/p/365953969
文件夹下生成了一个 classes.dot
文件
生成类图
dot -Tpdf classes.dot -o classes.pdf
只生成类名,不显示类属性和方法:-k
pyreverse -ASmy -k -o pdf .
忽略文件或文件夹,,
分隔,只用输入名称,不用输入路径。
pyreverse -ASmy -k --ignore feeds,indicators,filters -o pdf .
对指定的类,找到所有与他相关的类,并生成图表,但对复杂的类效果一般。
pyreverse -ASmy -k -c backtrader.cerebro.Cerebro -o pdf .
生成彩色的: --colorized
pyreverse -ASmy -k --colorized -o png .
设定相关类的层次,即如在子文件夹中,是否到上一次文件夹去搜索相关类。
pyreverse -ASmy -s 2 -k -o png .
查看所有可用选项
pyreverse -h
Create UML diagrams for classes and modules in <packages>
.
optional arguments:
-h
,--help
show this help message and exit
Pyreverse:
Base class providing common behaviour for pyreverse commands.
--filter-mode <mode>
,-f <mode>
filter attributes and functions according to<mode>
. Correct modes are : ‘PUB_ONLY’ filter all non public attributes [DEFAULT], equivalent to PRIVATE+SPECIAL_A ‘ALL’ no filter ‘SPECIAL’ filter Python special functions except constructor ‘OTHER’ filter protected and private attributes (default: PUB_ONLY)--class <class>
,-c <class>
create a class diagram with all classes related to<class>
; this uses by default the options -ASmy (default: [])--show-ancestors <ancestor>
,-a <ancestor>
show<ancestor>
generations of ancestor classes not in<projects>
(default: None)--all-ancestors
,-A
show all ancestors off all classes in<projects>
(default: None)--show-associated <association_level>
,-s <association_level>
show<association_level>
levels of associated classes not in<projects>
(default: None)--all-associated
,-S
show recursively all associated off all associated classes (default: None)--show-builtin
,-b
include builtin objects in representation of classes (default: False)--show-stdlib
,-L
include standard library objects in representation of classes (default: False)--module-names <y or n>
,-m <y or n>
include module name in representation of classes (default: None)--only-classnames
,-k
don’t show attributes and methods in the class boxes; this disables -f values (default: False)--no-standalone
only show nodes with connections (default: False)--output <format>
,-o <format>
create a *. output file if format is available. Available formats are: dot, puml, plantuml, mmd, html. Any other format will be tried to create by means of the ‘dot’ command line tool, which requires a graphviz installation. (default: dot)--colorized
Use colored output. Classes/modules of the same package get the same color. (default: False)--max-color-depth <depth>
Use separate colors up to package depth of<depth>
(default: 2)--color-palette <color1,color2,...>
Comma separated list of colors to use (default: (‘#77AADD’, ‘#99DDFF’, ‘#44BB99’, ‘#BBCC33’, ‘#AAAA00’, ‘#EEDD88’, ‘#EE8866’, ‘#FFAABB’, ‘#DDDDDD’))--ignore <file[,file...]>
Files or directories to be skipped. They should be base names, not paths. (default: (‘CVS’,))--project <project name>
,-p <project name>
set the project name. (default: )--output-directory <output_directory>
,-d <output_directory>
set the output directory path. (default: )--source-roots <path>[,<path>...]
Add paths to the list of the source roots. Supports globbing patterns. The source root is an absolute path or a path relative to the current working directory used to determine a package namespace for modules located under the source root. (default: ())--verbose
Makes pyreverse more verbose/talkative. Mostly useful for debugging. (default: False)
参考:
- Python类关系绘图Pyreverse全参数帮助中文版
https://zhuanlan.zhihu.com/p/649110516
伊织 2024-02-21