Python应用程序的最佳项目结构是什么? [英] What is the best project structure for a Python application?
问题描述
想象一下,您想用Python开发非平凡的最终用户桌面(非Web)应用程序。构造项目文件夹层次结构的最佳方法是什么?
Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy?
理想的功能是易于维护,IDE友好,适合源代码控制分支/合并以及易于生成。
Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install packages.
特别是:
- 您将源代码放在哪里?
- 在哪里放置应用程序启动脚本?
- 在哪里放置IDE项目文件?
- 您将单元/验收测试放在哪里?
- 将非Python数据(例如配置文件)放在哪里?
- 将非Python数据放在哪里? -Python来源,例如pyd / so二进制扩展模块的C ++?
- Where do you put the source?
- Where do you put application startup scripts?
- Where do you put the IDE project cruft?
- Where do you put the unit/acceptance tests?
- Where do you put non-Python data such as config files?
- Where do you put non-Python sources such as C++ for pyd/so binary extension modules?
推荐答案
太多的事。令您快乐的一切都会起作用。没有很多傻规则,因为Python项目可以很简单。
Doesn't too much matter. Whatever makes you happy will work. There aren't a lot of silly rules because Python projects can be simple.
-
/ scripts
或/ bin
用于此类命令行界面内容 -
/ tests
用于测试 -
/ lib
用于C语言库 -
/ doc
用于大多数文档 -
/ apidoc
用于Epydoc生成的API文档。
/scripts
or/bin
for that kind of command-line interface stuff/tests
for your tests/lib
for your C-language libraries/doc
for most documentation/apidoc
for the Epydoc-generated API docs.
顶级目录可以包含自述文件,配置文件和其他内容。
And the top-level directory can contain README's, Config's and whatnot.
困难的选择是是否使用 / src
树。 Python在 / src
, / lib
和 / bin <之间没有区别/ code>就像Java或C一样。
The hard choice is whether or not to use a /src
tree. Python doesn't have a distinction between /src
, /lib
, and /bin
like Java or C has.
因为可以看到顶层 / src
目录在某些情况下,毫无意义,您的顶级目录可以是应用程序的顶级体系结构。
Since a top-level /src
directory is seen by some as meaningless, your top-level directory can be the top-level architecture of your application.
-
/ foo
-
/ bar
-
/ baz
/foo
/bar
/baz
我建议将所有这些都放在我的产品名称下目录。因此,如果您正在编写名为 quux
的应用程序,则包含所有这些内容的目录将命名为 / quux
。
I recommend putting all of this under the "name-of-my-product" directory. So, if you're writing an application named quux
, the directory that contains all this stuff is named /quux
.
另一个项目的 PYTHONPATH
,然后可以包含 / path / to / quux / foo
重用 QUUX.foo
模块。
Another project's PYTHONPATH
, then, can include /path/to/quux/foo
to reuse the QUUX.foo
module.
就我而言,由于我使用Komodo Edit,因此我的IDE cuft是单个.KPF文件。实际上,我将其放在顶级 / quux
目录中,并忽略了将其添加到SVN中的情况。
In my case, since I use Komodo Edit, my IDE cuft is a single .KPF file. I actually put that in the top-level /quux
directory, and omit adding it to SVN.
这篇关于Python应用程序的最佳项目结构是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!