Beispiel #1
0
def main(args: Any = None) -> None:
    mctx, *_, migrators = initialize_migrators()

    for migrator in migrators:
        if isinstance(migrator, GraphMigrator):
            migrator_name = migrator.__class__.__name__.lower()
            print(migrator_name)
            print("=" * len(migrator_name))
            status, build_order, gv = migrator_status(migrator, mctx.graph)
            o = yaml.safe_dump(status, default_flow_style=False)
            print(o)
            print("\n\n")
Beispiel #2
0
def main(args: Any = None) -> None:
    import requests

    r = requests.get(
        "https://raw.githubusercontent.com/conda-forge/"
        "conda-forge.github.io/main/img/anvil.svg", )

    # cache these for later
    if os.path.exists("status/closed_status.json"):
        with open("status/closed_status.json") as fp:
            old_closed_status = json.load(fp)
    else:
        old_closed_status = {}

    with open("status/total_status.json") as fp:
        old_total_status = json.load(fp)

    mctx, *_, migrators = initialize_migrators()
    if not os.path.exists("./status"):
        os.mkdir("./status")
    regular_status = {}
    longterm_status = {}

    print(" ", flush=True)

    for migrator in migrators:
        if hasattr(migrator, "name"):
            assert isinstance(migrator.name, str)
            migrator_name = migrator.name.lower().replace(" ", "")
        else:
            migrator_name = migrator.__class__.__name__.lower()

        print(
            "================================================================",
            flush=True,
        )
        print("name:", migrator_name, flush=True)

        if isinstance(migrator, GraphMigrator) or isinstance(
                migrator, Replacement):
            if isinstance(migrator, GraphMigrator):
                mgconf = yaml.safe_load(
                    getattr(migrator, "yaml_contents", "{}")).get(
                        "__migrator",
                        {},
                    )
                if (mgconf.get("longterm", False)
                        or isinstance(migrator, ArchRebuild)
                        or isinstance(migrator, OSXArm)):
                    longterm_status[
                        migrator_name] = f"{migrator.name} Migration Status"
                else:
                    regular_status[
                        migrator_name] = f"{migrator.name} Migration Status"
            else:
                regular_status[
                    migrator_name] = f"{migrator.name} Migration Status"
            status, build_order, gv = graph_migrator_status(
                migrator, mctx.graph)
            num_viz = status.pop("_num_viz", 0)
            with open(os.path.join(f"./status/{migrator_name}.json"),
                      "w") as fp:
                json.dump(status, fp, indent=2)

            if num_viz <= 500:
                d = gv.pipe("dot")
                with tempfile.NamedTemporaryFile(suffix=".dot") as ntf:
                    ntf.write(d)
                    # make the graph a bit more compact
                    d = Source(
                        subprocess.check_output([
                            "unflatten", "-f", "-l", "5", "-c", "10",
                            f"{ntf.name}"
                        ], ).decode("utf-8"), ).pipe("svg")
                with open(os.path.join(f"./status/{migrator_name}.svg"),
                          "wb") as fb:
                    fb.write(d or gv.pipe("svg"))
            else:
                with open(os.path.join(f"./status/{migrator_name}.svg"),
                          "wb") as fb:
                    fb.write(r.content)

        elif isinstance(migrator, Version):
            write_version_migrator_status(migrator, mctx)

        print(" ", flush=True)

    print("writing data", flush=True)
    with open("./status/regular_status.json", "w") as f:
        json.dump(regular_status, f, sort_keys=True, indent=2)

    with open("./status/longterm_status.json", "w") as f:
        json.dump(longterm_status, f, sort_keys=True, indent=2)

    total_status = {}
    total_status.update(regular_status)
    total_status.update(longterm_status)
    with open("./status/total_status.json", "w") as f:
        json.dump(total_status, f, sort_keys=True, indent=2)

    closed_status = _compute_recently_closed(
        total_status,
        old_closed_status,
        old_total_status,
    )
    with open("./status/closed_status.json", "w") as f:
        json.dump(closed_status, f, sort_keys=True, indent=2)

    print("\ncomputing feedstock and PR stats", flush=True)

    def _get_needs_help(k):
        v = mctx.graph.nodes[k]
        if (len([
                z for z in v.get("payload", {}).get("PRed", [])
                if z.get("PR", {}).get("state", "closed") == "open"
                and z.get("data", {}).get("migrator_name", "") == "Version"
        ], ) >= Version.max_num_prs):
            return k
        else:
            return None

    lst = _collect_items_from_nodes(mctx.graph, _get_needs_help)
    with open("./status/could_use_help.json", "w") as f:
        json.dump(
            sorted(
                lst,
                key=lambda z: (len(nx.descendants(mctx.graph, z)), lst),
                reverse=True,
            ),
            f,
            indent=2,
        )

    lm = LicenseMigrator()

    def _get_needs_license(k):
        v = mctx.graph.nodes[k]
        if not lm.filter(v.get("payload", {})):
            return k
        else:
            return None

    lst = _collect_items_from_nodes(mctx.graph, _get_needs_license)
    with open("./status/unlicensed.json", "w") as f:
        json.dump(
            sorted(
                lst,
                key=lambda z: (len(nx.descendants(mctx.graph, z)), lst),
                reverse=True,
            ),
            f,
            indent=2,
        )

    def _get_open_pr_states(k):
        attrs = mctx.graph.nodes[k]
        _open_prs = []
        for pr in attrs.get("PRed", []):
            if pr.get("PR", {}).get("state", "closed") != "closed":
                _open_prs.append(pr["PR"])

        return _open_prs

    open_prs = []
    for op in _collect_items_from_nodes(mctx.graph, _get_open_pr_states):
        open_prs.extend(op)
    merge_state_count = Counter([o["mergeable_state"] for o in open_prs])
    with open("./status/pr_state.csv", "a") as f:
        writer = csv.writer(f)
        writer.writerow([merge_state_count[k] for k in GH_MERGE_STATE_STATUS])
