Background:
I'm trying to build a python project with a git submodule inside a Docker container. For handling all dependencies I am using poetry version 1.4. My Docker container is based on the python:3.11.3-slim image and the Dockerfile is mostly the same as the multi stage example from this stackoverflow answer.
Simplified file structure (only relevant files):
project
│ Dockerfile
│ poetry.lock
│ pyproject.toml
│
└───main module
│ │ cli.py
│ │
│ └───main_module_name
│ │ main_module.py
│
└───submodule
│ │ Dockerfile
│ │ poetry.lock
│ │ pyproject.toml
│ │
│ └───module_name
│ │ cli.py
│ └───subfolder
│ │ submodule.py
Problem:
When I'm importing the submodule on my local development machine I have to specify the full path including the top level folder ('submodule' folder) of the submodule.
But in my Docker container the submodule is installed inside /venv/lib/python3.11/site-packages/
without the top level folder, so that the import of the module fails because of the changed folder structure.
I tried to install the .whl
file of the submodule like this:
RUN poetry build && /venv/bin/pip install dist/*.whl --target path/to/target
but then pip installs the site packages from the /venv/lib/python3.11/site-packages/
also in my top level submodule folder. Furthermore I don't want to use an absolute path, so that I can use this project as a template for other project where I might use a different base image.
My current temporary solution copies the sitepackage folder of the submodule after installation with some bash commands:
RUN export source_path=$(/venv/bin/pip show module-name | grep Location | cut -d ' ' -f2)/module_name/
&& export destination_path=$(/venv/bin/pip show module-name | grep Location | cut -d ' ' -f2)/submodule/
&& mkdir -p $destination_path
&& mv $source_path $destination_path
This solution is working, but I think there should be a proper way to install the submodule correctly from the start.
Do you know why the folderstructure is off?
Do you know a better way to fix this problem?