Skip to content

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

@BigRoy

Description

@BigRoy

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:

  • Maya same error.
  • Houdini same error.
  • Fusion which looking at the code will actually pass but instead return the config itself as opposed to the fusion package inside of it. Which is also very wrong. It should actually set config = None.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions