在Heroku应用程序之间共享Python代码 [英] Sharing Python code between Heroku apps

查看:125
本文介绍了在Heroku应用程序之间共享Python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个Heroku应用程序,都是Pyhon,以及它们之间共享的一些python模块(即:它们在两个应用程序中都是相同的)。
设置我的git / requirements.txt以实现以下目标的最佳方式是什么?


  1. 共享代码是版本化的(也就是说:它也位于Git中,我不关心其中一个项目在哪里?另一个项目?)
  2. 在开发过程中,我有一份共享代码在我的磁盘上

  3. 在开发过程中,我可以更改共享代码的单个副本,并在两个应用程序中反映更改,理想情况下除了更改磁盘上的文件外,不需要执行任何操作。 >
  4. 推荐给Heroku时,我所做的只是一个简单的推送

我的直觉告诉我我需要将共享代码作为Python包,磁盘上以及开发中的代码添加到每个应用程序的PYTHONPATH中。
此外,我将它添加到每个应用程序的requriments.txt中(如何使用私有服务器?从s3?作为供应商目录?)。

...但是我不能完全明白它。



有什么想法?

解决方案

您可以使用 pip 需求文件来完成此操作。你可能有一个用于本地开发,一个用于你的应用程序。请查看需求文件格式获取更多信息。



本地开发需求文件



  file: /// path / to / your / lib / project#egg = MyProject 

这会让你只读从您的应用访问,这对共享代码很有用(例如,项目的 git clone )。请注意,它会指向HEAD。这应符合要求1,2,3。



对于项目布局,您可以查看 setuptools文档;例如创建一个 setup.py 和一个包含你的代码的包。您可以查看一个很好的示例< requests / a>。

应用程序需求文件

  git:// git.myproject.org/MyProject.git#egg=MyProject 

这个应该选择你推送的任何代码到你的回购。我没有Heroku的使用经验,但是如果他们支持应该只是工作的需求文件。这应该符合要求1,我希望4。



如果您想使用私有git回购与heroku,请参考heroku文档(请注意,它是用户名:密码基本身份验证和没有电子邮件地址)。如果你不想使用密码,你可以使用可撤销的OAuth令牌


I have 2 Heroku apps, both Pyhon, and some python modules that are shared between them (i.e.: they are the same in both apps). What is the best way to set up my git / requirements.txt to achieve the following?

  1. The shared code is versioned (that is: it too sits in Git, I don't care where -- one of the projects? Another project?)
  2. In development, I have a single copy of that shared code on my disk
  3. In development, I can change that single copy of the shared code and have the change reflected in both apps, ideally without doing anything other than changing files on disk.
  4. When pushing to Heroku, all I do is a simple "push"

My gut feeling tells me I need to have the shared code as a Python package, on disk, and in development add it to each app's PYTHONPATH. Further, I would add it (how? using a private server? from s3? as a vendor dir?) to the requriments.txt on each app.

... but I can't quite nail it.

Any thoughts?

解决方案

You can use pip requirements files to do that. You may have one for local development and one for your apps. Please check out the requirements file format for more info.

Local development requirements file

file:///path/to/your/lib/project#egg=MyProject

This should give you readonly access from your app, which is useful for shared code (e.g. git clone of a project). Please note that it will point to HEAD. This should fit requirements 1, 2, 3.

For the project layout, you can check out the setuptools documentation; e.g. create a setup.py and a package with your code in it. You can look at the requests library which is a good example.

App requirements file

git://git.myproject.org/MyProject.git#egg=MyProject

This should pick up whatever code you pushed to your repo. I don't have experience with Heroku, but if they support requirements file that should just work. This should fit requirement 1, and I hope 4.

If you want to use private git repo with heroku, please refer to heroku documentation (please note that it is username:password basic auth and does not have email address). If you don't want to use a password you can use a revocable OAuth token.

这篇关于在Heroku应用程序之间共享Python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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