configblock.path module

Class to represent a path through the configuration

class configblock.path.Path(path: str | Iterable[str] | Path)

Bases: object

Representation of a path through the configuration

Analysis configurations are formed from nested dictionaries. This class is designed to provide access to individual elements within the configuration. An extra complication is that individual elements of the configuration are not completely independent of each other so in some places we may require a method to access one element from another place in the configuration based on some relative path.

This now looks very similar to a directory structure in an operating system so we will use that as a model and use something resembling the (hopefully) familiar POSIX path formalism:

  • Nested segments of a path are separated by ‘/’ characters

  • A path beginning with a ‘/’ character is an absolute path beginning from the root of the configuration

  • A path not beginning with a ‘/’ character is a relative path beginning from the current location in the configuration

  • The current location is represented by a ‘.’ character

  • The location above this one is represented by ‘..’

  • An empty string translates to ‘.’

property absolute: bool

Whether or not this is an absolute path

property has_tail: bool

Whether this path has a tail

property head: str

The first part of the path

If the path is absolute this is ‘/’. If it refers to the current location it is ‘.’.

property refers_to_current_location: bool

Whether or not this path refers to the current location

property refers_upward: bool

Does the head of this path refers to the location above this

property segments: Tuple[str, ...]

The individual segments of the path

property tail: Path | None

Path object for everything after the head