Skip to content

Commit

Permalink
Updated wrapper spec
Browse files Browse the repository at this point in the history
core/wrapper/specs.py:
* Set default type to 'basic:String'
* Fixed input arg_pos and added output argname
* Fixed serialization using repr
- set_raw: *new method
  Set attribute from serialized string
- has_alternate_versions: *new method
  Ported from matplotlib

packages/vtk/identifiers.py:
  Updated package version so that xml spec is updated

packages/vtk/init.py:
  Added upgrade path to new package version
  • Loading branch information
rexissimus committed Oct 27, 2015
1 parent fa323b4 commit 72d94f3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
37 changes: 31 additions & 6 deletions vistrails/core/wrapper/specs.py
Expand Up @@ -131,15 +131,28 @@ def to_xml(self, elt=None):
for attr, props in self.attrs.iteritems():
value = getattr(self, attr)
default_val, is_subelt, run_eval = parse_props(props)
if default_val != value:
if default_val != value and value is not None:
if run_eval:
value = repr(value)
else:
value = unicode(value)
if is_subelt:
subelt = ET.Element(attr)
subelt.text = unicode(getattr(self, attr))
subelt.text = value
elt.append(subelt)
else:
elt.set(attr, unicode(value))
elt.set(attr, value)
return elt

def set_raw(self, attr, value):
""" parse the value before setting it
"""
props = self.attrs[attr]
run_eval = parse_props(props)[2]
if run_eval:
value = ast.literal_eval(value)
setattr(self, attr, value)

@classmethod
def internal_from_xml(cls, elt):
# Process attributes
Expand Down Expand Up @@ -186,7 +199,7 @@ class PortSpec(SpecObject):
# other attributes
attrs = {
"name": "", # port name
"port_type": None # type signature in vistrails
"port_type": 'basic:String' # type signature in vistrails
}
attrs.update(prop_attrs)

Expand Down Expand Up @@ -273,6 +286,9 @@ def __init__(self, **kwargs):
for spec in self.alternate_specs:
spec.set_parent(self)

def has_alternate_versions(self):
return len(self.alternate_specs) > 0

def set_parent(self, parent):
self._parent = parent
if not self.name:
Expand Down Expand Up @@ -432,7 +448,7 @@ class FunctionInputPortSpec(InputPortSpec):
attrs = {"arg": "", # function argument name
"in_kwargs": (True, False, True), # Add as kwarg?
"in_args": (False, False, True), # Add as arg?
"arg_pos": [None, False, False]} # argument position
"arg_pos": (-1, False, True)} # argument position
attrs.update(InputPortSpec.attrs)

def __init__(self, arg=None, **kwargs):
Expand All @@ -445,8 +461,17 @@ def __init__(self, arg=None, **kwargs):


class FunctionOutputPortSpec(OutputPortSpec):
pass
attrs = {"arg": "", # output name
}
attrs.update(InputPortSpec.attrs)

def __init__(self, arg=None, **kwargs):
if arg is not None:
kwargs['arg'] = arg
if 'name' not in kwargs and 'arg' in kwargs:
kwargs['name'] = kwargs['arg']

OutputPortSpec.__init__(self, **kwargs)

class FunctionSpec(ModuleSpec):
""" Specification for wrapping a python function
Expand Down
2 changes: 1 addition & 1 deletion vistrails/packages/vtk/identifiers.py
Expand Up @@ -39,4 +39,4 @@
identifier = 'org.vistrails.vistrails.vtk'
old_identifiers = ['edu.utah.sci.vistrails.vtk']
name = 'VTK'
version = '1.0.1'
version = '1.0.2'
7 changes: 7 additions & 0 deletions vistrails/packages/vtk/init.py
Expand Up @@ -698,6 +698,13 @@ def handle_module_upgrade_request(controller, module_id, pipeline):
module_remap.add_module_remap(
UpgradeModuleRemap('1.0.0', '1.0.1', '1.0.1',
module_name=module_name))
remap = module_remap.get_module_upgrade(module_name, '1.0.1')
# Only difference with 1.0.2 is that the spec serialization changed
if remap is None:
# Manually upgrade to 1.0.2
module_remap.add_module_remap(
UpgradeModuleRemap('1.0.1', '1.0.2', '1.0.2',
module_name=module_name))

return UpgradeWorkflowHandler.remap_module(controller, module_id, pipeline,
module_remap)

0 comments on commit 72d94f3

Please sign in to comment.