

def _splitSpec(spec):
    ' \n        Takes an input specification, and returns a (path, pattern) tuple.\n\n        The splitting works as follows:\n            - First, the spec is split on ".".\n            - We then try to maximally match as much as possible of the\n              start of the spec to an existing file or directory.\n            - The remainder is considered the mark pattern.\n\n        If no path is found, the first element of the return tuple is the empty\n        string.\n    '
    parts = spec.split('.')
    dirOffset = 0
    fileOffset = 0
    for i in range(1, (len(parts) + 1)):
        if os.path.isdir('.'.join(parts[:i])):
            dirOffset = i
        elif os.path.isfile(('.'.join(parts[:i]) + '.py')):
            fileOffset = i
    if (dirOffset > fileOffset):
        target = '.'.join(parts[:dirOffset])
        pattern = '.'.join(parts[dirOffset:])
    elif fileOffset:
        target = ('.'.join(parts[:fileOffset]) + '.py')
        pattern = '.'.join(parts[fileOffset:])
    else:
        target = ''
        pattern = '.'.join(parts)
    if (target and (pattern == 'py')):
        pattern = ''
    return (target, pattern)

dataset/ETHPy150Open cortesi/pry/libpry/utils.py _splitSpec/original