J21042
J21042

Reputation: 1284

Python requirements.txt use local git dependency

I have a small python flask app on a CentOS-7 VM that runs in docker, along with an nginx reverse proxy. The requirements.txt pulls in several external utilities using git+ssh such as:

git+ssh://path-to-our-repo/some-utility.git

I had to make a change to the utility, so I cloned it locally, and I need the app to use my local version. Say the cloned and modified utility is in a local directory:

/var/work/some-utility

In the requirements.txt I changed the entry to:

git+file:///var/work/some-utility

But when I try to run the app with

sudo docker-compose up

I get the error message

Invalid requirement: 'git+file:///var/work/some-utility'
it looks like a path. Does it exist ?

How can I get it to use my local copy of "some-utility" ?

I also tried:

git+file:///var/work/some-utility#egg=someutility

but that produced the same error.

I looked at PIP install from local git repository.

This is related to this question:

https://stackoverflow.com/questions/7225900/how-to-pip-install-packages-according-to-requirements-txt-from-a-local-directory?rq=1

I suppose most people would say why not just check in a development branch of some-utility to the corporate git repo, but in my case I do not have privileges for that.

Or maybe my problem is related to docker, and I need to map the some-utility folder into the docker container, and then use that path? I am a docker noob.

--- Edit ---

Thank you larsks for your answer. I tried to add the some-utility folder to the docker-compose.yml:

volumes:
  - ./some-utility:/usr/local/some-utility

and then changed the requirements.txt to

git+file:///usr/local/some-utility

but our local git repo just went down for maintenance, so I will have to wait a bit for it to come back up to try this.

=== Edit 2 ===

After I made the above changes, I get the following error when running docker-compose when it tries to build my endpoint app:

Cloning file:///usr/local/some-utility to /tmp/pip-yj9xxtae-build
fatal: '/usr/local/some-utility' does not appear to be a git repository

But the /usr/local/some-utility folder does contain the cloned some-utility repo, and I can go there and run git status.

Upvotes: 4

Views: 3153

Answers (1)

larsks
larsks

Reputation: 312410

If you're running pip install inside a container, then of course /var/work/some-utility needs to be available inside the container.

You can expose the directory inside your container using a host volume mount, like this:

docker run -v /var/work/some-utility:/var/work/some-utility ...

Upvotes: 1

Related Questions