stg-annon / stashapp-tools

Tools to interface with stashapps API
https://pypi.org/project/stashapp-tools/
MIT License
37 stars 4 forks source link

stashapi.stashapp.find_plugins_config #10

Closed David-Maisonave closed 4 weeks ago

David-Maisonave commented 1 month ago

This is a continuation from question 5103 in Stash. I tried downloading v0.2.47, but both the zip file and the tar file had nothing in the stashapi folder.

I did perform command line call: pip install stashapp-tools

I'm not sure if that would have pulled the latest changes. How can I tell what version is installed in user's directory? C:\Users\myUserName\AppData\Local\Programs\Python\Python310\Lib\site-packages\stashapi I could not find a version in any of the files in that folder.

The stashapi version I have does have find_plugins_config function, but when I call it without passing any arguments, I get following exception thrown:

[240730 09:32:42 - LN:111] Got exception on main handler
Traceback (most recent call last):
  File "E:\_\David-Maisonave\Axter-Stash\plugins\DupFileManager\DupFileManager.py", line 105, in <module>
    plugin_configuration = stash.find_plugins_config()
  File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\stashapp.py", line 405, in find_plugins_config
    config = self.call_GQL(query, {"input": plugin_ids})["configuration"]["plugins"]
  File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\stashapp.py", line 216, in call_GQL
    return self._GQL(query, variables)
  File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\classes.py", line 227, in _GQL
    return self._handle_GQL_response(response)
  File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\classes.py", line 270, in _handle_GQL_response
    raise Exception(error_msg)
Exception: 422 Unprocessable Entity query failed. v0.26.2-2
stg-annon commented 1 month ago

try pip install --upgrade stashapp-tools

do you have any debug from that?

find_plugins_config() without any args would return all existing plugins config values in a dict

David-Maisonave commented 1 month ago

try pip install --upgrade stashapp-tools

When I did that, it did show that I still had v0.2.46 installed.

Installing collected packages: stashapp-tools
  Attempting uninstall: stashapp-tools
    Found existing installation: stashapp-tools 0.2.46
    Uninstalling stashapp-tools-0.2.46:
      Successfully uninstalled stashapp-tools-0.2.46
Successfully installed stashapp-tools-0.2.47

I'll test it out again, and report back. Thank you

David-Maisonave commented 1 month ago

With version 0.2.47 both find_plugins_config() and stash.configure_plugin(PLUGIN_ID, settings) are working.

If I use these functions, I'm going to need the upgraded version of stashapp-tools. I though stash_version could help, but I get the following results: stash.stash_version()=v0.26.2-2 I'm guessing that's for the Stash program. Is there a way to check the version of stashapp-tools?

When using the requirements.txt file, as-in (pip install -r requirements.txt), there doesn't seem to be an easy way to make sure the user gets the upgrade if an old version of stashapp-tools is already installed.

upgrade-python-packages-from-requirements-txt From above link, it seems the easiest method would be the following command: pip install --upgrade --force-reinstall -r requirements.txt

On a related topic, stash.configure_plugin(PLUGIN_ID, settings) has an optional third argument (init_defaults), and I wasn't sure how a plugin would programmatically know when that value should be true. However, I notice when testing this function that when I added a bogus field which is not in the UI, the field does get set and the bogus field doesn't show up in the UI. stash.configure_plugin(PLUGIN_ID, {"fakeFieldName": 123}) I was thinking of using this to check if I should call configure_plugin with init_defaults as true, but I first want to make sure that the current behavior is not a bug which could potentially be fixed.

Is it expected behavior to allow field settings which are not in the UI? Is there a better method to determine if init_defaults should be true?

Thanks for all the help.

stg-annon commented 1 month ago

pip show stashapp-tools should show you all related info about the package including the version you have installed

indeed stash_version() is to show the version of the stash app

requirements.txt files can specify a specific version of a package to ensure compatibility

configure_plugin() is intended to support the mutation ConfigurePlugin so if you just wanted to set whatever values you wanted it would always set the cfg to those, the flag is added to support find_plugin_config() or if a user wanted to specify it themselves

You can think of it as a key value store, you can actually store info for bogus plugin IDs as well as bogus fields, the only things that will show in the UI are if you specify them in the plugin YML this is a Stash limitation/feature depending on how you look at it.

Is it expected behavior to allow field settings which are not in the UI?

this would be a question for the Stash side of things, for now I would say yes?

Is there a better method to determine if init_defaults should be true?

kind of a question for yourself, typically it would only need to be called once at the very init of a plugin with the default values you want to use, it will not override any existing values already in stash and will return the current config, alternatively you can use find_plugin_config() and always pass the defaults you want to use

David-Maisonave commented 1 month ago

requirements.txt files can specify a specific version of a package to ensure compatibility

Great. That's what I was looking. Thank you.

it will not override any existing values already in stash

In my testing, it does override existing values if init_defaults = True. In other words, it overrides whatever settings the user has made. IMHO, that would be expected behavior, and that's why you really want to make sure it's only ever called one time with init_defaults = True. But I think I can safely do that if I use the bogus field. if 'INITIAL_VALUES_SET' not in PLUGINCONFIGURATION[PLUGIN_ID]:

stg-annon commented 1 month ago

it will specifically pull the current config and override any defaults with what was in the config unless the key values aren't lining up it should always prefer the values in stash

https://github.com/stg-annon/stashapi/blob/main/stashapp.py#L375-L378

the case where it would always override should be when init_defaults=False the idea being you can safely call it once at the beginning of a plugin init to both retrieve the current plugin config and/or safely set any values that haven't been configured yet