docs/support/requirements_to_rst.py
def proc_requirements(mobj):
    """Get requirements in reStructuredText format."""
    pyvers = ["py{0}".format(item.replace(".", "")) for item in get_supported_interps()]
    py2vers = sorted([item for item in pyvers if item.startswith("py2")])
    py3vers = sorted([item for item in pyvers if item.startswith("py3")])
    fdict = json_load(os.path.join("data", "requirements.json"))
    olines = [""]
    sdict = dict([(item["name"], item) for item in fdict.values()])
    for real_name in sorted(sdict.keys()):
        pkg_dict = sdict[real_name]
        if pkg_dict["cat"] == ["rtd"]:
            continue
        plist = [] if not pkg_dict["optional"] else ["optional"]
        # Convert instances that have a single version for all Python
        # interpreters into a full dictionary of Python interpreter and
        # package versions # so as to apply the same algorithm in all cases
        if isinstance(pkg_dict["ver"], str):
            pkg_dict["ver"] = dict([(pyver, pkg_dict["ver"]) for pyver in pyvers])
        pkg_pyvers = sorted(pkg_dict["ver"].keys())
        pkg_py2vers = sorted(
            [item for item in pkg_dict["ver"].keys() if item.startswith("py2")]
        )
        req_vers = list(set(pkg_dict["ver"].values()))
        req_py2vers = list(
            set([pkg_dict["ver"][item] for item in py2vers if item in pkg_dict["ver"]])
        )
        req_py3vers = list(
            set([pkg_dict["ver"][item] for item in py3vers if item in pkg_dict["ver"]])
        )
        if (len(req_vers) == 1) and (pkg_pyvers == pyvers):
            plist.append(ops_to_words(req_vers[0]))
        elif (
            (pkg_pyvers == pyvers)
            and (len(req_py2vers) == 1)
            and (len(req_py3vers) == 1)
        ):
            make_common_entry(plist, "2", ": ", req_py2vers[0])
            make_common_entry(plist, "3", ": ", req_py3vers[0])
        elif (
            (pkg_pyvers == pyvers)
            and (len(req_py2vers) == len(py2vers))
            and (len(req_py3vers) == 1)
            and (pkg_dict["ver"][pkg_py2vers[-1]] == req_py3vers[0])
        ):
            py2dict = dict(
                [
                    (key, value)
                    for key, value in pkg_dict["ver"].items()
                    if key.startswith("py2") and (key != pkg_py2vers[-1])
                ]
            )
            make_multi_entry(plist, py2vers[:-1], py2dict)
            pver = pkg_py2vers[-1][2] + "." + pkg_py2vers[-1][3:]
            plist.append(
                "Python {pyver} or newer: {ver}".format(
                    pyver=pver, ver=ops_to_words(req_py3vers[0])
                )
            )
        elif (
            (pkg_pyvers == pyvers)
            and (len(req_py2vers) == len(py2vers))
            and (len(req_py3vers) == 1)
        ):
            py2dict = dict(
                [
                    (key, value)
                    for key, value in pkg_dict["ver"].items()
                    if key.startswith("py2")
                ]
            )
            make_multi_entry(plist, py2vers, py2dict)
            make_common_entry(plist, "3", ": ", req_py3vers[0])
        elif (
            (pkg_pyvers == pyvers)
            and (len(req_py3vers) == len(py3vers))
            and (len(req_py2vers) == 1)
        ):
            py3dict = dict(
                [
                    (key, value)
                    for key, value in pkg_dict["ver"].items()
                    if key.startswith("py3")
                ]
            )
            make_common_entry(plist, "2", ": ", req_py2vers[0])
            make_multi_entry(plist, py3vers, py3dict)
        elif (len(req_vers) == 1) and (pkg_pyvers == py2vers):
            make_common_entry(plist, "2", " only, ", req_vers[0])
        elif (len(req_vers) == 1) and (pkg_pyvers == py3vers):
            make_common_entry(plist, "3", " only, ", req_vers[0])
        else:
            make_multi_entry(plist, pkg_pyvers, pkg_dict["ver"])
        olines.append(
            "    * `{name}`_ ({par})".format(
                name=pkg_dict["name"], par=", ".join(plist)
            )
        )
    ret = []
    for line in olines:
        wobj = textwrap.wrap(line, width=LINE_WIDTH, subsequent_indent="      ")
        ret.append("\n".join([item for item in wobj]))

    mobj.out("\n\n".join(ret) + "\n\n")