Beispiel #3
0
def main(args: Any = None) -> None:
    mctx, *_, migrators = initialize_migrators()
    if not os.path.exists("./status"):
        os.mkdir("./status")
    total_status = {}

    for migrator in migrators:
        if isinstance(migrator, GraphMigrator) or isinstance(
                migrator, Replacement):
            if hasattr(migrator, "name"):
                assert isinstance(migrator.name, str)
                migrator_name = migrator.name.lower().replace(" ", "")
            else:
                migrator_name = migrator.__class__.__name__.lower()
            total_status[migrator_name] = f"{migrator.name} Migration Status"
            status, build_order, gv = graph_migrator_status(
                migrator, mctx.graph)
            with open(os.path.join(f"./status/{migrator_name}.json"),
                      "w") as fp:
                json.dump(status, fp, indent=2)

            d = gv.pipe("dot")
            with tempfile.NamedTemporaryFile(suffix=".dot") as ntf:
                ntf.write(d)
                # make the graph a bit more compact
                d = Source(
                    subprocess.check_output([
                        "unflatten", "-f", "-l", "5", "-c", "10", f"{ntf.name}"
                    ], ).decode("utf-8"), ).pipe("svg")
            with open(os.path.join(f"./status/{migrator_name}.svg"),
                      "wb") as fb:
                fb.write(d or gv.pipe("svg"))
        elif isinstance(migrator, Version):
            write_version_migrator_status(migrator, mctx)

    with open("./status/total_status.json", "w") as f:
        json.dump(total_status, f, sort_keys=True)

    lst = [
        k for k, v in mctx.graph.nodes.items() if len([
            z for z in v.get("payload", {}).get("PRed", [])
            if z.get("PR", {}).get("state", "closed") == "open"
            and z.get("data", {}).get("migrator_name", "") == "Version"
        ], ) >= Version.max_num_prs
    ]
    with open("./status/could_use_help.json", "w") as f:
        json.dump(
            sorted(
                lst,
                key=lambda z: (len(nx.descendants(mctx.graph, z)), lst),
                reverse=True,
            ),
            f,
            indent=2,
        )

    lm = LicenseMigrator()
    lst = [
        k for k, v in mctx.graph.nodes.items()
        if not lm.filter(v.get("payload", {}))
    ]
    with open("./status/unlicensed.json", "w") as f:
        json.dump(
            sorted(
                lst,
                key=lambda z: (len(nx.descendants(mctx.graph, z)), lst),
                reverse=True,
            ),
            f,
            indent=2,
        )