pleiszenburg / zugbruecke

Calling routines in Windows DLLs from Python scripts running under Linux, MacOS or BSD
https://zugbruecke.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
112 stars 11 forks source link

Mechanism to chose wine prefix ? #44

Closed stuaxo closed 4 years ago

stuaxo commented 5 years ago

It would be handy to have a way to chose the wine prefix used.

This would be handy when I want to use a wine environment that already has some programs installed.

(In my instance I was trying with Winamp / WACUP)

s-m-e commented 5 years ago

@stuaxo Good idea - I will add an option that allows a user to point to an existing wine prefix.

stuaxo commented 5 years ago

Great :)

It would be great to document the API the sets up zugbruecke with a wine prefix too.

Is there an easy way to check if a prefix is already setup with zugbruecke?

s-m-e commented 5 years ago

Currently, zugbruecke creates its own wine-prefix underneath its configuration folder, see here and here. The pattern is {path_to_home}/.zugbruecke/{arch}-wine where arch can be either win32 (default) or win64. {path_to_home} can also be replaced by something like /etc if you're installing system-wide (not recommended). In the early phase of the development of this package, I was messing around with different wine configuration options (like Windows version / API level support), so I did not want to destroy a user's wine-prefix - this was one of the reasons why I have intentionally kept this stuff separated / isolated. But if you really want to use a pre-existing environment, why not - I can modify the configuration logic to allow that.

s-m-e commented 5 years ago

Ok, I need some more time for this - it's not a 10 minute fix as I thought, unfortunately. I have hard-coded the pattern {path_to_home}/.zugbruecke/{arch}-wine in a few placed, i.e. I need to refactor some code before I can clean this up ...

s-m-e commented 5 years ago

@stuaxo I have pushed a new branch, refactor_moduledesign. It is still under development and not finalized yet. Among quite a lot of changes, I also added a new configuration parameter: wineprefix. In .zugbruecke.json, you can set it to a path of your choice. Please test.

Be aware that there are significant changes to the module layout, see change log. It might be necessary to run wenv init after you have installed the package for completing the installation process. If you go through the make file (make install or make install_link) the latter will be done for you automatically. For more details see wenv help.

stuaxo commented 5 years ago

Cheers, I'll give this a go.

stuaxo commented 5 years ago

I tried this, with the following .zugbruecke.json

{
    "wineprefix": "test-wacup"
}

This didn't work as it wants an absolute path. Would it be possible to support setting name like this, but the wineprefix still ending up in the default directory for zugbruecke wineprefixes ?

s-m-e commented 5 years ago

@stuaxo Thanks for testing. Yes, it's possible, but I am wondering about the semantics. wineprefix does not need to be absolute. Currently, it can also be relative to the current working directory. The question then becomes how you want to indicate that you want the path to be relative to something else other than the cwd. I could add another configuration option ... I am open to ideas and suggestions.

In this context, I am considering another design change related to the above: Currently, the wineprefix resides together with the configuration in {path_to_home}/.zugbruecke/. This basically means that both the wineprefix and the configuration can not easily be isolated for different installations of zugbruecke in different virtual environments. I am thinking about moving this stuff into the shared folder of the currently active virtual environment for improved isolation. Alternatively, this could become an optional feature as well. Thoughts and criticism are highly welcome.

stuaxo commented 5 years ago

Maybe support use expanduser so ~ can be used as part of a path?

I can see why you may not want general env var support without a bit more thought.

stuaxo commented 5 years ago

Maybe where the prefix is saved and what it's called are two settings (with sane defaults)?

s-m-e commented 5 years ago

I tried this, with the following .zugbruecke.json

{
    "wineprefix": "test-wacup"
}

This didn't work as it wants an absolute path. Would it be possible to support setting name like this, but the wineprefix still ending up in the default directory for zugbruecke wineprefixes ?

The current development version of zugbruecke (branch develop) now provides a somewhat cleaner path for this. The "default directory for zugbruecke wineprefixes" is exposed as the configuration parameter dir.

Option 1 is to actually reconfigure the default session right after import:

import os
import zugbruecke.ctypes as ctypes
ctypes._zb_set_parameter('wineprefix', os.path.join(ctypes._zb_get_parameter('dir'), 'test-wacup'))
# [proceed with using zugbruecke ...]

Option 2 is to start a customized session by configuring the session constructor:

import os
import zugbruecke
demo_session = zugbruecke.ctypes_session(parameter = {'wineprefix': os.path.join(zugbruecke.config()['dir'], 'test-wacup')})
# [proceed with using zugbruecke ...]

Beyond that, I also added support for environment variables. If an environment variable is set, it will override every other setting made in / configured for zugbruecke. But again, zugbruecke's wineprefix still is either an absolute path or relative to cwd. So you could do ...

user@comp:~> ZUGBRUECKE_WINEPREFIX=$(python -c "from zugbruecke import config; print(config()['dir'])")/test-wacup python -c "from zugbruecke import config; print(config()['wineprefix'])"
/home/user/.zugbruecke/test-wacup

The above could also be done like this:

user@comp:~> export ZUGBRUECKE_WINEPREFIX=$(python -c "from zugbruecke import config; print(config()['dir'])")/test-wacup
user@comp:~> python -c "from zugbruecke import config; print(config()['wineprefix'])"
/home/user/.zugbruecke/test-wacup

Also notice that configuration options (or actually their default values) depend on each other, which adds another bit of flexibility, see current implementation of __getitem__.

s-m-e commented 4 years ago

Feature released as part of new wenv package. zugbruecke will adopt it in next release.

stuaxo commented 4 years ago

Fantastic, this seems to solves the tricky problems of getting python in wine up and running.