Installing from a read-only source

I’d like to be run a series of regression tests against my package from within a docker container. To do this, I mount the package source into the docker image - but I don’t want changes from within the container to propagate to the host, so I mount it read-only.

But then when I try to install the package into a virtualenv within the container, I see:

root@b2e917cf2b2c:/src# /venv/bin/pip install /src 
Processing /src
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /venv/bin/python3 /venv/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmp2_9mzp35
       cwd: /src
  Complete output (2 lines):
  running egg_info
  error: [Errno 30] Read-only file system
  ----------------------------------------
ERROR: Command errored out with exit status 1: /venv/bin/python3 /venv/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmp2_9mzp35 Check the logs for full command output.

Is there any way to install from local source without modifying the source directory?

The problem is you need a place to build the wheel that will be installed. That means you will want to build the wheel ahead of time and then install that in your container instead of trying to install straight from source.

There has been some discussion on pip issue tracker about the need of out-of-tree builds support for PEP 517, I don’t recall whether someone has opened a thread here about it. This would be one of the use cases.

Alternatively you may try something like this:

tar zcvf /tmp/src.tgz /src
/venv/bin/pip install /tmp/src.tgz

pip will unpack the tarball and build it from a temporary location.

Thank you all for the suggestions; that gives me enough to work with. Certainly it seems to me that out-of-tree builds would be very nice to have. Indeed, it seems that it worked that way until the recent release of pip 20.1: can anyone point me toward what changed and why?

You want to take a look at https://github.com/pypa/pip/issues/7555 and at Proposal: Adding a persistent cache directory to PEP 517 hooks respectively.