INNER CODE UNIT · Python

sort_meta_yml

nf-core/tools · nf_core/modules/lint/__init__.py:308

    def sort_meta_yml(self, meta_yml: dict) -> dict:
        """Sort meta.yml keys according to the schema's property order.

        Recurses into nested objects that the schema describes with ``properties``
        (e.g. ``containers`` -> docker, singularity, conda), so sub-sections are sorted
        too. Arrays, ``$ref``/``patternProperties`` nodes and scalars are left untouched.
        """
        try:
            schema = self.load_meta_schema()
        except LintExceptionError as e:
            raise UserWarning("Failed to load meta schema", e) from e

        def sort_by_schema(data, node):
            properties = node.get("properties", {}) if isinstance(node, dict) else {}
            if not isinstance(data, dict) or not properties:
                return data
            # Schema-ordered keys first (recursing into each), then any extras preserved
            ordered = {key: sort_by_schema(data[key], child) for key, child in properties.items() if key in data}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…