labpack/compilers/yaml.py
def walk_data(target, source):
    
    ''' method to recursively walk parse tree and merge source into target '''

    from copy import deepcopy

    # skip if target and source are different datatypes
    if target.__class__.__name__ != source.__class__.__name__:
        pass
    # handle maps
    elif isinstance(target, CommentedMap):
        count = 0
        for k, v in source.items():
            # retrieve comments of field in source
            comments = source.get_comments(k)
            if comments:
                comments = '\n'.join([ comment.value for comment in comments ])
            # insert fields not found in target
            if k not in target.keys():
                target.insert(count, k, v, comments)
            else:
                # add comments from source when missing from target
                if comments:
                    if not target.get_comments(k):
                        target.ca.items[k] = source.ca.items.get(k)
                # walk down maps and sequences
                if isinstance(v, CommentedMap) or isinstance(v, CommentedSeq):
                    walk_data(target[k], v)
            count += 1
    # handle sequences
    elif isinstance(target, CommentedSeq):
        for idx, item in enumerate(target):
            # walk down maps and sequences
            source_copy = deepcopy(source[0])
            if isinstance(item, CommentedMap) or isinstance(item, CommentedSeq):
                if source:
                    walk_data(item, source_copy)
            # add comments to items found in both target and source
            elif source:
                if item in source:
                    comments = source.ca.items.get(source.index(item))
                    if comments:
                        if not target.get_comments(idx):
                            target.ca.items[idx] = comments
 method to recursively walk parse tree and merge source into target 
method to recursively walk parse tree and merge source into target
method to recursively walk parse tree and merge source into target
def walk_data(target, source):
    from copy import deepcopy
    if target.__class__.__name__ != source.__class__.__name__:
        pass
    elif isinstance(target, CommentedMap):
        count = 0
        for k, v in source.items():
            comments = source.get_comments(k)
            if comments:
                comments = '\n'.join([ comment.value for comment in comments ])
            if k not in target.keys():
                target.insert(count, k, v, comments)
            else:
                if comments:
                    if not target.get_comments(k):
                        target.ca.items[k] = source.ca.items.get(k)
                if isinstance(v, CommentedMap) or isinstance(v, CommentedSeq):
                    walk_data(target[k], v)
            count += 1
    elif isinstance(target, CommentedSeq):
        for idx, item in enumerate(target):
            source_copy = deepcopy(source[0])
            if isinstance(item, CommentedMap) or isinstance(item, CommentedSeq):
                if source:
                    walk_data(item, source_copy)
            elif source:
                if item in source:
                    comments = source.ca.items.get(source.index(item))
                    if comments:
                        if not target.get_comments(idx):
                            target.ca.items[idx] = comments
def walk_data ( target , source ) : from copy import deepcopy if target . __class__ . __name__ != source . __class__ . __name__ : pass elif isinstance ( target , CommentedMap ) : count = 0 for k , v in source . items ( ) : comments = source . get_comments ( k ) if comments : comments = '\n' . join ( [ comment . value for comment in comments ] ) if k not in target . keys ( ) : target . insert ( count , k , v , comments ) else : if comments : if not target . get_comments ( k ) : target . ca . items [ k ] = source . ca . items . get ( k ) if isinstance ( v , CommentedMap ) or isinstance ( v , CommentedSeq ) : walk_data ( target [ k ] , v ) count += 1 elif isinstance ( target , CommentedSeq ) : for idx , item in enumerate ( target ) : source_copy = deepcopy ( source [ 0 ] ) if isinstance ( item , CommentedMap ) or isinstance ( item , CommentedSeq ) : if source : walk_data ( item , source_copy ) elif source : if item in source : comments = source . ca . items . get ( source . index ( item ) ) if comments : if not target . get_comments ( idx ) : target . ca . items [ idx ] = comments
method to recursively walk parse tree and merge source into target
method to recursively walk parse tree and merge source into target
''' method to recursively walk parse tree and merge source into target ''' # skip if target and source are different datatypes # handle maps # retrieve comments of field in source # insert fields not found in target # add comments from source when missing from target # walk down maps and sequences # handle sequences # walk down maps and sequences # add comments to items found in both target and source
target
source