Kara-Moon Forum

Developers & Technology => Musical MIDI Accompaniment (MMA) => Topic started by: bvdp on October 20, 2020, 06:23:37 PM



Title: New mma.py
Post by: bvdp on October 20, 2020, 06:23:37 PM
To make installation easier in environments which want python programs installed in the system python tree I've made a few changes to the mma.py program so it now checks the system tree for modules. Could you guys please give this a test run and let me know of any problems.


Title: Re: New mma.py
Post by: sciurius on October 20, 2020, 07:23:22 PM
Looks okay, but I am not familiar with the way python organises its ecosystem.

Apparently python has a concept of library path, and that python locates modules by searching the library path, why not put the modules there (or add the path where the modules are to the library path) and leave it to python to find them?

The current approach searches for a directory MMA in a predefined set of locations (completely bypassing the python library path!) and, if found, requires all modules (and includes etc.) to be in that directory.

In short, if I have a file ~/lib/python/MMA/paths.py and I run

    env PYTHONPATH=$HOME/lib/python mma

I expect my private version of MMA.paths to be loaded.

While on the topic of paths...

MMA uses ~/.mmarc for init file. For the last couple of decades these home-dot files have been fased out in favour of XDG compliant locations. For MMA that would mean thay it first tries ~/.config/mma/mma.conf and, if not found, fallback to ~/.mmarc .
Windows and MacOS also have modern config file locations.


Title: Re: New mma.py
Post by: bvdp on October 22, 2020, 02:15:59 AM
Yes, python does have its own concept of where modules are to be stored. However, in order to separate out an application like MMA from the rest of the riffraff I like to have it separate :) One problem with storing application specific modules in /lib/python* is that you do need root permission to get there ... so then you need to use user-write space ... and, besides, this is the way I started the mess :)

Having config files in .config is a good idea. I've added environ.get('HOME')+'/.config/mma/mmarc' into the search path at line 113 in paths.py and added  "from os import environ" in the header. Do you know if there is an equivalent for mac and windows? BTW, the first mmarc is the only one processed. So, it's easy to have a directory specific file ... in that case I usually start it with an include statement.



Title: Re: New mma.py
Post by: bvdp on October 22, 2020, 04:04:02 AM
The added search line should be '~/.config/mma/mmarc'. Dumb for me to do python's work in figuring out $HOME ... and I'm sure that python's method is much more robust than mine!


Title: Re: New mma.py
Post by: sciurius on October 22, 2020, 06:31:49 AM
I suggest to take a look at https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html .
I assume there are equivalents for Windows and MacOS.


Title: Re: New mma.py
Post by: bvdp on October 22, 2020, 04:25:26 PM
I suggest to take a look at https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html .
I assume there are equivalents for Windows and MacOS.

Yes, I'm aware of that. But, the only reference it has to .config is that it uses $HOME. Using expanduser() is much better since it handles unix (Linux & Mac) and windows. https://docs.python.org/3/library/os.path.html#os.path.expanduser


Title: Re: New mma.py
Post by: sciurius on October 22, 2020, 07:05:38 PM
Wel, there are a couple of remarks involving XDG_DATA_HOME and XDG_CONFIG_HOME... But I must admit I ignore these in most of my own programs ;) .