Skip to content

mkdocs_demo.lib

lib module.

factory

This module contains factory functions.

command_factory

command_factory(cmd: str) -> Callable[..., int | None]

The factory function takes a command as input and returns a function that, when called, executes the command and returns the exit code or None if the execution is interrupted.

Parameters

cmd : str The cmd parameter is a string that represents a command to be executed.

Returns

Callable[..., int | None] The factory function returns a callable object, which is a function. The function takes no arguments and returns either an integer or None.

Source code in src/mkdocs_demo/lib/factory.py
def command_factory(cmd: str) -> Callable[..., int | None]:
    """
    The `factory` function takes a command as input and returns a function that, when called, executes
    the command and returns the exit code or None if the execution is interrupted.

    Parameters
    ----------
    `cmd` : `str`
        The `cmd` parameter is a string that represents a command to be executed.

    Returns
    -------
    `Callable`[`...`, `int` | `None`]
        The factory function returns a callable object, which is a function. The function takes no
        arguments and returns either an integer or None.
    """

    def _func(_cmd: str = cmd) -> int | None:
        try:
            return subprocess.call(_cmd.split(" "), shell=False)
        except KeyboardInterrupt:
            pass

        return None

    return _func

mkdocstrings

This module contains code for auto-generating the codebase documentation.

gen_ref_pages

gen_ref_pages(config: type[RefGenConfig]) -> Literal[True]

The gen_ref_pages function generates reference pages for Python modules and creates a navigation structure for them.

Parameters

config : type[RefGenConfig] The config parameter is of type RefGenConfig. It is used to provide configuration settings for generating reference pages.

Source code in src/mkdocs_demo/lib/mkdocstrings.py
def gen_ref_pages(config: type[RefGenConfig]) -> Literal[True]:
    """
    The `gen_ref_pages` function generates reference pages for Python modules
    and creates a navigation structure for them.

    Parameters
    ----------
    `config` : `type`[`RefGenConfig`]
        The `config` parameter is of type `RefGenConfig`. It is used to provide configuration settings for
        generating reference pages.
    """

    nav = mkdocs_gen_files.Nav()
    src = Path(__file__).parent.parent.parent

    # Get paths for the give language handler
    for path in sorted(src.rglob(config.handler.value)):
        module_path = path.relative_to(src).with_suffix("")
        doc_path = path.relative_to(src).with_suffix(".md")
        full_doc_path = config.out_dir.joinpath(doc_path)

        parts = tuple(module_path.parts)

        match parts[-1]:
            case "__init__":
                parts = parts[:-1]
                doc_path = doc_path.with_name("index.md")
                full_doc_path = full_doc_path.with_name("index.md")
            case "__main__":
                continue

        nav[parts] = doc_path.as_posix()

        with mkdocs_gen_files.open(full_doc_path, "w") as fd:
            identifier = ".".join(parts)
            fd.write(f"::: {identifier}")

        mkdocs_gen_files.set_edit_path(full_doc_path, path)

    with mkdocs_gen_files.open(config.out_dir.joinpath("SUMMARY.md"), "w") as nav_file:
        nav_file.writelines(nav.build_literate_nav())

    return True

superfluous

This module contains additional trivial filler code.

TestClass

TestClass(num_features: int, hidden_layers: int)

Bases: object

The TestClass is a basic Python class.

Parameters

num_features : int The num_features parameter represents the number of input features in your model. It indicates the size of the input layer of your neural network.

hidden_layers : int The hidden_layers parameter represents the number of hidden layers in a neural network.

Source code in src/mkdocs_demo/lib/superfluous.py
def __init__(self, num_features: int, hidden_layers: int) -> None:
    """
    Initializes the number of features and the number of hidden layers for a neural network.

    Parameters
    ----------
    `num_features` : `int`
        The `num_features` parameter represents the number of input features in your model. It
        indicates the size of the input layer of your neural network.

    `hidden_layers` : `int`
        The `hidden_layers` parameter represents the number of hidden layers in a neural network.
    """

    self.num_features: int = num_features
    self.hidden_layers: int = hidden_layers

MODEL_TYPE class-attribute instance-attribute

MODEL_TYPE: str = 'MLP'

hidden_layers instance-attribute

hidden_layers: int = hidden_layers

num_features instance-attribute

num_features: int = num_features

get_type staticmethod

get_type() -> Literal['Neural Network']

The method get_type returns the string "Neural Network".

Returns

Literal The string "Neural Network".

Source code in src/mkdocs_demo/lib/superfluous.py
@staticmethod
def get_type() -> Literal["Neural Network"]:
    """
    The method `get_type` returns the string "Neural Network".

    Returns
    -------
    `Literal`
        The string "Neural Network".
    """

    return "Neural Network"

load_model classmethod

load_model(path: Path | str) -> str

The method load_model loads a model from a given path and returns a string indicating the path from which the model was loaded.

Parameters

