简体   繁体   English

Git 最佳实践:如何构建一个大型应用程序所需的多个 python 模块

[英]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.

相关问题 Python / Git /模块结构最佳实践 - Python / Git / Module structure best practice Python大应用程序:如何使用可能需要或不需要的其他模块,具体取决于给出的请求? - Python large app: how to use other modules that might be needed or not, depending on the request given? 升级 Python 模块的最佳实践 - Best practice for upgrading Python modules 在 Python 中导入模块 - 最佳实践 - Importing modules in Python - best practice 延迟加载 Python 模块的最佳实践 - Best practice for lazy loading Python modules python中不同模块之间通信的最佳实践 - Best practice for communication between different modules in python Python - 令人难以置信的大型矩阵的最佳数据结构 - Python - Best data structure for incredibly large matrix 在Anaconda中安装Python模块的开发版本的最佳实践是什么? - What's the best practice for installing development versions of Python modules in Anaconda? Python记录了可重用模块的最佳实践,这些模块旨在包含在其他代码中 - Python logging best practice for reusable modules intended to be included with other code 在父子模块中导入祖父母模块的Python最佳实践 - Python best practice for importing grandparent module in parent and child modules
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM