from baz import symbolhi, i already mentioned it in a review request, but i think this is better.$ head -n 1 bar/bar.py
how about making python plugins python modules?
currently, they are “either a single-file module or a directory full of modules, with one special module that gets imported/executed”, which is not only more unwieldy to explain, but also a more complex implementation and puts many modules into the namespace.
e.g. i’m not sure if it’s possible to create a “util.py” module inside one of your plugins, because another one might have the same. they have to be prefixed, which is rather silly in a namespace-focused language.
so i’ll explain how it works now:
```
$ pwd
...plugins
$ ls
foo.desktop
foo.py
bar/bar.desktop
bar/bar.py
bar/baz.py```
the desktop files point to foo.py and bar/bar.py
Pâté loads both and checks if they are activated. for each activated one that is in a subdirectory, it prepends that one to the python path.
if both are activated, the python path now contains “...plugins/bar/” and “...plugins/” (in that order)
now the base name (remove directory part and “.py” extension) of both gets imported:
1. `py.import("foo")`: python checks in “...plugins/bar/”, doesn’t find it, checks in “...plugins/”, finds & imports it
2. `py.import("bar")`: checks in “...plugins/bar/”, finds & imports it3. during importing, “bar/bar.py” checks for the “baz” module in “...plugins/bar/”, finds & imports it
now if any plugin directory that gets prepended after “bar/” would contain baz.py, or if any plugin depended on some system module called “baz”, we’d be fucked.
---
my proposed changes:
* don’t change the path after adding the plugin directories (in our example, just add “...plugins/”, and be done with it)
* just put the module name in the .desktop files (in our example: “foo” and “bar”)
* change the name of the to-be-loaded submodule inside a plugin directory (bar/bar.py) to __init__.py
* change all relative imports inside plugins to python-3-style `from .relative_module import symbol`
now we have
```
$ pwd
...plugins
$ ls
foo.desktop
foo.py
bar/bar.desktop
bar/__init__.py
bar/baz.py
$ head -n 1 bar/__init__.py
from .baz import symbol # note the dot
```
how does it work now?just the plugin directory “...plugins/” gets prepended to the python paththe names given in the desktop files of each activated plugin – “foo” and “bar” – get imported:
1. `py.import("foo")`: python checks in “...plugins/”, finds & imports it
2. `py.import("bar")`: python checks in “...plugins/”, finds & imports it (as directory-based module)
3. during importing, “bar/__init__.py” checks for the “.baz” module next to itself (explicit relative import), finds & imports it
baz is invisible for other plugins
---what do you say?
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel