eye.pathutils module

Path manipulation utilities

eye.pathutils.data_path(*args)[source]
eye.pathutils.find_ancestor_containing(path, patterns)[source]

Find an ancestor containing any of patterns

Like find_in_ancestors, but returns the directory containing the matched file.

eye.pathutils.find_in_ancestors(path, patterns)[source]

Find file matching any of patterns in ancestors of path

patterns should be a list of globbing patterns (see standard glob module). Returns the absolute path of the first matching file. Patterns are searched in order given. path is searched first, then its parent, then ancestors in ascending order.

eye.pathutils.get_common_prefix(a, b)[source]

Return common path prefix between path a and path b

Paths are normalized with os.path.normpath. Will not cut in the middle of a path component.

>>> get_common_prefix('/foo/bar', '/foo/baz')
'/foo'
eye.pathutils.get_config_file_path(*args)[source]
eye.pathutils.get_config_path(*args)[source]
eye.pathutils.get_relative_path_in(a, b)[source]

Return the relative path of a inside b

If a is not contained inside b, returns None.

Paths are normalized with os.path.normpath. Does not check existence of paths.

>>> get_relative_path_in('/bar/foo/qux', '/bar')
'foo/qux'
>>> get_relative_path_in('/foo', '/bar') is None
True
eye.pathutils.is_in(a, b)[source]

Return True if path a is contained path b

Does not check existence of paths. Paths are normalized with os.path.normpath.

>>> is_in('/foo, '/bar')
False
>>> is_in('/bar/foo', '/bar')
True
eye.pathutils.parse_filename(filepath)[source]

Parse a filename:line:col string

Parse a string containing a file path, a line number and column number, in the format filepath:line:col. Line and column are optional. If only one is present, it’s taken as the line number. Returns a tuple

This function can be useful for command-line arguments.

>>> parseFilename('/foo/bar:1')
('/foo/bar', 1, None)
eye.pathutils.vim_filename_arg(args)[source]

Parse +line filename args

Vim and other editors are sometimes called with a filename and a line argument. Returns (filename, lineno)