Reputation: 1940
This is a pretty specific ask, so I'm open to helpful suggestions that get part of the way there.
I have a python project that runs inside a docker container configured to work with the Pycharm debugger. I have a package, installed in a virtual env with pip, used in this project, that I'd like to develop on.
I haven't found a way to link the package into my project's docker container in such a way that I can change the package and have the code update in my project. Currently, the debugger works on codepaths that enter into the package, as long as I don't change any code in the package.
These two problems combined make it hard to test changes to the package without installing it over and over.
Is there a better way to accomplish this goal?
Upvotes: 3
Views: 540
Reputation: 1940
I think I've covered all the bases I outlined above with this system:
My project structure is:
projects
projectA (my docker project)
projectB (the library used in my docker project that I want to develop on)
In projectA: project settings -> project interpreter -> add path mappings -> map local library path to remote install path on container
ex. local path: /user/{username}/projects/projectB remote path: /usr/local/lib/python3.6/site-packages/projectB
In projectA: project settings -> project structure -> add content root (projectB) -> choose mark as sources
In projectA: mark path on to projectB in container as a volume in dockerfile
ex. VOLUME /usr/local/lib/python3.6/site-packages/projectB
In projectA: load local library as volume to library installation on container in docker-compose.yml
ex.
volumes:
- ../projectB:/usr/local/lib/python3.6/site-packages/projectB
Using python 3.6 and Pycharm 2018.2
Upvotes: 1
Reputation: 159382
Given the two source trees that should work together:
python -m venv vpy
.. vpy/bin/activate
.cd library && pip install -e .
(-e
causes pip to remember a pointer to the live source tree.)cd app && pip install -e .
. (Pip should know you already have the library installed.)$EDITOR file.py; pytest; the_app; $SCM commit
.docker build && docker run
.I'd leave any interaction with Docker until the very end, once you've convinced yourself you've fixed the library bug or built the feature. That avoids troubles with your editor and the container disagreeing on paths, and it means you don't need root privileges for any of your ordinary development work.
Upvotes: 1
Reputation: 4765
You can try using combination of what @pbskumar proposed and docker volumes.
First run your container with option --volume /path/to/your/package/on/host/:/path/in/your/container
And then you execute this inside the container:
pip install -e /path/in/your/container
It should work.
Upvotes: 0
Reputation: 1157
Install the package in editable mode.
pip install -e .
This will allow you to make changes to the code and update the package simultaneously.
Upvotes: 0