Project Name: davidhalter+jedi
Language: Python
Statement Type: API

Source Code:
def transform_path_to_dotted(sys_path, module_path):
    """
    Returns the dotted path inside a sys.path as a list of names. e.g.

    >>> transform_path_to_dotted([str(Path("/foo").absolute())], Path('/foo/bar/baz.py').absolute())
    (('bar', 'baz'), False)

    Returns (None, False) if the path doesn't really resolve to anything.
    The second return part is if it is a package.
    """
    # First remove the suffix.
    module_path = remove_python_path_suffix(module_path)
    if module_path.name.startswith('.'):
        return None, False

    # Once the suffix was removed we are using the files as we know them. This
    # means that if someone uses an ending like .vim for a Python file, .vim
    # will be part of the returned dotted part.

    is_package = module_path.name == '__init__'
    if is_package:
        module_path = module_path.parent

    def iter_potential_solutions():
        for p in sys_path:
            if str(module_path).startswith(p):
                # Strip the trailing slash/backslash
                rest = str(module_path)[len(p):]
                # On Windows a path can also use a slash.
                if rest.startswith(os.path.sep) or rest.startswith('/'):
                    # Remove a slash in cases it's still there.
                    rest = rest[1:]

                if rest:
                    split = rest.split(os.path.sep)
                    if not all(split):
                        # This means that part of the file path was empty, this
                        # is very strange and is probably a file that is called
                        # `.py`.
                        return
                    # Stub folders for foo can end with foo-stubs. Just remove
                    # it.
                    yield tuple(re.sub(r'-stubs$', '', s) for s in split)

    potential_solutions = tuple(iter_potential_solutions())
    if not potential_solutions:
        return None, False
    # Try to find the shortest path, this makes more sense usually, because the
    # user usually has venvs somewhere. This means that a path like
    # .tox/py37/lib/python3.7/os.py can be normal for a file. However in that
    # case we definitely want to return ['os'] as a path and not a crazy
    # ['.tox', 'py37', 'lib', 'python3.7', 'os']. Keep in mind that this is a
    # heuristic and there's now ay to "always" do it right.
    return sorted(potential_solutions, key=lambda p: len(p))[0], is_package

transform_path_to_dotted(sys_path=['/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi', '/local/rcs/jinjun/code/pytrace-collector', '/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python39.zip', '/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9', '/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/lib-dynload', '/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/site-packages', '/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/site-packages/PySnooper-1.2.0-py3.9.egg'], module_path=PosixPath('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi/example.py'))

Selected Statement: module_path = remove_python_path_suffix(module_path)

Function Input:
sys_path: /local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi
/local/rcs/jinjun/code/pytrace-collector
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python39.zip
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/lib-dynload
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/site-packages
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/site-packages/PySnooper-1.2.0-py3.9.egg
module_path: PosixPath('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi/example.py')

Variable Values Before Statement:
module_path: PosixPath('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi/example.py')

Value After Statement Execution: PosixPath('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi/example')

Variable States During Runtime (line, value):
sys_path: 1
/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi
/local/rcs/jinjun/code/pytrace-collector
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python39.zip
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/lib-dynload
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/site-packages
/local/rcs/jinjun/miniforge3/envs/davidhalter+jedi/lib/python3.9/site-packages/PySnooper-1.2.0-py3.9.egg
module_path: 1
PosixPath('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi/example.py')
12
PosixPath('/local/rcs/jinjun/code/pytrace-collector/logs/self_collected/tried/davidhalter+jedi/davidhalter+jedi/example')
is_package: 20
False
iter_potential_solutions: 24
<function transform_path_to_dotted.<locals>.iter_potential_solutions at 0x7f5855feec10>
potential_solutions: 45
(('example',), ('logs', 'self_collected', 'tried', 'davidhalter+jedi', 'davidhalter+jedi', 'example'))