Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline MetaData ordering when dumping to yaml #5282

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions conda_build/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1026,22 +1027,26 @@ 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

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)
Expand All @@ -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 ("\\", "/")):
Expand Down
22 changes: 22 additions & 0 deletions news/5282-remove-custom-yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Enhancements

* <news item>

### Bug fixes

* <news item>

### 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

* <news item>

### Other

* <news item>
Loading