path : Path | str The path parameter is the path to the model file that needs to be loaded. It can be either a string or a Path object.

Returns

str A string that indicates the path from which the model was loaded.

Source code in src/mkdocs_demo/lib/superfluous.py
@classmethod
def load_model(cls, path: Path | str) -> str:
    """
    The method `load_model` loads a model from a given path and returns a string indicating the
    path from which the model was loaded.

    Parameters
    ----------
    `path` : `Path` | `str`
        The `path` parameter is the path to the model file that needs to be loaded. It can be either a
        string or a `Path` object.

    Returns
    -------
    `str`
        A string that indicates the path from which the model was loaded.
    """

    if isinstance(path, str):
        path = Path(path)

    return f"Model loaded from: '{path}' - Type: {cls.MODEL_TYPE}"

show_model

show_model() -> dict[str, str | int]

The method show_model returns a dictionary containing the model type and information about its layers.

Returns

dict[str, str | int] A dictionary containing the model type and the layers of the model.

Source code in src/mkdocs_demo/lib/superfluous.py
def show_model(self) -> dict[str, str | int]:
    """
    The method `show_model` returns a dictionary containing the model type and information about
    its layers.

    Returns
    -------
    `dict`[`str`, `str` | `int`]
        A dictionary containing the model type and the layers of the model.
    """

    model_dict: dict[str, str | int] = {"model_type": self.MODEL_TYPE}
    model_dict.update(self._show_layers())

    return model_dict

Trolling

Trolling(x: float, n: int)

Bases: ITrolling

The class Trolling implements the ITrolling interface.

Parameters

x : float The parameter x is a float, which means it can hold decimal values. It is used to store a numerical value.

n : int The parameter n is an integer that represents the number of iterations or steps in a process.

Source code in src/mkdocs_demo/config/interfaces.py
def __init__(self, x: float, n: int) -> None:
    """
    The above function is an initializer method for a class that takes in
    two parameters, `x` and `n`, and does not return anything.

    Parameters
    ----------
    `x` : `float`
        The parameter `x` is a float, which means it can hold decimal
        values. It is used to store a numerical value.

    `n` : `int`
        The parameter `n` is an integer that represents the number of
        iterations or steps in a process.
    """

    self.x = x
    self.n = n

multiple property

multiple: float

The function calculates the product of the variables x and n.

Returns

float The product of self.x and self.n.

n instance-attribute

n = n

x instance-attribute

x = x

__repr__

__repr__() -> str
Source code in src/mkdocs_demo/config/interfaces.py
def __repr__(self) -> str:
    return f"""{self.x} * {self.n} = {self.multiple}"""

__str__

__str__() -> str
Source code in src/mkdocs_demo/config/interfaces.py
def __str__(self) -> str:
    return f"""x={self.x}, n={self.n}, hence the multiple={self.multiple}"""

from_dict classmethod

from_dict(d: dict[str, int]) -> Self

The function from_dict takes a dictionary as input, checks if it contains the required keys, and returns an instance of the class with the dictionary values as arguments.

Parameters

d : dict[str, int] The parameter d is a dictionary with string keys and integer values.

Returns

Self The method is returning an instance of the class itself with the attributes specified in the dictionary d.

Source code in src/mkdocs_demo/lib/superfluous.py
@classmethod
def from_dict(cls, d: dict[str, int]) -> Self:
    """
    The function `from_dict` takes a dictionary as input, checks if it
    contains the required keys, and returns an instance of the class with
    the dictionary values as arguments.

    Parameters
    ----------
    `d` : `dict`[`str`, `int`]
        The parameter `d` is a dictionary with string keys and integer
        values.

    Returns
    -------
    `Self`
        The method is returning an instance of the class itself with the
        attributes specified in the dictionary `d`.
    """

    required = ("x", "n")
    obj = {k: v for k, v in d.items()}

    assert obj.keys() in required

    return cls(**obj)

create_trolling

create_trolling(d: dict[str, int]) -> Trolling

The function create_trolling takes a dictionary d and returns a Trolling object created from the dictionary.

Parameters

d : dict[str, int] A dictionary containing the data needed to create a Trolling object. The keys of the dictionary are strings representing the attributes of the Trolling object, and the values are integers representing the values of those attributes.

Returns

Trolling An instance of the class Trolling.

Source code in src/mkdocs_demo/lib/superfluous.py
def create_trolling(d: dict[str, int]) -> Trolling:
    """
    The function `create_trolling` takes a dictionary `d` and returns a `Trolling` object created from
    the dictionary.

    Parameters
    ----------
    `d` : `dict`[`str`, `int`]
        A dictionary containing the data needed to create a Trolling object. The keys of the dictionary are
    strings representing the attributes of the Trolling object, and the values are integers representing
    the values of those attributes.

    Returns
    -------
    `Trolling`
        An instance of the class Trolling.
    """

    return Trolling.from_dict(d)