pleiszenburg / wenv

Running Python on Wine
GNU Lesser General Public License v2.1
19 stars 1 forks source link

make wenv work with a read-only prefix - fallback to $HOME/.cache/wenv #22

Open milahu opened 3 months ago

milahu commented 3 months ago

by default, wenv fails with a read-only prefix

>>> import zugbruecke.ctypes as ctypes
OSError: [Errno 30] Read-only file system: '/nix/store/12hx5iv7v4jw64p4fwzx2cjwpdzh2gpf-python3-3.11.7-env/share/wenv'

wenv/_core/env.py

    def ensure(self):
        self.setup_wineprefix()
    def setup_wineprefix(self, overwrite: bool = False):
        os.makedirs(
            self._p["wineprefix"]
        )

wenv/_core/config.py

        if key == "prefix":
            install_location = os.path.abspath(__file__)
            if install_location.startswith(
                site.USER_BASE
            ):  # Hacky way of looking for a user installation
                return site.USER_BASE
            return sys.prefix
        if key == "wineprefix":
            return os.path.join(self["prefix"], "share", "wenv", self["arch"])

workaround: set env WENV_WINEPREFIX=/some/where/else or WENV_PREFIX=/some/where/else

import os
os.environ["WENV_PREFIX"] = os.environ["HOME"] + "/.cache/wenv"
import zugbruecke.ctypes as ctypes

expected: if the default wineprefix is read-only then fallback to $HOME/.cache/wenv/wine via platformdirs

similar #14

s-m-e commented 3 months ago

Having this kind of fallback is certainly a good idea. Added to my todo - though PR welcome ;)

milahu commented 3 months ago

two seconds ^^

ideally i want to setup the wine env only once in the read-only package store so im running wenv init as part of the build process just the default wineprefix is wrong, its based on the python interpreter location...

milahu commented 3 months ago

related issue:

this will not work with unpatched wine

wine/libs/wine/config.c

    if (st.st_uid != getuid()) fatal_error( "%s is not owned by you\n", config_dir );

wine complains about the ownership of WINEPREFIX

$ ./result/bin/wenv python
wine: '/nix/store/mcbrxyi2q7kksyrxm7px9l0ik3rxv94h-wenv-0.5.1/share/wenv/win32' is not owned by you

WINEPREFIX is not owned by you

i found many discussions on this problem but no solution to make wine ignore the ownership workarounds: sudo, chown, symlinks, bind mount, LD_PRELOAD, ...


but this issue remains:

if the default WENV_PREFIX is read-only then wenv should fallback to $HOME/.cache/wenv

ideally the "cache" config should be a list of paths for reading from the cache, all cache paths are used for writing to the cache, the first writable cache path is used