gemseo / utils

file_path_manager module

Services for handling file paths.

class gemseo.utils.file_path_manager.FileDefinition(name, extension)

Bases: tuple

Create new instance of FileDefinition(name, extension)

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.


Alias for field number 1


Alias for field number 0

class gemseo.utils.file_path_manager.FilePathManager(file_type, default_name=None, default_directory=None, default_extension=None)[source]

Bases: object

A factory of file paths for a given type of file and with default settings.

  • file_type (FileType) – The type of file, defined by its default file name and format; select a file type by iterating over FileType.

  • default_name (str) – The default file name. If None, use the default file name related to the given type of file.

  • default_directory (Path | None) – The default directory path. If None, use the current working directory.

  • default_extension (str | None) – The default extension. If None, use the default extension related to the given type of file.

classmethod add_suffix(file_path, suffix)[source]

Add a suffix to an existing file path between the filename and the extension.

E.g. directory/filename_suffix.pdf.

  • file_path (Path) – The file path to be suffixed.

  • suffix (str) – The suffix to be added to the file path.


The directory path, the file name and the file extension obtained from the file path.

Return type:


create_file_path(file_path=None, directory_path=None, file_name=None, file_extension=None)[source]

Make a file path from a directory path, a file name and a file extension.

  • file_path (str | Path | None) – The path of the file to be returned. If None, create a file path from directory_path, file_name and file_extension.

  • directory_path (str | Path | None) – The path of the directory. If None, use the default directory path.

  • file_name (str | None) – The file name to be used. If None, use the default file name.

  • file_extension (str | None) – A file extension, e.g. ‘png’, ‘pdf’, ‘svg’, … If None, use the default file extension.


The file path.

Return type:


static to_snake_case(message)[source]

Snake case a string.

That means:

  1. Split the message.

  2. Lowercase the resulting elements.

- and `` `` are replaced with _.


message (str) – The message to be snake-cased.


The snake-cased message.

Return type:


class gemseo.utils.file_path_manager.FileType(value)[source]

Bases: Enum

The type of a file, defined by its default name and format.

FIGURE = FileDefinition(name='figure', extension='png')
SCHEMA = FileDefinition(name='schema', extension='json')
TEXT = FileDefinition(name='document', extension='txt')
WEBPAGE = FileDefinition(name='page', extension='html')