gemseo / utils

Hide inherited members

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.

extension

Alias for field number 1

name

Alias for field number 0

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

Bases: object

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

Parameters:
  • 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 empty, use the default file name related to the given type of file.

    By default it is set to “”.

  • default_directory (Path | str) –

    The default directory path. If empty, use the current working directory.

    By default it is set to “”.

  • default_extension (str) –

    The default extension. If empty, use the default extension related to the given type of file.

    By default it is set to “”.

class FileType(value)[source]

Bases: LowercaseStrEnum

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

FIGURE = 'figure'
SCHEMA = 'schema'
TEXT = 'document'
WEBPAGE = 'page'
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.

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

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

Returns:

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

Return type:

Path

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

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

Parameters:
  • file_path (str | Path) –

    The path of the file to be returned. If empty, create a file path from directory_path, file_name and file_extension.

    By default it is set to “”.

  • directory_path (str | Path) –

    The path of the directory. If empty, use the default directory path.

    By default it is set to “”.

  • file_name (str) –

    The file name to be used. If empty, use the default file name.

    By default it is set to “”.

  • file_extension (str) –

    A file extension, e.g. ‘png’, ‘pdf’, ‘svg’, … If empty, use the default file extension.

    By default it is set to “”.

Returns:

The file path.

Return type:

Path

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 _.

Parameters:

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

Returns:

The snake-cased message.

Return type:

str