def parse_meta_yaml( text: str, for_pinning=False, platform=None, arch=None, recipe_dir=None, cbc_path=None, **kwargs: Any, ) -> "MetaYamlTypedDict": """Parse the meta.yaml. Parameters ---------- text : str The raw text in conda-forge feedstock meta.yaml file Returns ------- dict : The parsed YAML dict. If parsing fails, returns an empty dict. """ from conda_build.config import Config from conda_build.metadata import parse, ns_cfg if (recipe_dir is not None and cbc_path is not None and arch is not None and platform is not None): cbc = Config( platform=platform, arch=arch, variant_config_files=[cbc_path], **kwargs, ) cfg_as_dict = ns_cfg(cbc) with open(cbc_path, "r") as fp: _cfg_as_dict = yaml.load(fp, Loader=yaml.Loader) for k, v in _cfg_as_dict.items(): if (isinstance(v, list) and not isinstance(v, str) and len(v) > 0 and k not in ["zip_keys", "pin_run_as_build"]): v = v[0] cfg_as_dict[k] = v else: _cfg = {} _cfg.update(kwargs) if platform is not None: _cfg["platform"] = platform if arch is not None: _cfg["arch"] = arch cbc = Config(**_cfg) cfg_as_dict = {} if for_pinning: content = render_meta_yaml(text, for_pinning=for_pinning, **cfg_as_dict) else: content = render_meta_yaml(text, **cfg_as_dict) return parse(content, cbc)
def parsed_meta_yaml(text): """ :param str text: The raw text in conda-forge feedstock meta.yaml file :return: `dict|None` -- parsed YAML dict if successful, None if not """ try: yaml_dict = parse(Template(text).render(), Config()) except UndefinedError: # assume we hit a RECIPE_DIR reference in the vars and can't parse it. # just erase for now try: yaml_dict = parse( Template( re.sub('{{ (environ\[")?RECIPE_DIR("])? }}/', '', text) ).render(), Config()) except Exception as e: print(e) return None except Exception as e: print(e) return None return yaml_dict
def parse_meta_yaml(text): """Parse the meta.yaml. Parameters ---------- text : str The raw text in conda-forge feedstock meta.yaml file Returns ------- dict : The parsed YAML dict. If parseing fails, returns an empty dict. """ content = render_meta_yaml(text) return parse(content, Config())
def parsed_meta_yaml(text): """ :param str text: The raw text in conda-forge feedstock meta.yaml file :return: `dict|None` -- parsed YAML dict if successful, None if not """ try: env = jinja2.Environment(undefined=NullUndefined) content = env.from_string(text).render( os=os, environ=defaultdict(lambda: ''), compiler=lambda x: x + '_compiler_stub', pin_subpackage=lambda *args, **kwargs: 'subpackage_stub', pin_compatible=lambda *args, **kwargs: 'compatible_pin_stub', cdt=lambda *args, **kwargs: 'cdt_stub',) return parse(content, Config()) except: return {}
def parse_meta_yaml(text, **kwargs): """Parse the meta.yaml. Parameters ---------- text : str The raw text in conda-forge feedstock meta.yaml file Returns ------- dict : The parsed YAML dict. If parseing fails, returns an empty dict. """ from conda_build.config import Config from conda_build.metadata import parse content = render_meta_yaml(text) return parse(content, Config(**kwargs))
def parse_meta_yaml(text: str, for_pinning=False, **kwargs: Any) -> "MetaYamlTypedDict": """Parse the meta.yaml. Parameters ---------- text : str The raw text in conda-forge feedstock meta.yaml file Returns ------- dict : The parsed YAML dict. If parsing fails, returns an empty dict. """ from conda_build.config import Config from conda_build.metadata import parse if for_pinning: content = render_meta_yaml(text, for_pinning=for_pinning) else: content = render_meta_yaml(text) return parse(content, Config(**kwargs))
def _parse_meta_yaml_impl( text: str, for_pinning=False, platform=None, arch=None, recipe_dir=None, cbc_path=None, log_debug=False, **kwargs: Any, ) -> "MetaYamlTypedDict": from conda_build.config import Config from conda_build.metadata import parse, MetaData import conda_build.api import conda_build.environ from conda_build.variants import explode_variants if (recipe_dir is not None and cbc_path is not None and arch is not None and platform is not None): with tempfile.TemporaryDirectory() as tmpdir: with open(os.path.join(tmpdir, "meta.yaml"), "w") as fp: fp.write(text) def _run_parsing(): config = conda_build.config.get_or_merge_config( None, platform=platform, arch=arch, exclusive_config_file=cbc_path, ) _cbc, _ = conda_build.variants.get_package_combined_spec( tmpdir, config=config, ) return config, _cbc if not log_debug: fout = io.StringIO() ferr = io.StringIO() with sys_pipes(), contextlib.redirect_stdout( fout, ), contextlib.redirect_stderr(ferr): config, _cbc = _run_parsing() else: config, _cbc = _run_parsing() cfg_as_dict = {} for var in explode_variants(_cbc): try: m = MetaData(tmpdir, config=config, variant=var) except SystemExit as e: raise RuntimeError(str(e)) cfg_as_dict.update(conda_build.environ.get_dict(m=m)) logger.debug("jinja2 environmment:\n%s", pprint.pformat(cfg_as_dict)) cbc = Config( platform=platform, arch=arch, variant=cfg_as_dict, **kwargs, ) else: _cfg = {} _cfg.update(kwargs) if platform is not None: _cfg["platform"] = platform if arch is not None: _cfg["arch"] = arch cbc = Config(**_cfg) cfg_as_dict = {} if for_pinning: content = render_meta_yaml(text, for_pinning=for_pinning, **cfg_as_dict) else: content = render_meta_yaml(text, **cfg_as_dict) try: return parse(content, cbc) except Exception: logger.debug("template: %s", text) logger.debug("context:\n%s", pprint.pformat(cfg_as_dict)) raise