[英]Git Best Practice: How to structure multiple python modules needed for one large app
I have created a flask app that uses python modules that have been created by others in my team.我创建了一个 flask 应用程序,它使用了我团队中其他人创建的 python 模块。 To make it work on my pycharm I download the modules and load them in [either using init.py files or using full references] to use them.为了让它在我的 pycharm 上工作,我下载了模块并将它们加载到 [使用 init.py 文件或使用完整引用] 中以使用它们。
I want to understand what is the best way to store this kind of flask app and the python modules its references so that when someone downloads the app it can get all it needs.我想了解存储这种 flask 应用程序和 python 模块的最佳方法是什么,以便当有人下载该应用程序时,它可以获得所需的一切。 And very importantly keeping the flask app stuff [like app.py and html] completely separate from the python modules.并且非常重要的是,将 flask 应用程序内容 [如 app.py 和 html] 与 python 模块完全分开。
Currently my app.py just calls the functions in these python modules, so it has a degree of independence but I want to make sure I follow best practices and make it easy for my team to make changes to these modules and for me to update myself with these changes.目前我的 app.py 只调用这些 python 模块中的函数,因此它具有一定程度的独立性,但我想确保我遵循最佳实践,让我的团队轻松更改这些模块并让我更新自己随着这些变化。
In summary, what is the best way to store / use / update flask apps that are dependent on other python modules on GitHub and how one can then use this GitHub organization to easily setup part of the whole application on their local system? In summary, what is the best way to store / use / update flask apps that are dependent on other python modules on GitHub and how one can then use this GitHub organization to easily setup part of the whole application on their local system?
I would say you can make a repository per module and one for your application.我想说您可以为每个模块创建一个存储库,并为您的应用程序创建一个。
The modules are dependencies of your application.模块是您的应用程序的依赖项。
You can define a dependency from github in a requirement.txt
like this:您可以在requirement.txt
中定义来自github的依赖项,如下所示:
git+git://github.com/path/to/my-module@master#egg=my-module
SomeOtherPackage==1.0.4
You can specify a branch , a commit , a tag , a release .你可以指定一个分支、一个提交、一个标签、一个发布。
See How to state in requirements.txt a direct github source for more details and the requirements files documentation .有关更多详细信息和需求文件文档,请参阅requirements.txt 中的如何 state 直接 github 源。
When you want to update a module you push it in its own repository and then on your application you can update the requirement.txt
to update the commit hash the tag or the release or whatever you used if it needs to be updated and then just reinstall the dependency.当你想更新一个模块时,你将它推送到它自己的存储库中,然后在你的应用程序上你可以更新requirement.txt
以更新提交 hash标签或发布或任何你使用的,如果它需要更新,然后重新安装依赖。
Another solution instead of installing them as dependencies with pip
you could use Git Submodules .另一种解决方案,而不是将它们作为依赖项与pip
一起安装,您可以使用Git Submodules 。 The modules are still separated in their own repositories and these repositories are available inside your application repository.这些模块仍然在它们自己的存储库中分开,并且这些存储库在您的应用程序存储库中可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.