Permalink
Browse files

Add `manifest_from_string` (#339)

* Fix the unit test for the function-based plugin registration.
  • Loading branch information...
ssteinbach committed Oct 11, 2018
1 parent 7e82ebf commit 9fc219539f93148dffc5a0ccf1044a7ffe4fb6df
@@ -58,6 +58,10 @@ def plugin_manifest():
this function isn't defined. In most cases ``plugin_manifest.json`` should
be sufficient and the ``__init__.py`` file can be left empty.
"""
# XXX: note, this doesn't get called. For an example of this working,
# see the mockplugin unit test.
return manifest.manifest_from_string(
pkg_resources.resource_string(__name__, 'plugin_manifest.json')
)
@@ -49,6 +49,26 @@ def manifest_from_file(filepath):
return result
def manifest_from_string(input_string):
"""Deserialize the json string into a manifest object."""
result = core.deserialize_json_from_string(input_string)
# try and get the caller's name
name = "unknown"
stack = inspect.stack()
if len(stack) > 1 and len(stack[1]) > 3:
# filename function name
name = "{}:{}".format(stack[1][1], stack[1][3])
# set the value in the manifest
src_string = "call to manifest_from_string() in " + name
result.source_files.append(src_string)
result._update_plugin_source(src_string)
return result
@core.register_type
class Manifest(core.SerializableObject):
"""Defines an OTIO plugin Manifest.
@@ -2,8 +2,28 @@
from opentimelineio.plugins import manifest
"""An example plugin package that generates its package manifest on demand.
If you create a plugin that doesn't have a plugin_manifest.json, OTIO will
attempt to call the plugin_manifest() function from the __init__.py directory.
This would allow you to programmatically generate a manifest rather than have
it be static on disk, allowing you to switch features on or off or do some
template substition or any other kind of procedural processing.
This unit test uses a very simple example that just reads the manifest from
a non-standard json file path.
"""
def plugin_manifest():
# XXX: in python3.5 resource_string returns a 'bytes' object, but
# json.loads requires a string, not bytes (only in 3.5 -- 2.7 and 3.6
# seem to both be working). Luckily .decode() seems to work in both
# python3 and python2, so this *should* work for both versions.
return manifest.manifest_from_string(
pkg_resources.resource_string(__name__, 'plugin_manifest.json')
pkg_resources.resource_string(
__name__,
'unusually_named_plugin_manifest.json'
).decode('utf-8')
)
@@ -1,3 +1,4 @@
#!/usr/bin/env python
#
# Copyright 2018 Pixar Animation Studios
#
@@ -77,6 +78,8 @@ def tearDown(self):
del(sys.modules['otio_mockplugin'])
def test_detect_plugin(self):
"""This manifest uses the plugin_manifest function"""
# Create a manifest and ensure it detected the mock adapter and linker
man = otio.plugins.manifest.load_manifest()
@@ -95,7 +98,7 @@ def test_detect_plugin(self):
for linker in man.media_linkers:
self.assertIsInstance(linker, otio.media_linker.MediaLinker)
def test_detect_pugin_json_manifest(self):
def test_detect_plugin_json_manifest(self):
# Test detecting a plugin that rather than exposing the plugin_manifest
# function, just simply has a plugin_manifest.json provided at the
# package top level.
@@ -115,3 +118,7 @@ def test_detect_pugin_json_manifest(self):
for linker in man.media_linkers:
self.assertIsInstance(linker, otio.media_linker.MediaLinker)
if __name__ == '__main__':
unittest.main()
View
@@ -53,4 +53,6 @@ def create_manifest():
def remove_manifest(manifest):
"""Remove the manifest source files."""
for file_path in manifest.source_files:
os.remove(file_path)
# don't accidentally blow away python
if not file_path.endswith('.py'):
os.remove(file_path)

0 comments on commit 9fc2195

Please sign in to comment.