opynsim.config#

opynsim.config.append_search_path(search_path: str | os.PathLike) None#

Appends search_path to the end (lowest-priority) of the global search path list (see get_search_paths()).

If an existing entry in the global search path list lexicographically matches search_path, it is removed to prevent duplicate entries. search_path does not need to exist on the filesystem.

opynsim.config.get_log_level() int#

Returns the current global logging level for OPynSim. The default log level is logging.WARNING.

If the logger has been misconfigured (e.g. because the log level was edited via Python, rather than via opynsim.set_log_level()) then the value returned by this function may not match logger.getLogger("opynsim").level. See set_log_level() for more details.

Returns:

A logging level integer that’s compatible with the Python (logging) module such as logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, or logging.CRITICAL see Python’s Logging Levels documentation for more information on the logging levels.

Return type:

int

opynsim.config.get_search_paths() list[pathlib.Path]#

Returns a copy of the current global search paths used to resolve filesystem resources, ordered from highest to lowest priority.

When OPynSim resolves a relative path, it uses a context-dependent base_path (e.g., the directory containing the current model file) and probes locations in this order:

  1. If path is absolute: Probes only path

  2. If path is relative: For each entry in get_search_path(), probe (base_path / entry / path).

Notably, if an entry is absolute, (base_path / entry / path) == (entry / path), so the base_path is ignored for that entry.

When a resource cannot be found via probing, the consequences are context-dependent. For example, a mesh implementation that fails to find a mesh file may choose to ignore the failure, generate a debug/error mesh, or throw an exception.

The returned paths will be lexicographically unique, but entries may not be be behaviorally unique. For example, pathlib.Path("Geometry") == pathlib.Path("geometry") is True on Windows but False on macOS and Linux. Regardless, the OPynSim API for search paths checks and compares the lexicographic representation.

opynsim.config.prepend_search_path(search_path: str | os.PathLike) None#

Prepends search_path to the start (highest-priority) of the global search path list (see get_search_paths()).

If an existing entry in the global search path list lexicographically matches search_path, it is removed to prevent duplicate entries. search_path does not need to exist on the filesystem.

opynsim.config.remove_search_path(search_path: str | os.PathLike) bool#

Returns True if an entry that lexicographically matches search_path was found and removed from the global search path list.

Parameters:

search_path – The path to remove. It must lexicographically match an entry from get_search_paths().

opynsim.config.set_log_level(python_logging_level: int) None#

Sets the global logging level for OPynSim. The default log level is logging.WARN.

opynsim is integrated with Python’s logging API but, for performance reasons, its C++ engine stores an internal log level separately. This function synchronizes the log level of both OPynSim’s Python logger (i.e. logger.getLogger("opynsim")) and the internal C++ log level. Changing only the Python logger can result in a situation where the C++ engine emits (or doesn’t!) log messages that Python logger subsequently drops.

Parameters:

python_logging_level (int) –

A logging level from the Python (logging) module such as logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, or logging.CRITICAL see Python’s Logging Levels documentation for more information on the logging levels.