Skip to content

fediverse_pasture_inputs

fediverse_pasture_inputs

available module-attribute

Dynamically generated dictionary of all defined inputs

collect_available

collect_available() -> dict[str, InputData]

Collects the available input data

Source code in fediverse_pasture_inputs/__init__.py
def collect_available() -> dict[str, InputData]:
    """Collects the available input data"""
    available = {}
    for file_path in glob(f"{__file__.removesuffix('__init__.py')}/inputs/*.py"):
        if (
            not file_path.endswith("__init__.py")
            and not file_path.endswith("types.py")
            and not file_path.endswith("utils.py")
            and not file_path.endswith("version.py")
            and "test_" not in file_path
        ):
            module_name = (
                "fediverse_pasture_inputs.inputs."
                + file_path.split(".")[0].split("/")[-1]
            )

            spec = importlib.util.spec_from_file_location(module_name, file_path)
            if spec is None or spec.loader is None:
                raise ValueError(f"Could not load spec for {file_path}")

            module = importlib.util.module_from_spec(spec)
            spec.loader.exec_module(module)

            available_name = module.data.filename.removesuffix(".md")

            if available_name in available:
                raise ValueError(f"Duplicate input data filename: {available_name}")

            available[available_name] = module.data

    return available