niess / python-appimage

AppImage distributions of Python
https://python-appimage.readthedocs.io/en/latest/
GNU General Public License v3.0
170 stars 24 forks source link

Python Environment Does Not Work Under Directories With Spaces #55

Closed whinee closed 1 year ago

whinee commented 1 year ago

Summary

Type: Bug

Explanation

Python environments made with the current AppImage does not work when put inside a directory with a space in it.

Proposed Solution

At python_appimage/data/python-wrapper.sh, line 7, column 28 to 30 (the $0) needed to be encapsulated with double quotation marks (").

Environment

OS: Arch Linux Kernel: 5.19.7-arch1-1 Shell: zsh 5.9 (x86_64-pc-linux-gnu) AppImage: python3.9.14-cp39-cp39-manylinux2014_x86_64.AppImage

Explanation

Greetings! Let it be known that I do not have a lot of expertise in this kind of stuff.

To start, I've been using your python appimages to make a python environment if the version is not available at my package manager (I use Arch Linux, and AUR does not keep older versions of python, nor does it for any other programs).

In any case, this works well for me. I've never had any problems with it for a month that I've been using it. But it had been at least a month since I last touched that thingy. And now, I tried to make a python environment using a python 3.9 appimage, as the service that my project deploys to does not have python 3.10 available.

In any case, this fails specifically at the point where the python environment tries to install pip. This is an example of the error:

Error: Command '['/home/whinee/directory with space/project/pyenv/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 127.
pyenv:source:19: no such file or directory: pyenv/bin/activate
/home/whinee/projects/personal/directory with space/project/pyenv/bin/python: line 25: /home/whinee/opt/python3.9/bin/python3.9: No such file or directory
/home/whinee/projects/personal/directory with space/project/pyenv/bin/python: line 25: /home/whinee/opt/python3.9/bin/python3.9: No such file or directory
/home/whinee/projects/personal/directory with space/project/pyenv/bin/python: line 25: /home/whinee/opt/python3.9/bin/python3.9: No such file or directory

How to Replicate

tmpf=$(mktemp)
wget -O "$tmpf" "$(wget -qSO - "https://api.github.com/repos/niess/python-appimage/releases/tags/python$pyver" 2>/dev/null | grep -E "browser_download_url.*x86_64" | cut -d'"' -f4 | tail -2 | head -1)" >/dev/null
chmod +x "$tmpf"
"$tmpf" --appimage-extract >/dev/null
rm -rf "$tmpf" pyenv/
mkdir pyenv
mv squashfs-root/opt squashfs-root/usr pyenv/
pyenv/usr/bin/python -m venv pyenv/ # point of failure

With this, the last command should fail with the following error:

Error: Command '['$HOME/a/b/c d/e/pyenv/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 127.
pyenv:source:19: no such file or directory: pyenv/bin/activate
$HOME/a/b/c d/e/pyenv/bin/python: line 25: $HOME/opt/python3.9/bin/python3.9: No such file or directory
$HOME/a/b/c d/e/pyenv/bin/python: line 25: $HOME/opt/python3.9/bin/python3.9: No such file or directory
$HOME/a/b/c d/e/pyenv/bin/python: line 25: $HOME/opt/python3.9/bin/python3.9: No such file or directory

Tracking Down Bug

I tried to track where this error came from, as the error did not provide any information on what file is throwing this error, and I found it on ./pyenv/opt/python3.9/lib/python3.9/venv/__main__.py, at the part where it tries to install pip, as said earlier.

Well... I though that the thingy running that command just do not have enough quotations. But nawp! So I tried tracing the problem in the scripts, starting from the activate script, and got me to the pyenv/bin/python.

I kinda debugged it, and saw that $APPDIR's value is /home/whinee/ instead of /home/whinee/projects/personal/directory with space/project/pyenv/. So I started fiddling with the quotations, and sure enough, it lacked one. I encapsulated $0 at line 7 with double quotations, and it worked like it should!

Proposed Solution

As said earlier, encapsulating python_appimage/data/python-wrapper.sh, line 7, column 28 to 30 with double quotation marks (") solved the problem for me.

Rationale for Not Opening Pull Request

But you ask:

whi_ne, why didn't you just made a pull request, instead of writing this issue which can be solved by adding literally 2 characters?

Well... many reasons, actually:

Anyways, I hope that this issue will be resolved soon, thanks!

whinee commented 1 year ago

Apologies for not providing enough information regarding this issue. I have been called for dinner last night in the middle of writing this. Will edit right now.

niess commented 1 year ago

Hello @whinee,

Thank you for your detailed report, and for solving this issue :)

I just submitted a patch, based on your findings, that should solve your white space issue. Don't hesitate to let me know if it does not work.

Thanks again for spotting this.

whinee commented 1 year ago

Hello, I just read your comment. Thank you for immediately acting upon this issue.

However, I am unable to test this out for the next 3 days or so due to my school works. But, I will get to you as soon as possible.

Again, thank you!

whinee commented 1 year ago

I lied, I just got the time to test the latest release out. And yep, it is working as expected.

Thank you, @niess, for taking the time to resolve this issue.