https://bugs.kde.org/show_bug.cgi?id=391508

            Bug ID: 391508
           Summary: Kritarunner -s expects known module, not filepath
           Product: krita
           Version: 4.0 pre-alpha
          Platform: MS Windows
                OS: MS Windows
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: Scripting
          Assignee: krita-bugs-n...@kde.org
          Reporter: fred...@averpil.com
  Target Milestone: ---

kritarunner.exe --help says:

-s, --script <script>  The Script to run. Do not append the .py
-f, --function <function>  The function to call (by default __main__ is called)

But kritarunner actually expects the --script parameter to pass on a Python
module name, and this module must exist in one of the internal search paths
which kritarunner uses (details further below).


-- PROPOSAL --

Preferably, make kritarunner accept a simple script filepath. As an
alternative, make it possible to specify on which path the Python module should
be searched for.


-- BACKGROUND --

I had trouble getting this to work on my Windows box:
"C:\Program Files\Krita (x64)\bin\kritarunner.exe" -s 
C:\Users\fredrik\Desktop\kritadev\kritacomp -f make_layered_psd_from_images()

After getting some IRC help from boud, I checked the output of DebugView, which
gave me this clue:
[13956] krita.scripting: "ModuleNotFoundError: No module named
'C:\\\\Users\\\\fredrik\\\\Desktop\\\\kritadev\\\\kritacomp'"

So, it turns out that what the -s parameter wants is actually a module name,
not a filepath. I tried to CWD into my directory and tried again:

cd C:\Users\fredrik\Desktop\kritadev
"C:\Program Files\Krita (x64)\bin\kritarunner.exe" -s kritacomp -f
make_layered_psd_from_images()

This time around, I got this:
[19224] krita.scripting: "ModuleNotFoundError: No module named 'kritacomp'"

Okay, that's fine. I need to make sure the script is on my PYTHONPATH, I guess.
So I made sure to have the "kritadev" folder on my PYTHONPATH and I tried
again:
set PYTHONPATH=C:\Users\fredrik\Desktop\kritadev
"C:\Program Files\Krita (x64)\bin\kritarunner.exe" -s kritacomp -f
make_layered_psd_from_images()

But I still received the same ModuleNotFoundError. Judging from the DebugView
output, it has successfully registered my PYTHONPATH, but it doesn't add it to
its own search locations:
[19224]  Python path: "C:\\Users\\fredrik\\Desktop\\kritadev"
[19224] Setting python paths:
"C:/Users/fredrik/AppData/Roaming/kritarunner\\;C:/Program Files/Krita
(x64)/bin\\;C:/Users/fredrik/AppData/Roaming/kritarunner/pykrita\\;C:/Program
Files/Krita (x64)/share/pykrita\\;C:/Program Files/Krita
(x64)/share/krita/pykrita\\;C:/Program Files/Krita
(x64)/lib/krita-python-libs;C:/Program Files/Krita
(x64)/python/python36.zip;C:/Program Files/Krita (x64)/python"

Dropping the "kritacomp.py" script into either of those paths above will
suddenly make my command work and the script executes beautifully!

It's just that... I can't have my script manually placed on my local machine.
So still can't use kritarunner.

--

So, a couple of ideas (some good, some better):

1 - GOOD:
* Make kritarunner add whatever is on PYTHONPATH to its own search paths, or
make it possible to specify a custom search path. Without this, kritarunner can
basically never find any module in an arbitrary user-defined location. This is
very, very important that kritarunner can support a custom module location in
some way.
* Update the kritarunner --help message, to be more clear on that it expects a 
module name, not a filename or filepath, and where kritarunner searches for
this module.

2 - BETTER:
* Add a new kritarunner parameter which will accept script filepath instead of
a module name. I don't have a preference in terms of whether a function needs
to be specified in tandem with this argument or not.

Personally, I find dabbling with PYTHONPATH very, very messy. I would strongly
encourage you to make kritarunner support a single filepath leading up to a
Python script file regardless of how you want to tackle this bug report.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to