[Python] avoid building .egg-info files in read-only docker mount for local dependencies (uv...

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use uv sync from within docker with this command:

    Dockerfile

    RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
    --mount=type=bind,source=packages,target=/app/packages \
    uv sync --package ftp-mock --locked --no-editable


    However this wants to create .egg files which fails because I mounted the packages folder as read only (and I want to keep it this way). This is my current project layout:

    .
    ├── packages
    │ ├── ftp-mock
    │ │ ├── config
    │ │ │ ├── config_dev.json
    │ │ │ └── ftp_mock_config.py
    │ │ ├── Dockerfile
    │ │ ├── ftp_mock.py
    │ │ └── pyproject.toml
    │ ├── http-mock
    │ │ ├── config
    │ │ │ ├── config_dev.json
    │ │ │ └── http_mock_config.py
    │ │ ├── Dockerfile
    │ │ ├── pyproject.toml
    │ │ ├── http_mock.py
    │ │ └── templates
    │ │ └── index.html
    │ ├── local-shared
    │ │ ├── __init__.py
    │ │ ├── pyproject.toml
    │ │ ├── mymodule.py
    │ ├── main-app
    │ │ ├── config
    │ │ │ ├── config_dev.json
    │ │ │ └── main_app_config.py
    │ │ ├── Dockerfile
    │ │ ├── pyproject.toml
    │ │ └── main_app.py
    │ └── __init__.py


    ...

    As you can see I'm only trying to build the workspace-member ftp-mock which in turn requires local-shared. Now uv sync tries to install local-shared which creates the .egg-info file (or rather it tries and fails because it only has read access to the mount). How can I avoid polluting my the directory with the egg file (or any new files for that matter) so that docker stops complaining?

    Here's the exact error from docker:

    > [builder 4/6] RUN --mount=type=cache,target=/root/.cache/uv --mount=type=bind,source=uv.lock,target=uv.lock --mount=type=bind,source=pyproject.toml,target=pyproject.toml --mount=type=bind,source=packages,target=/app/packages uv sync --project ftp-mock --package -ftp-mock --no-install-project --locked --no-editable:
    0.382 Using CPython 3.11.12 interpreter at: /usr/local/bin/python3
    0.382 Creating virtual environment at: .venv
    0.384 Resolved 15 packages in 1ms
    0.385 Building local-shared @ file:///app/packages/local-shared
    0.588 Downloading pydantic-core (1.9MiB)
    0.660 Building pyftpdlib==2.0.1
    0.693 Downloading pydantic-core
    3.815 × Failed to build `local-shared @ file:///app/packages/local-shared`
    3.815 ├─▶ The build backend returned an error
    3.815 ╰─▶ Call to `setuptools.build_meta.build_wheel` failed (exit status: 1)
    3.815
    3.815 [stdout]
    3.815 running egg_info
    3.815 creating local_shared.egg-info
    3.815
    3.815 [stderr]
    3.815 error: could not create 'local_shared.egg-info': Read-only file system
    3.815
    3.815 hint: This usually indicates a problem with the package or the build
    3.815 environment.
    3.815 help: `local-shared` was included because `ftp-mock` (v0.1.0) depends
    3.815 on `local-shared`
    ------
    Dockerfile:10
    --------------------
    9 | # # Uses a cache to speed up the build. To clear the cache run docker with the --no-cache flag
    10 | >>> RUN --mount=type=cache,target=/root/.cache/uv \
    11 | >>> --mount=type=bind,source=uv.lock,target=uv.lock \
    12 | >>> --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
    13 | >>> --mount=type=bind,source=packages,target=/app/packages \
    14 | >>> uv sync --project ftp-mock --package ftp-mock --no-install-project --locked --no-editable
    15 |
    --------------------
    ERROR: failed to solve: process "/bin/sh -c uv sync --project ftp-mock --package ftp-mock --no-install-project --locked --no-editable" did not complete successfully: exit code: 1

    Continue reading...

Compartilhe esta Página