Example #1
0
    def skip(self):
        skips = self.sections["build"].get("skip")

        if skips:
            return any(
                [eval_selector(x, ns_cfg(self.config), []) for x in skips])
        return False
Example #2
0
def flatten_selectors(ydoc, namespace):
    if isinstance(ydoc, str):
        return ydoc

    if isinstance(ydoc, collections.Mapping):
        has_sel = any(k.startswith('sel(') for k in ydoc.keys())
        # print(f"Has sel: {has_sel}")
        if has_sel:
            for k, v in ydoc.items():
                selected = eval_selector(k[3:], namespace, [])
                if selected:
                    return v

            return None

        for k, v in ydoc.items():
            # print(f"Checking {k}: {v}")
            ydoc[k] = flatten_selectors(v, namespace)

    elif isinstance(ydoc, collections.Iterable):
        to_delete = []
        for idx, el in enumerate(ydoc):
            res = flatten_selectors(el, namespace)
            if res == None:
                to_delete.append(idx)
            else:
                ydoc[idx] = res

        if len(to_delete):
            ydoc = [
                ydoc[idx] for idx in range(len(ydoc)) if idx not in to_delete
            ]

    return ydoc
Example #3
0
 def skip(self):
     skips = self.sections["build"].get("skip", [])
     skip_reasons = []
     for x in skips:
         if eval_selector(x, ns_cfg(self.config), []):
             skip_reasons.append(x)
     if len(skip_reasons):
         console.print(
             f"[green]Skipping {self.name} {' | '.join(self.differentiating_variant)} because of[/green]\n"
             + "\n".join([f"  - {x}" for x in skip_reasons]))
     return len(skip_reasons) != 0
Example #4
0
def flatten_selectors(ydoc, namespace):
    if isinstance(ydoc, str):
        return ydoc

    if isinstance(ydoc, collections.Mapping):
        has_sel = any(k.startswith("sel(") for k in ydoc.keys())
        if has_sel:
            for k, v in ydoc.items():
                selected = eval_selector(k[3:], namespace, [])
                if selected:
                    return v

            return None

        for k, v in ydoc.items():
            ydoc[k] = flatten_selectors(v, namespace)

    elif isinstance(ydoc, collections.Iterable):
        to_delete = []
        for idx, el in enumerate(ydoc):
            res = flatten_selectors(el, namespace)
            if res is None:
                to_delete.append(idx)
            else:
                ydoc[idx] = res

        if len(to_delete):
            ydoc = [
                ydoc[idx] for idx in range(len(ydoc)) if idx not in to_delete
            ]

        # flatten lists if necessary
        if any([isinstance(x, list) for x in ydoc]):
            final_list = []
            for x in ydoc:
                if isinstance(x, list):
                    final_list += x
                else:
                    final_list.append(x)
            ydoc = final_list

    return ydoc