Skip to content

poetry install --no-root with only poetry.lockΒ #1301

@eliasmistler

Description

@eliasmistler
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/installerRelated to the dependency installerkind/featureFeature requests/implementations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions