假设您有一个客户端/服务器应用程序,例如一个 Web 服务器组件和一个 qt gui。你如何布局你的Python代码?
- 包 foo.server 和 foo.client?
- 包 fooserver 和 fooclient,都从 foocommon 导入?
- 一切都在一起,没有明显的区别?
对我来说,拥有服务器和客户端代码的子包(foo.server 和 foo.client)似乎是最好的方法,但是如果您不希望服务器代码与客户端代码一起发布,那么如何处理 distutils 设置呢?如果你使用setuptools(我宁愿不使用),你如何创建单独的鸡蛋?
Suppose you have a client/server application, say a webserver component and a qt gui. How do you layout your python code?
- Packages foo.server and foo.client?
- Packages fooserver and fooclient, with both importing from foocommon?
- Everything together with no clear distinction?
Having subpackages for server and client code (foo.server and foo.client) seems the best approach to me, but then how do you handle your distutils setup if you don't want the server code to be shipped along with the client code? If you use setuptools (I would rather not), how do you create separate eggs?
发布评论
评论(4)
buildbot 选择创建单独的包(对于 master 和 源控件中,它们具有三个文件夹:common、master 和 Slave(以及文档) 。
buildbot has opted to create separate packages (for the master and the slave). In source control, they have three folders: common, master, and slave (plus documentation).
我喜欢命名空间,所以是的。 foo.client 和 foo.server 以及 foo.common 和 foo.anythingelsethat 可以单独使用。但这真的只是品味问题。
我会将它们作为单独的包发布,是的,我会使用 Distribute。
I like namespaces, so yes. foo.client and foo.server and foo.common and foo.anythingelsethatcanbeusedseparately. But it's all a matter of taste, really.
And I'd release them as separate packages, and yes, I'd use Distribute.
现在我只使用setuptools(实际上是distribute),所以我在我的项目中使用该代码:
setup.py:
命名空间模块中的所有 __init__.py 文件:
而真正的 __init__.py 文件如下所示:
Now I'm use only setuptools (really distribute), so I'm use that code in my projects:
setup.py:
All __init__.py files in namespace modules:
And real __init__.py file looks like:
为什么?没有任何一个用户(除了你作为开发者)会同时使用双方。他们是完全分开的。
恰恰。他们几乎完全不相关。
如需指导,请查看其他客户端-服务器应用程序。
例如,万维网。
我可以看到 Apache HTTPD 服务器和 Firefox 浏览器没有任何通用代码。也许有一些底层库,但它们显然不是 htttpd.client 和 httpd.server。他们显然是完全分开的。
Sendmail 服务器和 Python 中的 pop/imap 库似乎完全分开,几乎没有任何共同点。
MySQL 数据库服务器和 Python 中的 MySQLDB 接口似乎完全分离,几乎没有任何共同点。
我在任何地方都看不到 foo.server 和 foo.client 的任何示例。也许您可以分享一个示例作为问题的一部分,以帮助阐明您对此主题的想法。
Why? No single user (except you the developer) will ever use both sides. They're completely separate.
Precisely. They're almost completely unrelated.
For guidance, look at other client-server applications.
The World Wide Web, for example.
The Apache HTTPD server and the Firefox browser do not have any common code that I can see. Maybe a few underlying libraries, but they're clearly not htttpd.client and httpd.server. They're clearly utterly separate.
The Sendmail server and the pop/imap libraries in Python seem to be utterly separated with almost nothing in common.
The MySQL database server and the MySQLDB interface in Python seem to be utterly and completely separated with almost nothing in common.
I can't see any examples of foo.server and foo.client anywhere. Perhaps you could share an example as part of your question to help clarify your thinking on this subject.