Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Dynamic modules #1872

Merged
merged 84 commits into from
Aug 23, 2021
Merged

Dynamic modules #1872

merged 84 commits into from
Aug 23, 2021

Conversation

iLLiCiTiT
Copy link
Member

@iLLiCiTiT iLLiCiTiT commented Jul 28, 2021

Description

Second step to be able implement OpenPype addons. This adds dynamic loading of OpenPype modules.

This is a proposal of a possible way how to approach addons and modules with ability to at least somehow communicate with each other. Most blocking part are currently interfaces defined by modules which require to import things in a specific order. We can modify interfaces idea or get rid of interfaces on modules side and reverse the logic of modules communications to previous state that if module want to communicate with other module he must know which methods are available and how to get the module (it's name etc.).

Changes

  • all modules were moved to subdirectory default_modules
  • all modules are dynamically imported
    • that is because all modules must first import interfaces and then module code itself in other words interfaces must be always imported before any openpype module (or addon) is imported that is because module may use other modules interface
    • interfaces as classes can be imported from virtual python module openpype_interfaces and all modules code (not module classes) can be imported using virtual python module openpype_modules
    # Now
    from openpype_modules.ftrack import FtrackModule
    from openpype_interfaces import IFtrackEventHandlerPaths
    
    # Before
    from openpype.modules.ftrack import FtrackModule
    from openpype.modules.ftrack import IFtrackEventHandlerPaths
    
    • this has few restrictions and disadvantages like lack of IDE support for modules code
    • to avoid this all we would not have ability of using interfaces on modules side or force to use them in a different way
    • path to module must be to parent directory of module content
  • all interfaces of all modules were moved to interfaces.py which are loaded before any module is imported
    • currently module can have interfaces.py in it's directory which must not import anything from module itself only can import from openpype

How to test

  • everything should work as before everywhere (in tray and in all hosts)
  • this is a huge change which should be fully tested at all platforms and most important hosts

Next PRs

  • settings definitions per module/addon
  • manifest of module which is readed before anything from module is imported
PR depends on
avalon-core ynput/avalon-core#356

@iLLiCiTiT iLLiCiTiT marked this pull request as ready for review August 5, 2021 09:05
Copy link
Member

@jakubjezek001 jakubjezek001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unable to launch Nuke as it is crashing. Hiero is opening but with this Traceback - the same as in Nuke

ERROR 12:39:20.844:Hiero(31140): Plugin C:/CODE/__PYPE/OpenPype/openpype/hosts/hiero/startup\Python\Startup\Startup.py could not be loaded: cannot import name load_modules
Traceback (most recent call last):
  File "C:\Program Files\Nuke12.0v1\pythonextensions\site-packages\hiero\core\find_plugins.py", line 42, in loadPluginsFromFolder
    module = imp.load_source( moduleName, p )
  File "C:/CODE/__PYPE/OpenPype/openpype/hosts/hiero/startup\Python\Startup\Startup.py", line 6, in <module>
    avalon.api.install(phiero)
  File "C:\CODE\__PYPE\OpenPype\repos\avalon-core\avalon\pipeline.py", line 111, in install
    config.install()
  File "C:\CODE\__PYPE\OpenPype\openpype\__init__.py", line 47, in decorated
    return func(*args, **kwargs)
  File "C:\CODE\__PYPE\OpenPype\openpype\__init__.py", line 71, in install
    from openpype.modules import load_modules
ImportError: cannot import name load_modules

@iLLiCiTiT
Copy link
Member Author

I am unable to launch Nuke as it is crashing. Hiero is opening but with this Traceback - the same as in Nuke

Thanks. Missing import in __init__.py, fixed.

Copy link
Member

@jakubjezek001 jakubjezek001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works

from openpype.modules.ftrack.event_handlers_server.event_sync_to_avalon import (
from openpype_modules.ftrack.lib import BaseEvent
from openpype_modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
from openpype_modules.ftrack.event_handlers_server.event_sync_to_avalon import (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

@@ -4,12 +4,12 @@
import pyblish.api
from avalon import io

# Copy of constant `openpype.modules.ftrack.lib.avalon_sync.CUST_ATTR_AUTO_SYNC`
# Copy of constant `openpype_modules.ftrack.lib.avalon_sync.CUST_ATTR_AUTO_SYNC`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

@iLLiCiTiT iLLiCiTiT merged commit 3023c6f into develop Aug 23, 2021
@mkolar mkolar deleted the feature/dynamic_modules branch September 17, 2021 22:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement Enhancements to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants