spakin / SimpInkScr

Simple Inkscape Scripting
https://inkscape.org/~pakin/%E2%98%85simple-inkscape-scripting
GNU General Public License v3.0
320 stars 31 forks source link

Finding the python script getting run? #91

Closed cwant closed 1 year ago

cwant commented 1 year ago

If I do print(__file__) in a script file that I load with this extension, it tells me the script is .config/inkscape/extensions/SimpInkScr/simple_inkscape_scripting.py.

It would be nice if there was a way to keep track where my script being run is (perhaps through an environment variable, e.g., INKSCAPE_SIMPLE_SCRIPT_FILE or such).

The use case is that I would like to set relative paths to set my python path to find libraries (e.g., I had expected that setting sys.path.append('..') would be relative to my script, not relative to the Inkscape extension code.) Having a way to locate my script file would help out with this.

Thanks! (for the awesome extension!)

spakin commented 1 year ago

For now, you can grab the corresponding command-line option passed to Simple Inkscape Scripting via extension.options.py_source. I probably ought to provide a more robust mechanism, though.

cwant commented 1 year ago

That works for me, thanks!

spakin commented 1 year ago

Simple Inkscape Scripting now provides a predefined script_filename variable. See https://github.com/spakin/SimpInkScr/wiki/Other-features#source-filename

cwant commented 1 year ago

Thanks again!