Skip to content

filesystem

dev_tool.config.filesystem

log = logging.getLogger(__name__) module-attribute

FilesystemConfig

A class for handling filesystem operations for configuration.

This class provides methods for resolving paths and reading configuration files.

get_resource_path

A method that resolves a resource path.

This method handles both packaged (frozen) and development environments by resolving the appropriate absolute path to a resource.

Parameters:

  • path (str) –

    The relative path to the resource.

Returns:

  • Path

    The absolute Path to the resource.

Source code in dev_tool/config/filesystem.py
def get_resource_path(self, path: str) -> Path:
    """
    A method that resolves a resource path.

    This method handles both packaged (frozen) and development environments
    by resolving the appropriate absolute path to a resource.

    :param path: The relative path to the resource.
    :return: The absolute Path to the resource.
    """

    if hasattr(sys, '_MEIPASS'):
        return Path(sys._MEIPASS, path)

    return Path(__file__).parent.parent.parent / path

get_developer_token

A method that retrieves a developer token from a file.

This method reads a token from the specified file, stripping any whitespace.

Parameters:

  • path (Path) –

    The path to the file containing the token.

Returns:

  • str | None

    The token as a string, or None if the file doesn't exist.

Source code in dev_tool/config/filesystem.py
def get_developer_token(self, path: Path) -> str | None:
    """
    A method that retrieves a developer token from a file.

    This method reads a token from the specified file, stripping any whitespace.

    :param path: The path to the file containing the token.
    :return: The token as a string, or None if the file doesn't exist.
    """

    if not path.exists():
        return None

    with open(path, 'r', encoding='utf-8') as handle:
        return handle.read().strip()