如何构建标准 Python 项目(模块、库)以供将来在 Google App Engine 中使用?

发布于 2024-12-10 19:49:45 字数 666 浏览 0 评论 0原文

我目前正在开发一个正在成长的Python项目,将来我可能会将其实现为GAE中的Web应用程序。

随着项目的发展,我正在将潜在的可重用代码修剪成单独的包和包。模块,目前位于我的 PYTHONPATH 上。

您对如何构建我的项目和可重用包以使其将来能很好地融入 GAE 项目有什么建议吗?

查看其他帖子中有关 GAE 项目结构的建议(例如和< a href="https://stackoverflow.com/questions/2546199/python-and-app-engine-project-struct">这个 和 这个)看起来相当平坦 - 这是最好的方法吗?

第三方包/模块怎么样?最好是硬着头皮从一开始就使用 VirtualEnv 吗?

非常感谢。 普雷姆博。

I'm currently developing a Python project which is growing and I may implement it as a webapp in GAE in the future.

As the project is growing I'm pruning potentially reusable code into separate packages & modules, which at present are on my PYTHONPATH.

Do you have any advice on how to structure my project, and reusable packages so that it will fit nicely into a GAE project in the future?

Looking at recommendations on GAE project structure in other posts (such as this and this and this) seem fairly flat - is that the best way to go?

What about 3rd party packages/modules? Is it best to bite the bullet and use VirtualEnv from the beginning?

Thanks very much.
Prembo.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌逼全场 2024-12-17 19:49:45

只需将各种库放在应用程序根目录下的包中即可。根目录会自动添加到应用的 sys.path 中。

如果您希望将它们放在根目录下的 lib 目录中,您可以这样做,但您必须编写一个模块来将该目录添加到 sys.path 的末尾,并在从 lib 导入任何内容之前导入它。

使用 virtualenv 是一种选择,但我个人认为它不会给你带来多大好处,因为你无法在生产中运行 virtualenv,并且 dev_appserver 会模拟生产环境。

Just put your various libraries in packages off the root directory of your app. The root directory is automatically added to your app's sys.path.

If you wish you can put them in a lib directory off the root, you can do so, but you'll have to write a module that adds that directory to the end of sys.path, and import it before you import anything from lib.

Using virtualenv is an option, but I personally don't think it gains you much, since you can't run a virtualenv in production, and the dev_appserver emulates the production environment.

标点 2024-12-17 19:49:45

我无法具体告诉您有关 GAE 的信息,但我可以告诉您,硬着头皮与它无关——使用 VirtualEnv(和 virtualenvwrapper)将使您的 Python 开发更加顺畅、简单和轻松。

开销低,好处多。

转变。现在。

I can't tell you about GAE in particular, but I can tell you that biting the bullet has nothing to do with it - using VirtualEnv (and virtualenvwrapper) will make your Python development smoother, simpler, and easier all around.

The over head is low, the benefits are many.

Switch. Now.

合约呢 2024-12-17 19:49:45

我作为学生时的硕士论文是在 App Engine 中实现的。该项目是开源的,您可以随心所欲地使用它,我希望您能明白这个想法,并可以根据您的需要进行调整。

My master thesis as a student was implemented in App Engine. The project is open source and you can use it however you like, I hope you will get the idea and you might adapt it to your needs.

酷到爆炸 2024-12-17 19:49:45

GAE Python SDK 在本地环境中运行时会创建自己的虚拟环境,因此 virtualenv 不会对您有太大帮助。如果您打算移植代码,或者至少从它们的文件夹结构中获得灵感,那么像 web2py 和 django-nonrel 这样的框架可以与 GAE 很好地配合。

The GAE Python SDK creates its own Virtual Environment when running on your local environment, so virtualenv won't help you much. There are frameworks like web2py and django-nonrel that works well with GAE, if you're up to porting your code, or at least take inspiration on their folder structure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文