Python应用程序的最佳项目结构是什么? [英] What is the best project structure for a Python application?

查看:510
本文介绍了Python应用程序的最佳项目结构是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,您想用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.

特别是:


  1. 您将源代码放在哪里?

  2. 在哪里放置应用程序启动脚本?

  3. 在哪里放置IDE项目文件?

  4. 您将单元/验收测试放在哪里?

  5. 将非Python数据(例如配置文件)放在哪里?

  6. 将非Python数据放在哪里? -Python来源,例如pyd / so二进制扩展模块的C ++?

  1. Where do you put the source?
  2. Where do you put application startup scripts?
  3. Where do you put the IDE project cruft?
  4. Where do you put the unit/acceptance tests?
  5. Where do you put non-Python data such as config files?
  6. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