Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin/Package Dependency Registry #139

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Plugin/Package Dependency Registry #139

wants to merge 5 commits into from

Conversation

LightArrowsEXE
Copy link
Member

@LightArrowsEXE LightArrowsEXE commented Sep 29, 2024

Taking feedback from #124 into account, this now implements a dependency registry object instead.

This allows for the following functionality:

  • Different packages can all add to the registry
  • New function and exceptions to check if the given plugins, or all plugins in the given parent namespace is available.
  • Automatically assume parent namespace if none is provided.
  • Prompt the user to install if vsrepo is available on their system and the given plugin/package is found in there.

Regular usage example

dependency_registry.add_plugin('akarin2', ["Expr"], optional=False)
dependency_registry.add_plugin('akarin', ["Expr"], "testfunc")
dependency_registry.add_plugin('Eedi3', ["Expr"], "lvsfunc", optional=True)
dependency_registry.add_plugin('assrender', ["Expr"], "havsfunc")
dependency_registry.add_plugin('Nnedi3', ["Expr"], "lvsfunc", optional=True)
dependency_registry.add_plugin('Nnedi3', ["Expr"], "xvsfunc")

pprint(dependency_registry, width=180)
print()

check_dependencies(None, func="some_random_func")
check_dependencies("lvsfunc", func="some_random_func")

Output:

$ python test.py
PackageDependencyRegistry(plugin_registry={'havsfunc': {'assrender': PluginInfo(required_functions=['Expr'], url=None, optional=False)},
                                           'lvsfunc': {'Eedi3': PluginInfo(required_functions=['Expr'], url=None, optional=True),
                                                       'Nnedi3': PluginInfo(required_functions=['Expr'], url=None, optional=True)},
                                           'test.py': {'akarin2': PluginInfo(required_functions=['Expr'], url=None, optional=False)},
                                           'testfunc': {'akarin': PluginInfo(required_functions=['Expr'], url=None, optional=False)},
                                           'xvsfunc': {'Nnedi3': PluginInfo(required_functions=['Expr'], url=None, optional=False)}},
                          package_registry={},
                          vsrepo_available=True,
                          install_mode=<InstallModeEnum.PROMPT: 1>)

Traceback (most recent call last):
  File "C:\Users\light\GitHub\Jaded-Encoding-Thaumaturgy\vs-tools\test.py", line 19, in <module>
    check_dependencies(None, func="some_random_func")
  File "C:\Users\light\GitHub\Jaded-Encoding-Thaumaturgy\vs-tools\vstools\functions\check.py", line 248, in check_dependencies
    raise errors[0]
  File "C:\Users\light\GitHub\Jaded-Encoding-Thaumaturgy\vs-tools\vstools\functions\check.py", line 237, in check_dependencies
    PluginNotFoundError.check(func, None, None, parent_package, **kwargs)
  File "C:\Users\light\GitHub\Jaded-Encoding-Thaumaturgy\vs-tools\vstools\exceptions\dependencies.py", line 253, in check
    raise cls(
PluginNotFoundError: (some_random_func) Plugin(s) not found for package 'test.py': akarin2

Checking only lvsfunc deps and check the optional deps

# check_dependencies(None, func="some_random_func")
check_dependencies("lvsfunc", func="some_random_func")

Output:

$ python test.py
PackageDependencyRegistry(plugin_registry={'havsfunc': {'assrender': PluginInfo(required_functions=['Expr'], url=None, optional=False)},
                                           'lvsfunc': {'Eedi3': PluginInfo(required_functions=['Expr'], url=None, optional=True),
                                                       'Nnedi3': PluginInfo(required_functions=['Expr'], url=None, optional=True)},
                                           'test.py': {'akarin2': PluginInfo(required_functions=['Expr'], url=None, optional=False)},
                                           'testfunc': {'akarin': PluginInfo(required_functions=['Expr'], url=None, optional=False)},
                                           'xvsfunc': {'Nnedi3': PluginInfo(required_functions=['Expr'], url=None, optional=False)}},
                          package_registry={},
                          vsrepo_available=True,
                          install_mode=<InstallModeEnum.PROMPT: 1>)

C:\Users\light\GitHub\Jaded-Encoding-Thaumaturgy\vs-tools\vstools\exceptions\dependencies.py:218: UserWarning: Optional plugin 'Eedi3' for 'lvsfunc' is not installed.
  warnings.warn(
C:\Users\light\GitHub\Jaded-Encoding-Thaumaturgy\vs-tools\vstools\exceptions\dependencies.py:218: UserWarning: Optional plugin 'Nnedi3' for 'lvsfunc' is not installed.
  warnings.warn(

Drawbacks

  • The biggest drawback is that vsrepo is slow. However, should something better come along, we can always update it.
  • There's currently no support for installing the git latest of anything, though this feature could be added with some finesse

Additional wants

  • It would be nice if this could be done on a per-function namespace instead of just the parent namespace, but you run into the issue of heavy duplication if you do this. I've kinda worked around this by simply allowing devs to only check for specific plugins/packages instead, but better suggestions are welcome.

To fix

  • Ensure the setting in vspreview is respected. The setting exists now in Add deps install mode setting vs-preview#199, but currently, it sets this after the script is loaded(?), meaning it will not respect the flag when it has to determine whether to auto-install stuff.
  • When running vspreview x.py in a terminal, it seems to skip installing missing plugins. I think it's just completely ignoring the check_dependencies function, as print statements in there do not print at all?
  • It should ideally only prompt for missing packages/plugins that are strictly necessary for a function run. This could be achieved through using function/class namespaces, but that quickly becomes a mess to maintain. Writing some smarter decorator or checking function is probably the way to go.

@LightArrowsEXE LightArrowsEXE changed the title Updated dependency check implementation Plugin/Package Dependency Registry Sep 29, 2024
@LightArrowsEXE LightArrowsEXE marked this pull request as draft October 2, 2024 00:30
@LightArrowsEXE LightArrowsEXE force-pushed the master branch 2 times, most recently from 9f91ef5 to 8db0659 Compare October 10, 2024 17:31
@LightArrowsEXE LightArrowsEXE force-pushed the master branch 4 times, most recently from 6155720 to 81a0b18 Compare October 15, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant