getavalon / core

The safe post-production pipeline - https://getavalon.github.io/2.0
MIT License
218 stars 49 forks source link

Avoid requiring host in config to avoid "No module named xxx" errors #499

Closed BigRoy closed 4 years ago

BigRoy commented 4 years ago

Issue

Say you're a newcomer to Avalon and you'd want to try the setup in Nuke with a config that does not have {config}/nuke/__init__.py yet you will run into an ImportError error saying "No module name nuke".

The same is true for other hosts like:

What did you expect?

Clarify what is going on, and allow it to pass.

It should either:

  1. Show a descriptive error message on how this could be solved.
  2. Or, maybe even more preferred, allow it to actually run fine without requiring {config}/nuke module to exist. Maybe just logging a warning of something like:
    • Config "polly" has no dedicated "nuke" module. Skipping config initialization for "nuke"

I'd opt for two and make it very clear where and how one could set something like that up. Maybe even pointing to a part in the documentation on how to set up custom installations in a studio config for an integration.

Avoid code duplication

Additionally, note how the find_host_config code is duplicated among all integrations. I'd recommend instead making a single function in avalon.lib like:

# pseudocode
def find_host_config(config, host):

    config_name = config.__name__
    module_name = "%s.%s" % (config_name, host)
    try:
        config = importlib.import_module(module_name)
    except ImportError as exc:
        if str(exc) != "No module name {}".format(module_name):
            log.warning("Config has no '%s' module." % module_name)
        config = None

    return config

And then e.g. use it in the avalon.nuke.pipeline as simply as lib.find_host_config(config, "nuke").

To Reproduce

Try running e.g Nuke with the Polly config which does not have anything set up for nuke.

Additional context

This "No module" error caught my attention as someone asked me about how to get the Nuke integration up and running which he failed to try out because of a config that didn't have polly/nuke/__init__.py

BigRoy commented 4 years ago

In the PR I actually proposed a different way of cleaning the duplicate code by moving the code to the global install/uninstall which makes much more sense and it would never have to be duplicated for new hosts, greatly simplifying what's required for new host integrations.

BigRoy commented 4 years ago

This is fixed with #501

Be aware that pending integrations like #466 #497 #496 #502 should update the core install and uninstall functions for the host accordingly, that is the removal of calling install and uninstall on the config's host module.