Skip to content

Commit

Permalink
Report fully rendered recipe to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed May 17, 2024
1 parent 9c0ceec commit 70f9c16
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 50 deletions.
58 changes: 9 additions & 49 deletions conda_build/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ def render(
templates evaluated.
Returns a list of (metadata, need_download, need_reparse in env) tuples"""

from conda.exceptions import NoPackagesFoundError

from .exceptions import DependencyNeedsBuildingError
from .render import finalize_metadata, render_recipe
from .render import render_metadata_tuples, render_recipe

config = get_or_merge_config(config, **kwargs)

Expand All @@ -68,50 +64,14 @@ def render(
variants=variants,
permit_unsatisfiable_variants=permit_unsatisfiable_variants,
)
output_metas: dict[tuple[str, str, tuple[tuple[str, str], ...]], MetaDataTuple] = {}
for meta, download, render_in_env in metadata_tuples:
if not meta.skip() or not config.trim_skip:
for od, om in meta.get_output_metadata_set(
permit_unsatisfiable_variants=permit_unsatisfiable_variants,
permit_undefined_jinja=not finalize,
bypass_env_check=bypass_env_check,
):
if not om.skip() or not config.trim_skip:
if "type" not in od or od["type"] == "conda":
if finalize and not om.final:
try:
om = finalize_metadata(
om,
permit_unsatisfiable_variants=permit_unsatisfiable_variants,
)
except (DependencyNeedsBuildingError, NoPackagesFoundError):
if not permit_unsatisfiable_variants:
raise

# remove outputs section from output objects for simplicity
if not om.path and (outputs := om.get_section("outputs")):
om.parent_outputs = outputs
del om.meta["outputs"]

output_metas[
om.dist(),
om.config.variant.get("target_platform"),
tuple(
(var, om.config.variant[var])
for var in om.get_used_vars()
),
] = MetaDataTuple(om, download, render_in_env)
else:
output_metas[
f"{om.type}: {om.name()}",
om.config.variant.get("target_platform"),
tuple(
(var, om.config.variant[var])
for var in om.get_used_vars()
),
] = MetaDataTuple(om, download, render_in_env)

return list(output_metas.values())
return render_metadata_tuples(
metadata_tuples,
config=config,
permit_unsatisfiable_variants=permit_unsatisfiable_variants,
finalize=finalize,
bypass_env_check=bypass_env_check,
)



def output_yaml(
Expand Down
9 changes: 9 additions & 0 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
execute_download_actions,
expand_outputs,
output_yaml,
render_metadata_tuples,
render_recipe,
reparse,
try_download,
Expand Down Expand Up @@ -2425,6 +2426,14 @@ def build(
# Write out metadata for `conda debug`, making it obvious that this is what it is, must be done
# after try_download()
output_yaml(m, os.path.join(m.config.work_dir, "metadata_conda_debug.yaml"))
if m.config.verbose:
m_copy = m.copy()
for om, _, _ in render_metadata_tuples([(m_copy, False, False)], m_copy.config):
print("", "Rendered as:", "```yaml", output_yaml(om).rstrip(), "```", "", sep="\n")
# Each iteration returns the whole meta yaml, and then we are supposed to remove
# the outputs we don't want. Instead we just take the first and print it fully
break
del m_copy

# get_dir here might be just work, or it might be one level deeper,
# dependening on the source.
Expand Down
54 changes: 53 additions & 1 deletion conda_build/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from conda.base.context import context
from conda.cli.common import specs_from_url
from conda.core.package_cache_data import ProgressiveFetchExtract
from conda.exceptions import UnsatisfiableError
from conda.exceptions import NoPackagesFoundError, UnsatisfiableError
from conda.gateways.disk.create import TemporaryDirectory
from conda.models.records import PackageRecord
from conda.models.version import VersionOrder
Expand Down Expand Up @@ -999,6 +999,58 @@ def render_recipe(
bypass_env_check=bypass_env_check,
)

def render_metadata_tuples(
metadata_tuples: Iterable[MetaDataTuple],
config: Config,
permit_unsatisfiable_variants: bool = True,
finalize: bool = True,
bypass_env_check: bool = False
) -> list[MetaDataTuple]:
output_metas: dict[tuple[str, str, tuple[tuple[str, str], ...]], MetaDataTuple] = {}
for meta, download, render_in_env in metadata_tuples:
if not meta.skip() or not config.trim_skip:
for od, om in meta.get_output_metadata_set(
permit_unsatisfiable_variants=permit_unsatisfiable_variants,
permit_undefined_jinja=not finalize,
bypass_env_check=bypass_env_check,
):
if not om.skip() or not config.trim_skip:
if "type" not in od or od["type"] == "conda":
if finalize and not om.final:
try:
om = finalize_metadata(
om,
permit_unsatisfiable_variants=permit_unsatisfiable_variants,
)
except (DependencyNeedsBuildingError, NoPackagesFoundError):
if not permit_unsatisfiable_variants:
raise

# remove outputs section from output objects for simplicity
if not om.path and (outputs := om.get_section("outputs")):
om.parent_outputs = outputs
del om.meta["outputs"]

output_metas[
om.dist(),
om.config.variant.get("target_platform"),
tuple(
(var, om.config.variant[var])
for var in om.get_used_vars()
),
] = MetaDataTuple(om, download, render_in_env)
else:
output_metas[
f"{om.type}: {om.name()}",
om.config.variant.get("target_platform"),
tuple(
(var, om.config.variant[var])
for var in om.get_used_vars()
),
] = MetaDataTuple(om, download, render_in_env)

return list(output_metas.values())


# Keep this out of the function below so it can be imported by other modules.
FIELDS = [
Expand Down

0 comments on commit 70f9c16

Please sign in to comment.