commit/galaxy-central: carlfeberhard: sphinx-autodoc: better formatting for metadata_spec
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/9b27168c9442/ changeset: 9b27168c9442 user: carlfeberhard date: 2012-11-19 17:30:35 summary: sphinx-autodoc: better formatting for metadata_spec affected #: 3 files diff -r 19cbbaf566216cb46ecc6a6d17e0f1e0ab52978e -r 9b27168c94423a91e0dc0249bb9453adc9532610 lib/galaxy/datatypes/assembly.py --- a/lib/galaxy/datatypes/assembly.py +++ b/lib/galaxy/datatypes/assembly.py @@ -225,4 +225,3 @@ if __name__ == '__main__': import doctest, sys doctest.testmod(sys.modules[__name__]) - diff -r 19cbbaf566216cb46ecc6a6d17e0f1e0ab52978e -r 9b27168c94423a91e0dc0249bb9453adc9532610 lib/galaxy/datatypes/data.py --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -69,6 +69,9 @@ <class 'galaxy.datatypes.metadata.MetadataParameter'> """ + #: dictionary of metadata fields for this datatype:: + metadata_spec = None + __metaclass__ = DataMeta # Add metadata elements MetadataElement( name="dbkey", desc="Database/Build", default="?", param=metadata.DBKeyParameter, multiple=False, no_value="?" ) @@ -849,4 +852,3 @@ except UnicodeDecodeError: text = "binary/unknown file" return text - diff -r 19cbbaf566216cb46ecc6a6d17e0f1e0ab52978e -r 9b27168c94423a91e0dc0249bb9453adc9532610 lib/galaxy/datatypes/metadata.py --- a/lib/galaxy/datatypes/metadata.py +++ b/lib/galaxy/datatypes/metadata.py @@ -123,6 +123,7 @@ def __getstate__( self ): return None #cannot pickle a weakref item (self._parent), when data._metadata_collection is None, it will be recreated on demand + class MetadataSpecCollection( odict ): """ A simple extension of dict which allows cleaner access to items @@ -132,13 +133,21 @@ """ def __init__( self, dict = None ): odict.__init__( self, dict = None ) + def append( self, item ): self[item.name] = item + def iter( self ): return self.itervalues() + def __getattr__( self, name ): return self.get( name ) + def __repr__( self ): + # force elements to draw with __str__ for sphinx-apidoc + return ', '.join([ item.__str__() for item in self.iter() ]) + + class MetadataParameter( object ): def __init__( self, spec ): self.spec = spec @@ -185,7 +194,6 @@ """ pass - def unwrap( self, form_value ): """ Turns a value into its storable form. @@ -205,19 +213,22 @@ Turns a value read from an external dict into its value to be pushed directly into the metadata dict. """ return value + def to_external_value( self, value ): """ Turns a value read from a metadata into its value to be pushed directly into the external dict. """ return value + class MetadataElementSpec( object ): """ Defines a metadata element and adds it to the metadata_spec (which is a MetadataSpecCollection) of datatype. """ - - def __init__( self, datatype, name=None, desc=None, param=MetadataParameter, default=None, no_value = None, visible=True, set_in_upload = False, **kwargs ): + def __init__( self, datatype, + name=None, desc=None, param=MetadataParameter, default=None, no_value = None, + visible=True, set_in_upload = False, **kwargs ): self.name = name self.desc = desc or name self.default = default @@ -226,24 +237,37 @@ self.set_in_upload = set_in_upload # Catch-all, allows for extra attributes to be set self.__dict__.update(kwargs) - #set up param last, as it uses values set above + # set up param last, as it uses values set above self.param = param( self ) - datatype.metadata_spec.append( self ) #add spec element to the spec + # add spec element to the spec + datatype.metadata_spec.append( self ) + def get( self, name, default=None ): return self.__dict__.get(name, default) + def wrap( self, value ): """ Turns a stored value into its usable form. """ return self.param.wrap( value ) + def unwrap( self, value ): """ Turns an incoming value into its storable form. """ return self.param.unwrap( value ) + def __str__( self ): + #TODO??: assuming param is the class of this MetadataElementSpec - add the plain class name for that + spec_dict = dict( param_class=self.param.__class__.__name__ ) + spec_dict.update( self.__dict__ ) + return ( "{name} ({param_class}): {desc}, defaults to '{default}'".format( **spec_dict ) ) + +# create a statement class that, when called, +# will add a new MetadataElementSpec to a class's metadata_spec MetadataElement = Statement( MetadataElementSpec ) + """ MetadataParameter sub-classes. """ Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket