From 667b1e980a8a8712acec6f3b0533e715c5e70ab9 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 12 Apr 2024 16:03:23 -0500 Subject: [PATCH 1/2] Inline MetaData ordering when dumping to yaml --- conda_build/render.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/conda_build/render.py b/conda_build/render.py index be17eaa461..acd2ad886a 100644 --- a/conda_build/render.py +++ b/conda_build/render.py @@ -32,6 +32,7 @@ from . import environ, exceptions, source, utils from .conda_interface import PackageRecord, TemporaryDirectory, specs_from_url +from .deprecations import deprecated from .exceptions import DependencyNeedsBuildingError from .index import get_build_index from .metadata import MetaData, combine_top_level_metadata_with_output @@ -1026,6 +1027,7 @@ def render_recipe( # Next bit of stuff is to support YAML output in the order we expect. # http://stackoverflow.com/a/17310199/1170370 +@deprecated("24.5", "24.7") class _MetaYaml(dict): fields = FIELDS @@ -1033,15 +1035,18 @@ def to_omap(self): return [(field, self[field]) for field in _MetaYaml.fields if field in self] +@deprecated("24.5", "24.7") def _represent_omap(dumper, data): return dumper.represent_mapping("tag:yaml.org,2002:map", data.to_omap()) +@deprecated("24.5", "24.7") def _unicode_representer(dumper, uni): node = yaml.ScalarNode(tag="tag:yaml.org,2002:str", value=uni) return node +@deprecated("24.5", "24.7") class _IndentDumper(yaml.Dumper): def increase_indent(self, flow=False, indentless=False): return super().increase_indent(flow, False) @@ -1050,24 +1055,17 @@ def ignore_aliases(self, data): return True -yaml.add_representer(_MetaYaml, _represent_omap) -yaml.add_representer(str, _unicode_representer) -unicode = None # silence pyflakes about unicode not existing in py3 - - def output_yaml(metadata, filename=None, suppress_outputs=False): - local_metadata = metadata.copy() - if ( - suppress_outputs - and local_metadata.is_output - and "outputs" in local_metadata.meta - ): - del local_metadata.meta["outputs"] + meta = metadata.meta + # create a manually ordered copy of the meta dict + meta = {field: meta[field] for field in FIELDS if field in meta} + if suppress_outputs and metadata.is_output and "outputs" in meta: + del meta["outputs"] output = yaml.dump( - _MetaYaml(local_metadata.meta), - Dumper=_IndentDumper, - default_flow_style=False, + meta, + default_flow_style=False, # always serialize in the block style indent=2, + sort_keys=False, # preserve manual order ) if filename: if any(sep in filename for sep in ("\\", "/")): From 4d5a6630bfacd975f5dc2edc3409973d25339ced Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 12 Apr 2024 16:18:55 -0500 Subject: [PATCH 2/2] Add news --- news/5282-remove-custom-yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 news/5282-remove-custom-yaml diff --git a/news/5282-remove-custom-yaml b/news/5282-remove-custom-yaml new file mode 100644 index 0000000000..6d4a66242a --- /dev/null +++ b/news/5282-remove-custom-yaml @@ -0,0 +1,22 @@ +### Enhancements + +* + +### Bug fixes + +* + +### Deprecations + +* Deprecate `conda_build.render._MetaYaml`. Unused. (#5282) +* Deprecate `conda_build.render._represent_omap`. Unused. (#5282) +* Deprecate `conda_build.render._unicode_representer`. Unused. (#5282) +* Deprecate `conda_build.render._IndentDumper`. Unused. (#5282) + +### Docs + +* + +### Other + +*