0

I have a python package that I want to install inside a docker file.
pyproject.toml looks like:
[build-system]
requires = [“setuptools>=61.0”]
build-backend = “setuptools.build_meta”

[project]
name = “bar”
dependencies = [
“pandas”,
]

[project.optional-dependencies]
foo = [
“matplotlib”,
]

… and Dockerfile:
# …
WORKDIR /app
COPY . /app
RUN pip install /app

This installs the dependencies (in this example, pandas) on every build, which I want to avoid to save developer time, since pyproject.toml is rarely touched.
How can I install only pandas (the dependencies listed pyproject.toml) without having to COPY . and installing bar.
I want to avoid:

adopt other tools like poetry
create a requirements.txt and use dynamic keyword in pyproject.toml, because I have optional-dependencies and I want to keep the list of dependencies as close together (i.e. same file) as possible.

Something like:
# …
WORKDIR /app
COPY ./pyproject.toml /app/
RUN pip install –requirements-from /app/pyproject.toml # <-- HERE COPY . /app RUN pip install /app # <-- Installs `bar` only. All dependencies already installed.

Kuldeep Baberwal Changed status to publish February 17, 2025