raesl.utils#

Generic utility functions.

Module Contents#

Functions#

get_esl_paths(→ List[pathlib.Path])

Get a sorted list of ESL file paths from multiple file or directory paths.

check_output_path(→ pathlib.Path)

Check output filepath versus force overwrite status.

get_location(→ raesl.types.Location)

Generation utility to quickly drum up a location.

cleanup_path(→ pathlib.Path)

Cleanup pathname for some typical mistakes.

uri_to_path(→ pathlib.Path)

Convert a file URI to a regular path.

path_to_uri(→ str)

Convert a path to a file URI.

split_first_dot(→ Tuple[str, str, int])

Split the provided name on the first dot if it exists, return both parts, and

get_first_namepart(→ str)

Return the name upto and excluding the first dot.

get_scoped_nodes(→ List[ragraph.node.Node])

Get scoped nodes, being subtrees of the graph of varying depth.

yield_subtree(→ Generator[ragraph.node.Node, None, None])

Yield nodes from a given subtree starting at Node and with given depth.

raesl.utils.get_esl_paths(*paths: str | pathlib.Path) List[pathlib.Path]#

Get a sorted list of ESL file paths from multiple file or directory paths.

raesl.utils.check_output_path(fpath: str | pathlib.Path, force: bool) pathlib.Path#

Check output filepath versus force overwrite status.

raesl.utils.get_location(uri: str = 'Unknown', start_line: int = 0, start_character: int = 0, end_line: int | None = None, end_character: int | None = None) raesl.types.Location#

Generation utility to quickly drum up a location.

Parameters:
  • uri – Location uri.

  • start_line – Location’s range start line.

  • start_character – Location’s range start offset.

  • end_line – Optional Location’s range end line (otherwise identical to start.)

  • end_character – Optional Location’s range end offset (otherwise identical to start.)

Returns:

Newly created location instance.

raesl.utils.cleanup_path(path: str | pathlib.Path) pathlib.Path#

Cleanup pathname for some typical mistakes.

raesl.utils.uri_to_path(uri: str) pathlib.Path#

Convert a file URI to a regular path.

raesl.utils.path_to_uri(path: str | pathlib.Path) str#

Convert a path to a file URI.

raesl.utils.split_first_dot(name: str) Tuple[str, str, int]#

Split the provided name on the first dot if it exists, return both parts, and the length of the dot.

raesl.utils.get_first_namepart(name: str) str#

Return the name upto and excluding the first dot.

raesl.utils.get_scoped_nodes(graph: ragraph.graph.Graph, scopes: Dict[str, int | None]) List[ragraph.node.Node]#

Get scoped nodes, being subtrees of the graph of varying depth.

Parameters:
  • graph – Graph data.

  • scopes – Node names mapped to depths of the subtree to include. A depth of None includes the whole subtree starting at that node.

Returns:

List of nodes in all given scopes.

raesl.utils.yield_subtree(root: ragraph.node.Node, depth: int | None) Generator[ragraph.node.Node, None, None]#

Yield nodes from a given subtree starting at Node and with given depth.

Parameters:
  • root – Root node of subtree.

  • depth – Depth of subtree. If None, defaults to full depth.

Yields:

Nodes in the subtree.