问题:从Python源代码生成UML图的最佳方法是什么?[关闭]

一位同事正在寻找从Python源代码堆中生成UML类图的方法。他主要对继承关系感兴趣,对组合关系也颇有兴趣,并且不太在乎仅仅是Python原语的类属性。

源代码非常简单明了,没有太大的弊端-例如,它没有做任何花哨的元类魔术。(这主要是从Python 1.5.2时代开始的,其中散布着一些“现代”的2.3ish东西。)

有什么最好的现有解决方案推荐?

A colleague is looking to generate UML class diagrams from heaps of Python source code. He’s primarily interested in the inheritance relationships, and mildly interested in compositional relationships, and doesn’t care much about class attributes that are just Python primitives.

The source code is pretty straightforward and not tremendously evil–it doesn’t do any fancy metaclass magic, for example. (It’s mostly from the days of Python 1.5.2, with some sprinklings of “modern” 2.3ish stuff.)

What’s the best existing solution to recommend?


回答 0

您可能听说过Pylint可帮助静态检查Python代码。很少有人知道它带有一个名为Pyreverse的工具,该工具从读取的python代码中绘制UML图。Pyreverse使用graphviz作为后端。

You may have heard of Pylint that helps statically checking Python code. Few people know that it comes with a tool named Pyreverse that draws UML diagrams from the python code it reads. Pyreverse uses graphviz as a backend.

It is used like this:

pyreverse -o png -p yourpackage .

where the . can also be a single file.


回答 1

Epydoc是从Python源代码生成API文档的工具。它还以花哨的方式使用Graphviz生成UML类图。这是从Epydoc本身的源代码生成的图表示例

由于Epydoc同时执行对象自省和源解析,因此它可以收集有关静态代码分析器(例如Doxygen)的更多信息:它可以检查大量动态生成的类和函数,但也可以使用注释或未分配的字符串作为文档源,例如用于变量和类的公共属性。

Epydoc is a tool to generate API documentation from Python source code. It also generates UML class diagrams, using Graphviz in fancy ways. Here is an example of diagram generated from the source code of Epydoc itself.

Because Epydoc performs both object introspection and source parsing it can gather more informations respect to static code analysers such as Doxygen: it can inspect a fair amount of dynamically generated classes and functions, but can also use comments or unassigned strings as a documentation source, e.g. for variables and class public attributes.


回答 2

检查此列表的七个python uml工具


回答 3

某些行为良好的程序可能是图表,但是在一般情况下,这是无法完成的。可以在运行时扩展Python对象,并且可以将任何类型的对象分配给任何实例变量。弄清楚一个对象可以包含指向(组成)的指针的类,将需要对程序的运行时行为有充分的了解。

Python的元类功能意味着对继承结构的推理还需要对程序的运行时行为有充分的了解。

为了证明这些是不可能的,您认为如果存在这样的UML图表生成器,则可以采用任意程序,将“暂停”语句转换为会影响UML图表的语句,然后使用UML图表生成器解决暂停问题,我们知道这是不可能的。

Certain classes of well-behaved programs may be diagrammable, but in the general case, it can’t be done. Python objects can be extended at run time, and objects of any type can be assigned to any instance variable. Figuring out what classes an object can contain pointers to (composition) would require a full understanding of the runtime behavior of the program.

Python’s metaclass capabilities mean that reasoning about the inheritance structure would also require a full understanding of the runtime behavior of the program.

To prove that these are impossible, you argue that if such a UML diagrammer existed, then you could take an arbitrary program, convert “halt” statements into statements that would impact the UML diagram, and use the UML diagrammer to solve the halting problem, which as we know is impossible.


回答 4

如果您使用eclipse,则可能是PyUML。不过还没有使用过。

If you use eclipse, maybe PyUML. Haven’t used it, though.


回答 5

值得一提的是Gaphor。Python建模/ UML工具。

It is worth mentioning Gaphor. A Python modelling/UML tool.


回答 6

雨伞也这样做。在菜单中,转到代码->导入项目,然后指向项目的根目录。然后它会反转代码…

Umbrello does that too. in the menu go to Code -> import project and then point to the root deirectory of your project. then it reverses the code for ya…


回答 7

vipera是一名小型应用程序设计师,其中包括uml。您可以在以下位置看到它:

per蛇

最好的祝福。

vipera is a small application designer, and uml is included. You can see it in:

vipera

Best regards.


回答 8

SPE IDE内置了UML的创造者。只需在SPE中打开文件,然后单击UML选项卡即可。

我不知道它对您的需求有多全面,但是不需要任何其他下载或配置。

The SPE IDE has built-in UML creator. Just open the files in SPE and click on the UML tab.

I don’t know how comprhensive it is for your needs, but it doesn’t require any additional downloads or configurations to use.


回答 9

Sparx的企业架构师执行Python源的往返操作。他们有免费的限时试用版。

Sparx’s Enterprise Architect performs round-tripping of Python source. They have a free time-limited trial edition.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。