lib/util/fs.py
def _commonpath_polyfill(paths):
    '''
    Polyfill for `os.path.commonpath` (not available in Python 3.3).
    This method returns the common ancestor between all the given `paths`.

    Implementation note:
    This works by splitting the paths using directory separators, and then
    comparing each portion from left to right until a mismatch is found.
    This calls `os.path.commonprefix`, which doesn't necessarily result in a
    valid path. To get the valid path from it, we need to ensure that the
    string ends in a directory separator. Anything else is considered invalid.
    '''
    if not paths:
        raise ValueError('paths are invalid: %r' % (paths))

    # NOTE : the `zip` logic below is slow... only do it if necessary:
    if len(paths) == 1:
        first_path = paths[0]
        logger.debug('only one path, returning it: %s', first_path)
        return first_path

    path_components = [_split_path_components(path) for path in paths]
    logger.debug(
        'calculated path components for all paths: %s', path_components
    )

    # bundle up the components so we traverse them one at a time
    # e.g.  [['usr', 'lib'], ['usr', 'bin']]
    #   ->  (('usr', 'usr'), ('lib', 'bin'))
    path_traverser = zip(*path_components)

    # now traverse them until there's a mismatch
    common_path_components = []
    for current_components in path_traverser:
        # `current_components` is a tuple of strings
        # e.g.  ('usr', 'usr', 'lib') from ['/usr', '/usr/bin', '/lib']
        if not current_components:
            break
        one_component = current_components[0]
        all_equal = all(map(
            lambda c, e=one_component: c == e, current_components
        ))

        if not all_equal:
            break

        # else, equal! record this component and move on
        common_path_components.append(one_component)

    logger.debug(
        'calculated common path components: %s', common_path_components
    )

    if not common_path_components:
        raise ValueError('paths do not have a common ancestor')

    # ugh, `ntpath` won't join absolute paths correctly, so ensure that the
    # first item always ends in a directory separator
    common_path_components[0] += os.sep
    return os.path.join(*common_path_components)

    Polyfill for `os.path.commonpath` (not available in Python 3.3).
    This method returns the common ancestor between all the given `paths`.

    Implementation note:
    This works by splitting the paths using directory separators, and then
    comparing each portion from left to right until a mismatch is found.
    This calls `os.path.commonprefix`, which doesn't necessarily result in a
    valid path. To get the valid path from it, we need to ensure that the
    string ends in a directory separator. Anything else is considered invalid.
    


Implementation note:
This works by splitting the paths using directory separators, and then
comparing each portion from left to right until a mismatch is found.
This calls `os.path.commonprefix`, which doesn't necessarily result in a
valid path. To get the valid path from it, we need to ensure that the
string ends in a directory separator. Anything else is considered invalid.
Implementation note : This works by splitting the paths using directory separators and then comparing each portion from left to right until a mismatch is found . This calls ` os . path . commonprefix ` which doesn ' t necessarily result in a valid path . To get the valid path from it we need to ensure that the string ends in a directory separator . Anything else is considered invalid .
def _commonpath_polyfill(paths):
    if not paths:
        raise ValueError('paths are invalid: %r' % (paths))
    if len(paths) == 1:
        first_path = paths[0]
        logger.debug('only one path, returning it: %s', first_path)
        return first_path
    path_components = [_split_path_components(path) for path in paths]
    logger.debug(
        'calculated path components for all paths: %s', path_components
    )
    path_traverser = zip(*path_components)
    common_path_components = []
    for current_components in path_traverser:
        if not current_components:
            break
        one_component = current_components[0]
        all_equal = all(map(
            lambda c, e=one_component: c == e, current_components
        ))
        if not all_equal:
            break
        common_path_components.append(one_component)
    logger.debug(
        'calculated common path components: %s', common_path_components
    )
    if not common_path_components:
        raise ValueError('paths do not have a common ancestor')
    common_path_components[0] += os.sep
    return os.path.join(*common_path_components)
def _commonpath_polyfill ( paths ) : if not paths : raise ValueError ( 'paths are invalid: %r' % ( paths ) ) if len ( paths ) == 1 : first_path = paths [ 0 ] logger . debug ( 'only one path, returning it: %s' , first_path ) return first_path path_components = [ _split_path_components ( path ) for path in paths ] logger . debug ( 'calculated path components for all paths: %s' , path_components ) path_traverser = zip ( * path_components ) common_path_components = [ ] for current_components in path_traverser : if not current_components : break one_component = current_components [ 0 ] all_equal = all ( map ( lambda c , e = one_component : c == e , current_components ) ) if not all_equal : break common_path_components . append ( one_component ) logger . debug ( 'calculated common path components: %s' , common_path_components ) if not common_path_components : raise ValueError ( 'paths do not have a common ancestor' ) common_path_components [ 0 ] += os . sep return os . path . join ( * common_path_components )
Polyfill for `os.path.commonpath` (not available in Python 3.3).
Polyfill for ` os . path . commonpath ` ( not available in Python 3 . 3 ) .
'''
    Polyfill for `os.path.commonpath` (not available in Python 3.3).
    This method returns the common ancestor between all the given `paths`.

    Implementation note:
    This works by splitting the paths using directory separators, and then
    comparing each portion from left to right until a mismatch is found.
    This calls `os.path.commonprefix`, which doesn't necessarily result in a
    valid path. To get the valid path from it, we need to ensure that the
    string ends in a directory separator. Anything else is considered invalid.
    ''' # NOTE : the `zip` logic below is slow... only do it if necessary: # bundle up the components so we traverse them one at a time # e.g.  [['usr', 'lib'], ['usr', 'bin']] #   ->  (('usr', 'usr'), ('lib', 'bin')) # now traverse them until there's a mismatch # `current_components` is a tuple of strings # e.g.  ('usr', 'usr', 'lib') from ['/usr', '/usr/bin', '/lib'] # else, equal! record this component and move on # ugh, `ntpath` won't join absolute paths correctly, so ensure that the # first item always ends in a directory separator
paths