Skip to content

Commit 3c56e75

Browse files
authored
Enforce order for elements in unordered data structures (#33)
* Lint for order of set/dict elements * Fix linting order There isn't a great way to make these come in the order that would be logical to humans. Given that this is how these will also be presented at https://pypi.org/classifiers/, we should sort them the same as they are there until we find a better way to order these.
1 parent 1b648a7 commit 3c56e75

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ test: .state/env/pyvenv.cfg
1616

1717
lint: .state/env/pyvenv.cfg
1818
$(BINDIR)/black --check tests trove_classifiers
19+
$(BINDIR)/python bin/sort.py trove_classifiers/__init__.py
1920

2021
reformat: .state/env/pyvenv.cfg
2122
$(BINDIR)/black tests trove_classifiers

bin/sort.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import ast
2+
3+
import sys
4+
5+
6+
def _test_sort(elements, _type):
7+
values = [e.value for e in elements]
8+
for wrong, right in zip(values, sorted(values)):
9+
if wrong != right:
10+
print(f"{_type} is not sorted, {right!r} should come before {wrong!r}")
11+
return True
12+
return False
13+
14+
15+
if len(sys.argv) == 1:
16+
print("Usage: ssort.py [filename]")
17+
sys.exit(1)
18+
19+
20+
with open(sys.argv[1]) as f:
21+
contents = f.read()
22+
23+
fail = False
24+
25+
for node in ast.walk(ast.parse(contents)):
26+
if type(node) == ast.Set:
27+
fail = _test_sort(node.elts, "Set") or fail
28+
if type(node) == ast.Dict:
29+
fail = _test_sort(node.keys, "Dict") or fail
30+
31+
sys.exit(fail)

trove_classifiers/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"Environment :: GPU :: NVIDIA CUDA",
1717
"Environment :: GPU :: NVIDIA CUDA :: 1.0",
1818
"Environment :: GPU :: NVIDIA CUDA :: 1.1",
19+
"Environment :: GPU :: NVIDIA CUDA :: 10.0",
20+
"Environment :: GPU :: NVIDIA CUDA :: 10.1",
21+
"Environment :: GPU :: NVIDIA CUDA :: 10.2",
1922
"Environment :: GPU :: NVIDIA CUDA :: 2.0",
2023
"Environment :: GPU :: NVIDIA CUDA :: 2.1",
2124
"Environment :: GPU :: NVIDIA CUDA :: 2.2",
@@ -36,9 +39,6 @@
3639
"Environment :: GPU :: NVIDIA CUDA :: 9.0",
3740
"Environment :: GPU :: NVIDIA CUDA :: 9.1",
3841
"Environment :: GPU :: NVIDIA CUDA :: 9.2",
39-
"Environment :: GPU :: NVIDIA CUDA :: 10.0",
40-
"Environment :: GPU :: NVIDIA CUDA :: 10.1",
41-
"Environment :: GPU :: NVIDIA CUDA :: 10.2",
4242
"Environment :: Handhelds/PDA's",
4343
"Environment :: MacOS X",
4444
"Environment :: MacOS X :: Aqua",

0 commit comments

Comments
 (0)