def proc_requirements(mobj):
    """Get requirements in reStructuredText format."""
    pyvers = ["py{0}".format(item.replace(".", "")) for item in get_supported_interps()]
    py2vers = sorted([item for item in pyvers if item.startswith("py2")])
    py3vers = sorted([item for item in pyvers if item.startswith("py3")])
    fdict = json_load(os.path.join("data", "requirements.json"))
    olines = [""]
    sdict = dict([(item["name"], item) for item in fdict.values()])
    for real_name in sorted(sdict.keys()):
        pkg_dict = sdict[real_name]
        if pkg_dict["cat"] == ["rtd"]:
            continue
        plist = [] if not pkg_dict["optional"] else ["optional"]
        # Convert instances that have a single version for all Python
        # interpreters into a full dictionary of Python interpreter and
        # package versions # so as to apply the same algorithm in all cases
        if isinstance(pkg_dict["ver"], str):
            pkg_dict["ver"] = dict([(pyver, pkg_dict["ver"]) for pyver in pyvers])
        pkg_pyvers = sorted(pkg_dict["ver"].keys())
        pkg_py2vers = sorted(
            [item for item in pkg_dict["ver"].keys() if item.startswith("py2")]
        )
        req_vers = list(set(pkg_dict["ver"].values()))
        req_py2vers = list(
            set([pkg_dict["ver"][item] for item in py2vers if item in pkg_dict["ver"]])
        )
        req_py3vers = list(
            set([pkg_dict["ver"][item] for item in py3vers if item in pkg_dict["ver"]])
        )
        if (len(req_vers) == 1) and (pkg_pyvers == pyvers):
            plist.append(ops_to_words(req_vers[0]))
        elif (
            (pkg_pyvers == pyvers)
            and (len(req_py2vers) == 1)
            and (len(req_py3vers) == 1)
        ):
            make_common_entry(plist, "2", ": ", req_py2vers[0])
            make_common_entry(plist, "3", ": ", req_py3vers[0])
        elif (
            (pkg_pyvers == pyvers)
            and (len(req_py2vers) == len(py2vers))
            and (len(req_py3vers) == 1)
            and (pkg_dict["ver"][pkg_py2vers[-1]] == req_py3vers[0])
        ):
            py2dict = dict(
                [
                    (key, value)
                    for key, value in pkg_dict["ver"].items()
                    if key.startswith("py2") and (key != pkg_py2vers[-1])
                ]
            )
            make_multi_entry(plist, py2vers[:-1], py2dict)
            pver = pkg_py2vers[-1][2] + "." + pkg_py2vers[-1][3:]
            plist.append(
                "Python {pyver} or newer: {ver}".format(
                    pyver=pver, ver=ops_to_words(req_py3vers[0])
                )
            )
        elif (
            (pkg_pyvers == pyvers)
            and (len(req_py2vers) == len(py2vers))
            and (len(req_py3vers) == 1)
        ):
            py2dict = dict(
                [
                    (key, value)
                    for key, value in pkg_dict["ver"].items()
                    if key.startswith("py2")
                ]
            )
            make_multi_entry(plist, py2vers, py2dict)
            make_common_entry(plist, "3", ": ", req_py3vers[0])
        elif (
            (pkg_pyvers == pyvers)
            and (len(req_py3vers) == len(py3vers))
            and (len(req_py2vers) == 1)
        ):
            py3dict = dict(
                [
                    (key, value)
                    for key, value in pkg_dict["ver"].items()
                    if key.startswith("py3")
                ]
            )
            make_common_entry(plist, "2", ": ", req_py2vers[0])
            make_multi_entry(plist, py3vers, py3dict)
        elif (len(req_vers) == 1) and (pkg_pyvers == py2vers):
            make_common_entry(plist, "2", " only, ", req_vers[0])
        elif (len(req_vers) == 1) and (pkg_pyvers == py3vers):
            make_common_entry(plist, "3", " only, ", req_vers[0])
        else:
            make_multi_entry(plist, pkg_pyvers, pkg_dict["ver"])
        olines.append(
            "    * `{name}`_ ({par})".format(
                name=pkg_dict["name"], par=", ".join(plist)
            )
        )
    ret = []
    for line in olines:
        wobj = textwrap.wrap(line, width=LINE_WIDTH, subsequent_indent="      ")
        ret.append("\n".join([item for item in wobj]))

    mobj.out("\n\n".join(ret) + "\n\n")
Get requirements in reStructuredText format.