GAE - 包含外部python模块而不将它们添加到存储库? [英] GAE - Including external python modules without adding them to the repository?

查看:181
本文介绍了GAE - 包含外部python模块而不将它们添加到存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究基于python的Google App Engine项目。具体来说,我使用Flask作为应用程序。我想知道包括外部python模块的接受方法是什么,特别是当涉及到存储库。从我可以告诉,包括其他人的代码在我的存储库是不好的形式有几个原因。然而,其他人将在同一个存储库上工作,所以我们应该使用相同的外部模块来确保相同的结果。



具体来说,我需要包括Flask和它的依赖)到我的应用程序。使用Google App Engine最简单的方法就是将它们引入根级别:

  MyProject 
app .yaml
main.py
MyApp
Flask
...

在这样的项目中引入这些外部模块的正确方法是什么?对于我的情况,一个普遍的答案和一个特定的答案都是有用的。此外,任何其他相关的建议,将不胜感激。尽管将第三方库作为子模块或来自外部存储库的符号链接确实是可能的,但实际上它是可能的不是一个好主意。这里有两种可能出错的情况:如果第三方库发布了一个破坏功能的新版本,那么您可能会遇到以下情况: 将不得不做出所有必要的改变来满足新的要求,或者只是找到以前的版本来继续工作并打破外部连接。如果第三方库发布了一个新版本,并且你的一个同事被升级并完成了所有必要的工作,那么通常情况下,这种情况发生在接近截止日期的时候。 更改以支持新版本,在您身边的代码将被打破,直到您将升级。 上面的例子在有大量依赖项目的大项目中可见得多,而且从长远来看,越来越多的人加入项目,这成为一个巨大的问题!我可以拿出更多的例子,但我认为你可以看到这一点。



你最好的选择是将外部库包括到你的仓库,这也有优势你可以让整个项目在一台没有太多依赖的新机器上运行。在如何组织您的第三方库方面有很多方法,并且所有这些方法都需要包含在相同或更深的级别与您的 app.yaml 文件。就像@dragonx提到的只包括核心库代码一样。

另外,不要害怕将东西放入存储库,因为空间不是今天的问题,而且这些库通常不会更新,所以您的存储库大小不会太大

由于您在Google App Engine上提到了Flask,因此您可以查看我的 gae-init 项目,您可以在练习中看到外部库被组织。


I'm current working on a python based Google App Engine project. Specifically, I'm using Flask for the application. I'm wondering what the accepted method of including external python modules is, specifically when it comes to the repository. From what I can tell, including other people's code in my repository is bad form for several reasons. However, other people will be working on the same repository, so we should be using the same external modules to insure the same results.

Specifically, I need to include Flask (and its dependencies) to my application. The easiest way to do this with Google App Engine is just to throw them into the root level:

MyProject
    app.yaml
    main.py
    MyApp
    Flask
    ...

What is the proper way to bring in these external modules in such a project? Both a generalized answer and one specific to my case would be useful. Also, any other related recommendations would be appreciated. Thank you much.

解决方案

While it is indeed possible to include third party libraries as submodules or symlinks from external repositories, in practice it's not a good idea. Here are two scenarios on what could go wrong:

  1. If the third party library releases a new version that breaks the functionality, you will have to either make all the necessary changes to meet the new requirements or simply find the previous version to keep working and break the external connection. Usually this happens when you are very close to deadlines.

  2. If the third party library releases a new version and one of your colleagues is upgraded and made all the necessary changes to support the new version, on your side the code will be broken until you will upgrade as well.

The above examples are much more visible in big projects with lots of dependencies and as more people joining the project in the long run it becomes a huge problem! I could come up with more examples, but I think you can see the point.

Your best option is to include the external libraries into your repository, which also has the advantage that you are able to have the whole project up and running on a new machine without many dependencies. There are many ways on how to organize your third party libraries and all of them needs to be included on the same or deeper level with your app.yaml file. Just as @dragonx mentioned include only the core library code.

Also do not afraid putting stuff into your repository cause space is not an issue today and these libraries usually not updating that often so your repository size is not getting too much bigger over time.

Since you mentioned Flask on Google App Engine, you can check out my gae-init project, where you can see in practice how the external libraries are organised.

这篇关于GAE - 包含外部python模块而不将它们添加到存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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