`poetry install --no-root` with only poetry.lock
See original GitHub issue- I have searched the issues of this repo and believe that this is not a duplicate.
- I have searched the documentation and believe that my question is not covered.
Feature Request
When doing poetry install, both pyproject.toml and poetry.lock are required. This makes sense as the package itself is installed along with its dependencies.
However, this breaks caching in Docker. Let’s say I have these lines in docker:
COPY pyproject.toml poetry.lock README.md /
RUN poetry install --no-dev
(Note how I also need the README.md as that is referenced in the pyproject.toml)
The main problem here is: On every build, I bump the version using poetry version .... This changes the pyproject.toml file, therefore breaks the docker caching mechanism. In comparison, with an additional requirements.txt, I can do something like:
COPY requirements.txt /
RUN pip install -r requirements.txt
COPY pyproject.toml poetry.lock README.md /
RUN poetry install --no-dev
In this case, all the dependencies (which quite often do not change between builds) can be cached. This speeds up my docker build by 80-90%, but it’s obviously ugly to have to rely on requirements.txt
FYI: I have a workaround for requirements.txt, where I simply generate it from poetry.lock:
def _poetry_lock_to_requirements_txt(start_dir):
with open(f'{start_dir}/poetry.lock') as f:
lock = toml.load(f)
requirements = {package['name']: package['version']
for package in lock['package']}
with open(f'{start_dir}/requirements.txt', 'w') as f:
f.writelines(f'{name}=={version}\n' for name, version in sorted(requirements.items()))
Alternatively, I could do some trickery around when to (re-)set the version, but this is getting uglier and uglier [plus I need requirements.txt anyway due to an other issue with poetry that I find really hard to pin down - more on that soon]
I would suggest adding the flag poetry install --dependencies-only which only requires poetry.lock, not pyproject.toml
Issue Analytics
- State:
- Created 4 years ago
- Reactions:103
- Comments:37 (8 by maintainers)
Top Related StackOverflow Question
Honest question, why would you use poetry to set up a container? pip (with
exportfrom preview builds, as dmontagu pointed out) is enough. See here for a stack overflow post where someone had a different problem with using poetry in docker, where just using pip seems a good alternative.This issue is related to #1899. I posted my current solution for caching there, and I’ll post it here too, if it might help anyone: