python-poetry / python-poetry/poetry
`poetry install --no-root` with only poetry.lock
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 34.3k
- Forks
- 2.5k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 30
Description
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the poetry install --no-root command and the pyproject.toml and poetry.lock inputs described in the issue. Review the Dockerfile caching example and the existing --no-dev behavior, then determine how completion should work when only the lockfile is available. Done means the dependency installation can be cached without requiring version changes in pyproject.toml.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- cli, devops
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100