Path Expansion

Conversion between pathnames with and without expanded %ENVIRONMENT_VARIABLES%.

mhi.enerplot.common.path.expand_path(path, abspath=False)

Expand path, by replacing a ~ or ~user prefix, as well as expanding any $var, ${var} and %var% patterns in the path.

Parameters:
  • path (str) – The path to be expanded.
  • abspath (bool) – If True, convert resulting path to an absolute path.
Returns:

The expanded path, optionally forced to an absolute path.

Return type:

str

mhi.enerplot.common.path.expand_paths(paths, abspath=False)

Expand paths, by replacing a ~ or ~user prefix, as well as expanding any $var, ${var} and %var% patterns in the paths.

Parameters:
  • path (List[str]) – A list of paths to be expanded.
  • abspath (bool) – If True, convert resulting paths to absolute paths.
Returns:

A list of expanded paths, optionally forced to absolute paths.

Return type:

List[str]

mhi.enerplot.common.path.contract_path(path)

Look for and replace any substring of the path that matches a value found in an environment variable with that environment variable: ${key} or %key%. Additionally, replace a path starting with the user’s home path with ~.

Parameters:path (str) – The path to be shortened by replacing parts with environment variables.
Returns:The contracted path.
Return type:str
mhi.enerplot.common.path.contract_paths(paths)

Look for and replace any substring of the paths that matches a value found in an environment variable with that environment variable: ${key} or %key%. Additionally, replace paths starting with the user’s home path with ~.

Parameters:paths (List[str]) – The paths to be shortened by replacing parts with environment variables.
Returns:A list of contracted paths.
Return type:List[str]