I am building a Dockerfile, using Python, with hatch as a build manager. I want to install dependencies separately from compiling py => pyc files, so that when my code changes I can cache the dependencies (which can take a while to redownload and install).
I'm not sure how I can build the dependencies in hatch as a separate step. (Maybe I can't read the hatch docs, but it doesn't seem to mention it anywhere)
My dockerfile looks something like (simplified)
FROM python
RUN python -m pip install hatch
COPY . /
RUN hatch build
I'd like to change it to
FROM python
RUN python -m pip install hatch
COPY pyproject.toml /
RUN hatch build-deps # this step should be cached if a different file is changed
COPY . /
RUN hatch build # this step shouldn't re-install deps again
Is this possible?
You could use hatch to extract the requirements out of the
pyproject.toml, install those using pip, and then install your project in a second step:The disadvantage is that if any change is made to
pyproject.tomlthat is not related to the dependencies, these will still be reinstalled the next time you create the container.