#!/usr/bin/env python
import pprint
from collections import defaultdict

# The file ./magic-table has ben created with the following command in the python git repository:
# for tag in `git tag --list | grep v3`; do git checkout $tag &>/dev/null; printf "%10s  " $tag; (grep -IhEr '^MAGIC_NUMBER = ' || echo "not found") | cut -f1 -d.; done

with open("./magic-table") as fp:
    lines = fp.readlines()

magics = defaultdict(list)
for line in lines:
    line = line.strip()
    python_version, _, _, _, magic_number = line.split(" ")
    clean_magic = int(magic_number[1:-1])
    clean_python_version = python_version[1:]
    # use the latest full release that matches the magic number
    magics[clean_magic].insert(0, clean_python_version)
    # if clean_magic not in magics or clean_python_version.replace(".", "").isdecimal():

pprint.pprint(magics)
