Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: script that discovers minimum tested versions #9418

Closed
wants to merge 11 commits into from
51 changes: 51 additions & 0 deletions all_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import csv
from typing import Dict
from typing import Set

from packaging.version import parse as parse_version

import riotfile


def tree_pkgs_from_riot() -> Dict[str, Set[str]]:

return _tree_pkgs_from_riot(riotfile.venv)


def _tree_pkgs_from_riot(node: riotfile.Venv) -> Dict[str, Set]:
emmettbutler marked this conversation as resolved.
Show resolved Hide resolved
result = {pkg: _format_version_specifiers(set(versions)) for pkg, versions in node.pkgs.items()}
for child_venv in node.venvs:
emmettbutler marked this conversation as resolved.
Show resolved Hide resolved
child_pkgs = _tree_pkgs_from_riot(child_venv)
for pkg_name, versions in child_pkgs.items():
if pkg_name in result:
result[pkg_name] = result[pkg_name].union(versions)
else:
result[pkg_name] = versions
return result


def _format_version_specifiers(spec: Set[str]) -> Set[str]:
return set([part.strip("~<>==") for v in [v.split(",") for v in spec if v] for part in v if "!=" not in part])


def write_out(all_pkgs: Dict[str, Set[str]]) -> None:
with open("min_versions.csv", "w") as csvfile:
csv_writer = csv.writer(csvfile, delimiter=",")
csv_writer.writerow(["pkg_name", "min_version"])
for pkg, versions in sorted(all_pkgs.items()):
min_version = "0"
if versions:
min_version = min((parse_version(v) for v in versions))
print("%s\n\tTested versions: %s\n\tMinimum: %s" % (pkg, sorted(list(versions)), min_version))
csv_writer.writerow([pkg, min_version])


def main():
"""Discover the minimum version of every package referenced in the riotfile

Writes to stdout and min_versions.csv
"""
write_out(tree_pkgs_from_riot())


main()
Loading