1313
1414ROOT_PATH = Path (__file__ ).parent .parent
1515CHANGELOG = ROOT_PATH / "docs" / "changelog.rst"
16- README = ROOT_PATH / "README.md "
16+ USAGE = ROOT_PATH / "docs" / "usage.rst "
1717INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
1818
19+ ALLOW_FUTURE = "--allow-future-in-changelog" in sys .argv
20+
1921T = TypeVar ("T" , bound = "Version" )
2022
2123
@@ -44,6 +46,7 @@ def get_releases() -> Iterable[Version]:
4446 valid_pattern = re .compile (r"^(\d\d\.\d?\d\.\d?\d)$" )
4547 header_pattern = re .compile (r"^=+$" )
4648 last_line_was_date = False
49+ last_line : str | None = None
4750 with open (CHANGELOG , encoding = "utf-8" ) as f :
4851 lines = f .readlines ()
4952 for line in lines :
@@ -54,15 +57,21 @@ def get_releases() -> Iterable[Version]:
5457 elif version_match :
5558 yield Version .from_string (version_match .group (1 ))
5659 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
6066
6167
6268def 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+ """
6473 latest_release = next (iter (get_releases ()))
65- assert latest_release == VERSION
74+ assert latest_release >= VERSION , f" { latest_release } , { VERSION } "
6675
6776
6877def test_version_increments_are_correct () -> None :
@@ -98,20 +107,27 @@ def update_version() -> None:
98107 INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
99108 subs = (f'__version__ = "{ VERSION } "' , f'__version__ = "{ last_version } "' )
100109 INIT_FILE .write_text (INIT_FILE .read_text ().replace (* subs ))
110+ print ("updated VERSION in __init__.py" )
101111
102112 # Similarly, update the pre-commit config example in the README
103- current = README .read_text ()
113+ current = USAGE .read_text ()
104114 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 } " ,
107117 string = current ,
108118 flags = re .MULTILINE ,
109119 )
120+ if last_version != VERSION :
121+ assert current != wanted , "version changed but regex didn't substitute"
110122 if current != wanted :
111- README .write_text (wanted )
123+ USAGE .write_text (wanted )
124+ print ("updated rev in pre-commit example" )
112125
113126
114127if __name__ == "__main__" :
128+ test_last_release_against_changelog ()
129+ test_version_increments_are_correct ()
130+
115131 update_version ()
116132 if "--ensure-tag" in sys .argv :
117133 ensure_tagged ()
0 commit comments