13
13
14
14
ROOT_PATH = Path (__file__ ).parent .parent
15
15
CHANGELOG = ROOT_PATH / "docs" / "changelog.rst"
16
- README = ROOT_PATH / "README.md "
16
+ USAGE = ROOT_PATH / "docs" / "usage.rst "
17
17
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
18
18
19
+ ALLOW_FUTURE = "--allow-future-in-changelog" in sys .argv
20
+
19
21
T = TypeVar ("T" , bound = "Version" )
20
22
21
23
@@ -44,6 +46,7 @@ def get_releases() -> Iterable[Version]:
44
46
valid_pattern = re .compile (r"^(\d\d\.\d?\d\.\d?\d)$" )
45
47
header_pattern = re .compile (r"^=+$" )
46
48
last_line_was_date = False
49
+ last_line : str | None = None
47
50
with open (CHANGELOG , encoding = "utf-8" ) as f :
48
51
lines = f .readlines ()
49
52
for line in lines :
@@ -54,15 +57,21 @@ def get_releases() -> Iterable[Version]:
54
57
elif version_match :
55
58
yield Version .from_string (version_match .group (1 ))
56
59
last_line_was_date = True
57
- else :
58
- # stop lines such as `Future\n=====` making it through to main/
59
- assert not header_pattern .match (line ), line
60
+ # only allow `Future\n=====` when run in pre-commit
61
+ elif header_pattern .match (line ):
62
+ assert ALLOW_FUTURE , "FUTURE header with no --allow-future-in-changelog. "
63
+ assert last_line is not None
64
+ assert last_line .lower ().strip () == "future"
65
+ last_line = line
60
66
61
67
62
68
def test_last_release_against_changelog () -> None :
63
- """Ensure we have the latest version covered in 'changelog.rst'."""
69
+ """Ensure we have the latest version covered in 'changelog.rst'.
70
+
71
+ If changelog version is greater, the __init__ gets bumped in update_version().
72
+ """
64
73
latest_release = next (iter (get_releases ()))
65
- assert latest_release == VERSION
74
+ assert latest_release >= VERSION , f" { latest_release } , { VERSION } "
66
75
67
76
68
77
def test_version_increments_are_correct () -> None :
@@ -98,20 +107,27 @@ def update_version() -> None:
98
107
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
99
108
subs = (f'__version__ = "{ VERSION } "' , f'__version__ = "{ last_version } "' )
100
109
INIT_FILE .write_text (INIT_FILE .read_text ().replace (* subs ))
110
+ print ("updated VERSION in __init__.py" )
101
111
102
112
# Similarly, update the pre-commit config example in the README
103
- current = README .read_text ()
113
+ current = USAGE .read_text ()
104
114
wanted = re .sub (
105
- pattern = r"^ rev: (\d+\.\d+\.\d+)$" ,
106
- repl = f" rev: { last_version } " ,
115
+ pattern = r"^ rev: (\d+\.\d+\.\d+)$" ,
116
+ repl = f" rev: { last_version } " ,
107
117
string = current ,
108
118
flags = re .MULTILINE ,
109
119
)
120
+ if last_version != VERSION :
121
+ assert current != wanted , "version changed but regex didn't substitute"
110
122
if current != wanted :
111
- README .write_text (wanted )
123
+ USAGE .write_text (wanted )
124
+ print ("updated rev in pre-commit example" )
112
125
113
126
114
127
if __name__ == "__main__" :
128
+ test_last_release_against_changelog ()
129
+ test_version_increments_are_correct ()
130
+
115
131
update_version ()
116
132
if "--ensure-tag" in sys .argv :
117
133
ensure_tagged ()
0 commit comments