Heroku 上 Django 应用程序的条件 pip 安装要求 [英] Conditional pip install requirements on Heroku for Django app

查看:19
本文介绍了Heroku 上 Django 应用程序的条件 pip 安装要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说,我认为没有办法做到这一点......但是,那里有很多聪明人,所以我想我会问!:)

Let me start by saying, that I don't think there is a way to do this... but, there are a lot of clever people out there and so I thought I would ask! :)

我找到了 Randall Degges 关于在 Heroku 上设置 Django 应用程序 (互联网档案链接).我真的很喜欢他关于将您的需求分解成不同文件(common.txt、dev.txt、prod.txt 等)的说法.

I found a good article/post by Randall Degges on setting up a Django app on Heroku (Internet Archive link). I really like what he has to say about breaking your requirements up into different files (common.txt, dev.txt, prod.txt etc).

这在 Heroku 上非常适合用于生产,但我还在 Heroku 上维护了一个 Dev/QA 站点,并且我有一些我确实不需要用于开发/QA 的生产包.最好的例子是 django-debug-toolbar.目前,我的生产需求.txt 中确实有这个,并且我在运行时通过查看 DEBUG 设置动态决定是否需要将它添加到 settings.py 中的已安装应用程序等中.

This works great on Heroku for production, but I also maintain a Dev/QA site on Heroku, and I have a few packages that I don't really need for prod that I do use for Dev/QA. The best example is django-debug-toolbar. Currently, I do have this in my production requirements.txt, and I dynamically decide if I need to add it to my installed apps, etc in settings.py at runtime by looking at the DEBUG setting.

哪个工作正常......但是,如果我什至不费心在产品中安装它,那就太好了.我想我想要的是 pip 能够获取一个允许条件包含的需求文件(为什么不能只获取一个 python 文件?)或者让 Heroku 支持一个配置设置,告诉它哪个需求文件使用.有没有人找到实现这一目标的方法?还是只是一厢情愿?

Which works fine... but, it would be great if I could not even bother about installing it in prod. I guess what I sort of want is for pip to be able to take a requirements file that allows for conditionals includes (why couldn't it just take a python file?) or for Heroku to support a config setting that tells it which requirements file to use. Has anyone found a way of accomplishing this? Or is it just wishful thinking?

推荐答案

你有没有研究过这个?

如果您的 Python 应用程序包含 setup.py 文件但不包括 requirements.txt 文件,python setup.py develop 将用于安装您的包并解决您的依赖项.这对分发或设置工具最有效.直接使用 distutils 的项目将被安装,但不会链接.模块不会得到更新,直到出现版本碰撞.如果您已经有一个需求文件但想要使用此功能,您可以将以下内容添加到您的需求文件中:

-e .

然后按照有条件地在python2.6上安装importlib

这篇关于Heroku 上 Django 应用程序的条件 pip 安装要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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