Skip to content

Commit

Permalink
Merge pull request #230 from mottosso/master
Browse files Browse the repository at this point in the history
Fixes #229
  • Loading branch information
mottosso committed Oct 27, 2015
2 parents 65a0bc0 + 74c7223 commit 14ea713
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,16 @@ def discover(type=None, regex=None, paths=None):
continue

module = types.ModuleType(mod_name)
module.__file__ = abspath

try:
execfile(abspath, module.__dict__)

# Store reference to original module, to avoid
# garbage collection from collecting it's global
# imports, such as `import os`.
sys.modules[mod_name] = module

except Exception as err:
log.debug("Skipped: \"%s\" (%s)", mod_name, err)
continue
Expand All @@ -1100,11 +1107,6 @@ def discover(type=None, regex=None, paths=None):
log.debug("Duplicate plug-in found: %s", plugin)
continue

# Store reference to original module, to avoid
# garbage collection from collecting it's global
# imports, such as `import os`.
plugin.__parent__ = module

plugins[plugin.id] = plugin

# Include plug-ins from registration.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,16 @@ def e():

assert pyblish.api.Plugin.process.__code__.co_code == e.__code__.co_code
assert pyblish.api.Plugin.repair.__code__.co_code == e.__code__.co_code


def test_plugin_source_path():
"""Plugins discovered carry a source path"""

import sys
plugin = pyblish.plugin.discover()[0]
module = sys.modules[plugin.__module__]
assert hasattr(module, "__file__")

# Also works with inspect.getfile
import inspect
assert inspect.getfile(plugin) == module.__file__

0 comments on commit 14ea713

Please sign in to comment.