/
niceSOFT
/
python3-trove_classifiers
Обзор
Документация
Войти
/
niceSOFT
/
python3-trove_classifiers
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
bin/sort.py
34 строки
796 B
Hugo van Kemenade
Sort classifiers by version and add 'classifiers_sorted' function (#57)
28 фев 2021, 16:57
Не верифицирован
28 фев 2021, 16:57
1b3b784
Код
Авторство
О чём код?
import ast import sys from natsort import natsorted def _test_sort(elements, _type): values = [e.value for e in elements] for wrong, right in zip(values, natsorted(values)): if wrong != right: print(f"{_type} is not sorted, {right!r} should come before {wrong!r}") return True return False if len(sys.argv) == 1: print("Usage: sort.py [filename]") sys.exit(1) with open(sys.argv[1]) as f: contents = f.read() fail = False for node in ast.walk(ast.parse(contents)): if type(node) == ast.List: fail = _test_sort(node.elts, "List") or fail if type(node) == ast.Set: fail = _test_sort(node.elts, "Set") or fail if type(node) == ast.Dict: fail = _test_sort(node.keys, "Dict") or fail sys.exit(fail)