1#!/usr/bin/env python3
2"""
3Checks that the version of the projects bundled in ensurepip are the latest
4versions available.
5"""
6import ensurepip
7import json
8import urllib.request
9import sys
10
11
12def main():
13    outofdate = False
14
15    for project, version in ensurepip._PROJECTS:
16        data = json.loads(urllib.request.urlopen(
17            "https://pypi.org/pypi/{}/json".format(project),
18            cadefault=True,
19        ).read().decode("utf8"))
20        upstream_version = data["info"]["version"]
21
22        if version != upstream_version:
23            outofdate = True
24            print("The latest version of {} on PyPI is {}, but ensurepip "
25                  "has {}".format(project, upstream_version, version))
26
27    if outofdate:
28        sys.exit(1)
29
30
31if __name__ == "__main__":
32    main()
33