15
15
import re
16
16
import subprocess
17
17
import sys
18
-
19
18
from pathlib import Path
20
19
21
20
ROOT_DIR = Path (__file__ ).parent
27
26
sys .exit (1 )
28
27
29
28
30
- old_version : str | None = None
29
+ old_version : str = None
31
30
32
31
33
32
def sub_version (m : re .Match [str ]) -> str :
@@ -72,7 +71,17 @@ def replace_deps_version(text: str) -> tuple[str, int]:
72
71
graph_pp_text = graph_pp .read_text ()
73
72
graph_pp_text , count_graph = replace_deps_version (graph_pp_text )
74
73
75
- if count_root == 2 and count_ex == 2 and count_slim == 2 and count_graph == 1 :
74
+ EXPECTED_COUNT_ROOT = 2
75
+ EXPECTED_COUNT_EX = 2
76
+ EXPECTED_COUNT_SLIM = 2
77
+ EXPECTED_COUNT_GRAPH = 1
78
+
79
+ if (
80
+ count_root == EXPECTED_COUNT_ROOT
81
+ and count_ex == EXPECTED_COUNT_EX
82
+ and count_slim == EXPECTED_COUNT_SLIM
83
+ and count_graph == EXPECTED_COUNT_GRAPH
84
+ ):
76
85
root_pp .write_text (root_pp_text )
77
86
examples_pp .write_text (examples_pp_text )
78
87
slim_pp .write_text (slim_pp_text )
@@ -81,20 +90,14 @@ def replace_deps_version(text: str) -> tuple[str, int]:
81
90
subprocess .run (['make' , 'sync' ], check = True )
82
91
print (f'running `git switch -c uprev-{ version } `...' )
83
92
subprocess .run (['git' , 'switch' , '-c' , f'uprev-{ version } ' ], check = True )
84
- print (
85
- f'SUCCESS: replaced version in\n '
86
- f' { root_pp } \n '
87
- f' { examples_pp } \n '
88
- f' { slim_pp } \n '
89
- f' { graph_pp } '
90
- )
93
+ print (f'SUCCESS: replaced version in\n { root_pp } \n { examples_pp } \n { slim_pp } \n { graph_pp } ' )
91
94
else :
92
95
print (
93
96
f'ERROR:\n '
94
- f' { count_root } version references in { root_pp } (expected 2 )\n '
95
- f' { count_ex } version references in { examples_pp } (expected 2 )\n '
96
- f' { count_slim } version references in { slim_pp } (expected 1)' ,
97
- f' { count_graph } version references in { graph_pp } (expected 1 )' ,
97
+ f' { count_root } version references in { root_pp } (expected { EXPECTED_COUNT_ROOT } )\n '
98
+ f' { count_ex } version references in { examples_pp } (expected { EXPECTED_COUNT_EX } )\n '
99
+ f' { count_slim } version references in { slim_pp } (expected { EXPECTED_COUNT_SLIM } ) \n '
100
+ f' { count_graph } version references in { graph_pp } (expected { EXPECTED_COUNT_GRAPH } )' ,
98
101
file = sys .stderr ,
99
102
)
100
103
sys .exit (1 )
0 commit comments