uv: Race condition when two libraries update the same __init__.py
This has had me pulling my hair out.
If pydantic is enabled in the requirements.txt, pyjwt fails with
#12 7.705 Traceback (most recent call last):
#12 7.705 File "<string>", line 1, in <module>
#12 7.706 ImportError: cannot import name 'PyJWKClient' from 'jwt' (/opt/venv/lib/python3.12/site-packages/jwt/__init__.py)
Looks like the init.py doesnt get updated with PyJWKClient in the failed runs, but no indication as to why.
Cant make it fail deterministically but doing docker system prune, it will fail every other (?) time.
Here is the Dockerfile:
FROM python:3.12.3 AS build
ENV PATH="/opt/venv/bin:$PATH"
ENV VIRTUAL_ENV="/opt/venv"
# Python runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
make \
g++ \
gfortran \
cmake && \
python -m venv /opt/venv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
WORKDIR /app
COPY requirements.txt ./
RUN echo 1 && \
uv pip -v --no-cache sync requirements.txt &&\
python -c "from jwt import PyJWKClient"
Here is the requirements.txt:
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in pyproject.toml
annotated-types==0.7.0
# via pydantic
anyio==3.7.1
# via
# fastapi
# starlette
certifi==2022.12.7
# via requests
cffi==1.17.0
# via cryptography
charset-normalizer==2.1.1
# via requests
cryptography==43.0.0
# via jwt
# fastapi==0.105.0
# via -r requirements.in
google-search-results==2.4.2
# via locus-ferb (pyproject.toml)
idna==3.4
# via
# anyio
# requests
jwt==1.3.1
# via locus-ferb (pyproject.toml)
pycparser==2.22
# via cffi
pydantic==2.8.2
# via fastapi
pydantic-core==2.20.1
# via pydantic
pyjwt==2.9.0
# via locus-ferb (pyproject.toml)
requests==2.28.1
# via
# google-search-results
# serpapi
serpapi==0.1.5
# via locus-ferb (pyproject.toml)
sniffio==1.3.1
# via anyio
# starlette==0.27.0
# via fastapi
typing-extensions==4.9.0
# via
# fastapi
# pydantic
# pydantic-core
urllib3==1.26.13
# via requests
Attached are the two logs, running the same command one after the other:
docker system prune && docker build --ssh default --progress plain -f Dockerfile-fail .
build-working.log
build-failing.log
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (8 by maintainers)
I see. I don’t know if it’s feasible for us to unpack packages in a defined order like that, @charliermarsh would know better.
It seems like pretty bad behavior for a package to rely on patching an existing one by overwriting its files. I think in this case, you’d be best off running two separate install operations — one to prepare the environment, and the next to patch the package.