Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created May 17, 2024 00:41
Show Gist options
  • Save inklesspen/4de53c385d207624bd2766728ce1c6c6 to your computer and use it in GitHub Desktop.
Save inklesspen/4de53c385d207624bd2766728ce1c6c6 to your computer and use it in GitHub Desktop.

These two examples show building a meson-python package in editable (-e) mode without the --no-build-isolation flag.

The package in question is my meson-python-cffi-example. It requires fontconfig libraries and headers to be present, along with at least a couple of fonts. It depends on cffi both at build time and runtime.

The example Dockerfiles are based on buildpack-deps, a Debian-based container. The only difference between them is whether meson and ninja are installed using the system package tool.

Build (with Docker)

$ docker build -f Dockerfile.working -t example:working .
$ docker build -f Dockerfile.not-working -t example:not-working .

Working example

docker run --rm -it example:working
['/usr/share/texmf/fonts/opentype/public/tex-gyre/texgyrepagella-regular.otf']

Not-working example

docker run --rm -it example:not-working
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1080, in _find_spec
  File "/home/builder/myvenv/lib/python3.11/site-packages/_meson_python_cffi_example_editable_loader.py", line 310, in find_spec
    tree = self._rebuild()
           ^^^^^^^^^^^^^^^
  File "/home/builder/myvenv/lib/python3.11/site-packages/_meson_python_cffi_example_editable_loader.py", line 343, in _rebuild
    subprocess.run(self._build_cmd, cwd=self._build_path, env=env, stdout=subprocess.DEVNULL)
  File "/usr/lib/python3.11/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-env-yfxix8xz/normal/bin/ninja'
FROM buildpack-deps
RUN apt update && apt install -y python3-venv python3-dev fonts-texgyre
RUN adduser --disabled-password --comment "" builder
USER builder
WORKDIR /home/builder
RUN python3 -m venv myvenv
RUN git clone https://github.com/inklesspen/meson-python-cffi-example.git
WORKDIR /home/builder/meson-python-cffi-example
# specific known commit (current HEAD)
RUN git checkout b83508b99c0edd719475d4f4d5b1cb35e2ef2a50
RUN /home/builder/myvenv/bin/pip install -e .
CMD ["/home/builder/myvenv/bin/python3", "-c", "import meson_python_cffi_example.fontconfig; print(meson_python_cffi_example.fontconfig.match_pattern('TeX Gyre Pagella'))"]
FROM buildpack-deps
RUN apt update && apt install -y python3-venv python3-dev fonts-texgyre meson ninja-build
RUN adduser --disabled-password --comment "" builder
USER builder
WORKDIR /home/builder
RUN python3 -m venv myvenv
RUN git clone https://github.com/inklesspen/meson-python-cffi-example.git
WORKDIR /home/builder/meson-python-cffi-example
# specific known commit (current HEAD)
RUN git checkout b83508b99c0edd719475d4f4d5b1cb35e2ef2a50
RUN /home/builder/myvenv/bin/pip install -e .
CMD ["/home/builder/myvenv/bin/python3", "-c", "import meson_python_cffi_example.fontconfig; print(meson_python_cffi_example.fontconfig.match_pattern('TeX Gyre Pagella'))"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment