How do I install in-house requirements for Python

2019-04-21 10:32发布

We have a few in-house libraries that we've split off (for several reasons, mostly administrative or to have the possibility to easily open source them later). They live in private Github repositories, if that matters.

I'd like to deploy an app to Heroku to try it out. It depends on one of those libraries.

I'm supposed to specify my dependencies in requirements.txt. That's easy for the PyPI-installable stuff, but what do I do for these in-house dependencies?

I could either run my own private PyPI mirror that has this stuff, or I could use editable packages (even though the documentation says they shouldn't be used in production).

What's the appropriate way to do it?

4条回答
贪生不怕死
2楼-- · 2019-04-21 11:02

You can write, say, "-e git+ssh://git@.../PIL#egg=PIL" instead of "PIL" in your requirements.txt file and it'll fetch it from there.

However, this would require you to somehow specify the ssh private key to be used by heroku when pulling.

查看更多
家丑人穷心不美
3楼-- · 2019-04-21 11:05

GitHub allows HTTP Basic authentication on Git repos.

So, you can add a line like this:

-e git+https://username:password@github.com/kennethreitz/requests.git@v0.10.0#egg=requests

And everything will work properly :)

查看更多
冷血范
4楼-- · 2019-04-21 11:08

There is a buildpack for just this: https://elements.heroku.com/buildpacks/debitoor/ssh-private-key-buildpack

Do this:

$ heroku buildpacks:set --index 1 https://github.com/debitoor/ssh-private-key-buildpack.git
$ heroku buildpacks:add heroku/python
$ heroku config:set SSH_KEY="$(cat path/to/your/keys/id_rsa | base64)"

Now add given ssh key to github and you can use those "git+git@github.com" dependencies when deploying to Heroku.

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-04-21 11:16

In requirements.txt you can mention like the following.

git+git://github.com/kracekumar/blaze.git

Meanwhile you can clone the library and create virtual environment and install inside the env. Heroku dev center has articles including virtual env set up.

查看更多
登录 后发表回答