Skip to content

Registry Module

datajoint_file_validator.registry.list_manifests(query=None, sort_alpha='asc', additional_dirs=None, ignore_patterns=('mkdocs.yaml', 'docs-example', 'docs'))

List all available manifests.

Parameters

query : Optional[str], optional A regular expression query to filter manifest names, by default None

Returns

List[Dict[str, Any]] A list of dicts containing information about each manifest.

Source code in datajoint_file_validator/registry.py
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def list_manifests(
    query: Optional[str] = None,
    sort_alpha: Optional[str] = "asc",
    additional_dirs: Optional[list] = None,
    ignore_patterns: Optional[list] = ("mkdocs.yaml", "docs-example", "docs"),
) -> List[Dict[str, Any]]:
    """
    List all available manifests.

    Parameters
    ----------
    query : Optional[str], optional
        A regular expression query to filter manifest names, by default None

    Returns
    -------
    List[Dict[str, Any]]
        A list of dicts containing information about each manifest.
    """
    if query is None:
        query = ".+"
    else:
        query = ".*" + query + ".*"
    additional_dirs = additional_dirs or list()

    # Get the unique set of possible manifest paths from _get_try_paths
    poss_paths = set()
    for dir in ["*"] + [f"{dir}/*" for dir in additional_dirs]:
        for glob_query in _get_try_paths(dir):
            for path_str in glob(str(glob_query), exclude=ignore_patterns):
                poss_paths.add(Path(path_str))
    logger.debug(f"Searching for manifests at the following paths: {pf(poss_paths)}")

    manifests = set()
    for path in poss_paths:
        if path.suffix != ".yaml":
            continue
        if not re.match(query, path.name) and not re.match(query, path.parent.name):
            continue
        try:
            manifest = Manifest.from_yaml(path)
        except InvalidManifestError as e:
            logger.debug(
                f"Could not load manifest at {path} "
                f"due to InvalidManifestError: {e}"
            )
            continue
        else:
            manifest._meta["path"] = str(path)
            manifest._meta["stem"] = str(path.stem)
            manifests.add(manifest)
    manifests = list(manifests)

    if sort_alpha is not None:
        if sort_alpha not in ("asc", "desc"):
            raise ValueError(f"sort_alpha must be 'asc' or 'desc', not {sort_alpha}")
        manifests = sorted(manifests, key=lambda m: getattr(m, "id", None))
        if sort_alpha == "desc":
            manifests = list(reversed(manifests))

    return [manifest.to_dict() for manifest in manifests]

datajoint_file_validator.registry.find_manifest(query)

Try to find a manifest file on local disk, and if that fails, the manifest registry.

Parameters

query : str A string to query the registry with.

Returns

Path A resolved path to a manifest file.

Source code in datajoint_file_validator/registry.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def find_manifest(query: str) -> Path:
    """
    Try to find a manifest file on local disk, and if that fails,
    the manifest registry.

    Parameters
    ----------
    query : str
        A string to query the registry with.

    Returns
    -------
    Path
        A resolved path to a manifest file.
    """
    if not isinstance(query, str):
        query = str(query)

    try_paths: List[Path] = list(_get_try_paths(query))
    # Remove duplicates while preserving order
    try_paths = list(dict.fromkeys(try_paths))
    logger.debug(f"Trying paths: {pf(try_paths)}")

    for path in try_paths:
        if path.is_file():
            logger.debug(f"Found manifest file: {path}")
            return path
        else:
            logger.debug(f"No manifest file found at: {path}")
    raise FileNotFoundError(f"Could not find manifest file with query: {query}")