mu-editor / pup

Pluggable Micro Packager
MIT License
14 stars 5 forks source link

Feature request: `--build-dir` flag to change the build directory #242

Open carlosperate opened 1 year ago

carlosperate commented 1 year ago

This is because when using docker to build an AppImage for Mu, if we mount the Mu repository from the host (in my case macOS) as a volume inside the docker container (so that it can be build using docker run... commands), it fails to build the AppImage.

To illustrate the issue:

$ git clone https://github.com/mu-editor/mu.git
$ cd mu
$ docker run -v $(pwd):/home --rm ghcr.io/mu-editor/mu-appimage:2022.05.01 bash -c "\
  pip install .[dev] && \
  python -m mu.wheels --package && \
  python -m virtualenv venv-pup && \
  ./venv-pup/bin/pip install pup && \
  ./venv-pup/bin/pup package --launch-module=mu --nice-name='Mu Editor' --icon-path=./mu/resources/images/icon.png --license-path=./LICENSE ."

The pup output is:

20221201 231447 I pup pup 1.0.0a17 - starting with PID=160
20221201 231447 I pup.api Package '.': starting.
20221201 231448 I pup.plugins.metadata Collecting metadata for '.'.
20221201 231448 I pup.plugins.metadata Packaging local project at '/home'.
20221201 231448 I pup.plugins.metadata About to run '/home/venv-pup/bin/python -m pip wheel --no-deps /home'.
20221201 231450 I pup.plugins.metadata pip out: Processing /home
20221201 231450 I pup.plugins.metadata pip out:   Preparing metadata (setup.py): started
20221201 231453 I pup.plugins.metadata pip out:   Preparing metadata (setup.py): finished with status 'done'
20221201 231453 I pup.plugins.metadata pip out: Building wheels for collected packages: mu-editor
20221201 231453 I pup.plugins.metadata pip out:   Building wheel for mu-editor (setup.py): started
20221201 231512 I pup.plugins.metadata pip out:   Building wheel for mu-editor (setup.py): finished with status 'done'
20221201 231512 I pup.plugins.metadata pip out:   Created wheel for mu-editor: filename=mu_editor-1.2.0-py3-none-any.whl size=49867188 sha256=f319fd33823f8934df71ad8daddc2998f83387edb885c8de8840a95d638df063
20221201 231512 I pup.plugins.metadata pip out:   Stored in directory: /tmp/pip-ephem-wheel-cache-ww0mianr/wheels/ca/d0/93/fbd585043e7e8c744cf5e0d3d167303a7cb9893e8a403c9bb8
20221201 231512 I pup.plugins.metadata pip out: Successfully built mu-editor
20221201 231513 I pup.api Step 'pup.python-runtime': starting.
20221201 231513 I pup.plugins.download Downloading 'https://github.com/indygreg/python-build-standalone/releases/download/20211017/cpython-3.8.12-x86_64-unknown-linux-gnu-pgo-20211017T1616.tar.zst'...
20221201 231516 I pup.plugins.download Cached in '/root/.local/share/pup/afa233629c00506a066ce8492216a61813d5bd87607db03088ec6aeb831f8168'.
20221201 231620 I pup.plugins.python_runtime Deleting Standard Library test packages...
20221201 231622 I pup.plugins.python_runtime Deleting Platform Config files...
20221201 231622 I pup.api Step 'pup.python-runtime': completed.
20221201 231622 I pup.api Step 'linux.appdir_layout': starting.
20221201 231622 I pup.api Step 'linux.appdir_layout': completed.
20221201 231622 I pup.api Step 'pup.pip-install': starting.
20221201 231622 I pup.plugins.pip_install About to run '/home/build/pup/Mu Editor.AppDir/usr/bin/python3.8 -m pip install --no-warn-script-location build/pup/mu_editor-1.2.0-py3-none-any.whl'.
20221201 231622 C pup Execution failure: [Errno 2] No such file or directory: '/home/build/pup/Mu Editor.AppDir/usr/bin/python3.8'
20221201 231622 C pup Traceback below:
Traceback (most recent call last):
  File "/home/venv-pup/lib/python3.8/site-packages/pup/__main__.py", line 31, in wrapper
    exit_code = command_function(*args, **kw)
  File "/home/venv-pup/lib/python3.8/site-packages/pup/__main__.py", line 82, in package
    return api.package(
  File "/home/venv-pup/lib/python3.8/site-packages/pup/api.py", line 64, in package
    dsp.run_pluggable_step(step)
  File "/home/venv-pup/lib/python3.8/site-packages/pup/dispatcher.py", line 79, in run_pluggable_step
    return self._invoke_plugin(name)
  File "/home/venv-pup/lib/python3.8/site-packages/pup/dispatcher.py", line 68, in _invoke_plugin
    return plugin(self._ctx, self, **kwargs)
  File "/home/venv-pup/lib/python3.8/site-packages/pup/plugins/pip_install.py", line 40, in __call__
    dsp.spawn(
  File "/home/venv-pup/lib/python3.8/site-packages/pup/dispatcher.py", line 99, in spawn
    return spawn.spawn(command, out_callable, err_callable, encoding, env=env)
  File "/home/venv-pup/lib/python3.8/site-packages/pup/spawn.py", line 30, in spawn
    child = subprocess.Popen(
  File "/python/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/python/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/build/pup/Mu Editor.AppDir/usr/bin/python3.8'
20221201 231623 I pup pup 1.0.0a17 - done

However, by changing the build directory set in this file, to a different path not monted from the host (for example from build to /build), and running the same steps in a container bash session works. (And just to double check, running the original unmodified steps in a docker container bash session does fail the same way).

https://github.com/mu-editor/pup/blob/55bf81d7f5395910639ad384dd0db8665bc2ea2b/src/pup/plugins/dirs.py#L8-L11

I'm not 100% what the issue might be, but I woudn't be surprised if AppImageBuildKit (or whatever the build engine is) is trying to create symlinks and that somehow fails as the thing it point to does not exist in the host OS filesystem.

So, if we could have a --build-dir flag (or similarly named), we could avoid this issue and add a new Makefile target in the Mu project to build an AppImage using docker.

carlosperate commented 1 year ago

A current workaround could be to mount the local mu repository in a subdirectory (/home/mu instead of /home), and call the pup command from the parent folder (/home), so that the build folder (/home/build) does not end up in the directory mounted from the host:

docker run -v $(pwd):/home/mu --rm ghcr.io/mu-editor/mu-appimage:2022.05.01 bash -c "\
  cd mu && \
  pip install .[dev] && \
  python -m mu.wheels --package && \
  cd .. &&
  python -m virtualenv venv-pup && \
  ./venv-pup/bin/pip install pup && \
  ./venv-pup/bin/pup package --launch-module=mu --nice-name='Mu Editor' --icon-path=./mu/mu/resources/images/icon.png --license-path=./mu/LICENSE mu/ && \
  ls -la dist/ && \
  mv dist mu/dist"