def test_select_lines(): lines = """ test test [abc] no test [abc] # no test [abc] 'quoted # [abc] ' "quoted # [abc] yes " test # stuff [abc] yes test {{ JINJA_VAR[:2] }} test {{ JINJA_VAR[:2] }} # stuff [abc] yes test {{ JINJA_VAR[:2] }} # stuff yes [abc] test {{ JINJA_VAR[:2] }} # [abc] stuff yes {{ environ["test"] }} # [abc] """ assert select_lines(lines, {'abc': True}) == """ test test [abc] no test [abc] # no test 'quoted' "quoted" test test {{ JINJA_VAR[:2] }} test {{ JINJA_VAR[:2] }} test {{ JINJA_VAR[:2] }} test {{ JINJA_VAR[:2] }} {{ environ["test"] }} """ assert select_lines(lines, {'abc': False}) == """
def parse_variant( variant_file_content: str, config: Optional[Config] = None ) -> Dict[str, Union[List[str], float, List[List[str]], Dict[str, Dict[ str, str]], Dict[str, Dict[str, List[str]]], ], ]: """ Parameters ---------- variant_file_content : str The loaded vaiant contents. This can include selectors etc. """ if not config: from conda_build.config import Config config = Config() from conda_build.metadata import select_lines, ns_cfg contents = select_lines(variant_file_content, ns_cfg(config), variants_in_place=False) content = yaml.load(contents, Loader=yaml.loader.BaseLoader) or {} variants.trim_empty_keys(content) # TODO: Base this default on mtime or something content["migration_ts"] = float(content.get("migration_ts", -1.0)) return content
def parse_config_file(path, config): from conda_build.metadata import select_lines, ns_cfg with open(path) as f: contents = f.read() contents = select_lines(contents, ns_cfg(config)) content = yaml.load(contents, Loader=yaml.loader.BaseLoader) return content
def parse_config_file(path, config): from conda_build.metadata import select_lines, ns_cfg with open(path) as f: contents = f.read() contents = select_lines(contents, ns_cfg(config), variants_in_place=False) content = yaml.load(contents, Loader=yaml.loader.BaseLoader) or {} trim_empty_keys(content) return content
def test_select_lines(): lines = """ test test [abc] no test [abc] test # [abc] test # [abc] yes test # stuff [abc] yes """ assert select_lines(lines, {'abc': True}) == """ test test [abc] no test test test test """ assert select_lines(lines, {'abc': False}) == """
def load_packages_from_conda_build_config(conda_build_config, condarc_options): with open(conda_build_config, "r") as f: content = f.read() idx1 = content.find("# AUTOMATIC PARSING START") idx2 = content.find("# AUTOMATIC PARSING END") content = content[idx1:idx2] # filter out using conda-build specific markers from conda_build.metadata import ns_cfg, select_lines config = make_conda_config(conda_build_config, None, None, condarc_options) content = select_lines(content, ns_cfg(config), variants_in_place=False) package_pins = yaml.safe_load(content) package_names_map = package_pins.pop("package_names_map") packages = [package_names_map.get(p, p) for p in package_pins.keys()] return packages, package_names_map