Kara-Moon Forum
April 25, 2024, 11:50:08 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: You can go back to the main site here: Kara-Moon site
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: New mma.py  (Read 2911 times)
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« 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.

* mma.py.txt (2.93 KB - downloaded 161 times.)
Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 443



« Reply #1 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.
Logged
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #2 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 Smiley 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 Smiley

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.

Logged

My online life: http://www.mellowood.ca
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #3 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!
Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 443



« Reply #4 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.
Logged
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #5 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
Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 443



« Reply #6 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 Wink .
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.058 seconds with 19 queries.