1+ #!/usr/bin/env -S uv run --script
2+
3+ # /// script
4+ # dependencies = ["nox>=2025.2.9"]
5+ # ///
6+
17"""
28Nox runner for cookie & sp-repo-review.
39
713from __future__ import annotations
814
915import difflib
10- import email .message
16+ import email .parser
17+ import email .policy
1118import functools
1219import json
1320import os
2633import nox
2734
2835nox .needs_version = ">=2025.2.9"
29- nox .options .sessions = ["rr_lint" , "rr_tests" , "rr_pylint" , "readme" ]
3036nox .options .default_venv_backend = "uv|virtualenv"
3137
3238
@@ -58,7 +64,7 @@ def get_expected_version(backend: str, vcs: bool) -> str:
5864 return "0.2.3" if vcs and backend not in {"maturin" , "mesonpy" , "uv" } else "0.1.0"
5965
6066
61- def make_copier (session : nox .Session , backend : str , vcs : bool ) -> None :
67+ def make_copier (session : nox .Session , backend : str , vcs : bool ) -> Path :
6268 package_dir = Path (f"copy-{ backend } " )
6369 if package_dir .exists ():
6470 rmtree_ro (package_dir )
@@ -85,7 +91,7 @@ def make_copier(session: nox.Session, backend: str, vcs: bool) -> None:
8591 return package_dir
8692
8793
88- def make_cookie (session : nox .Session , backend : str , vcs : bool ) -> None :
94+ def make_cookie (session : nox .Session , backend : str , vcs : bool ) -> Path :
8995 package_dir = Path (f"cookie-{ backend } " )
9096 if package_dir .exists ():
9197 rmtree_ro (package_dir )
@@ -106,7 +112,7 @@ def make_cookie(session: nox.Session, backend: str, vcs: bool) -> None:
106112 return package_dir
107113
108114
109- def make_cruft (session : nox .Session , backend : str , vcs : bool ) -> None :
115+ def make_cruft (session : nox .Session , backend : str , vcs : bool ) -> Path :
110116 package_dir = Path (f"cruft-{ backend } " )
111117 if package_dir .exists ():
112118 rmtree_ro (package_dir )
@@ -156,7 +162,7 @@ def init_git(session: nox.Session, package_dir: Path) -> None:
156162IGNORE_FILES = {"__pycache__" , ".git" , ".copier-answers.yml" , ".cruft.json" }
157163
158164
159- def valid_path (path : Path ):
165+ def valid_path (path : Path ) -> bool :
160166 return path .is_file () and not IGNORE_FILES & set (path .parts )
161167
162168
@@ -233,7 +239,9 @@ def tests(session: nox.Session, backend: str, vcs: bool) -> None:
233239 "-c" ,
234240 f'import importlib.metadata as m; print(m.version("{ name } "))' ,
235241 silent = True ,
236- ).strip ()
242+ )
243+ assert version
244+ version = version .strip ()
237245 expected_version = get_expected_version (backend , vcs )
238246 assert version == expected_version , f"{ version = } != { expected_version = } "
239247
@@ -287,7 +295,9 @@ def dist(session: nox.Session, backend: str, vcs: bool) -> None:
287295 (metadata_path ,) = (
288296 n for n in names if n .endswith ("PKG-INFO" ) and "egg-info" not in n
289297 )
290- with tf .extractfile (metadata_path ) as mfile :
298+ efile = tf .extractfile (metadata_path )
299+ assert efile
300+ with efile as mfile :
291301 info = mfile .read ().decode ("utf-8" )
292302 if "License-Expression: BSD-3-Clause" not in info :
293303 msg = "License expression not found in METADATA"
@@ -302,7 +312,11 @@ def dist(session: nox.Session, backend: str, vcs: bool) -> None:
302312 metadata_path = next (iter (n for n in names if n .endswith ("METADATA" )))
303313 with zf .open (metadata_path ) as mfile :
304314 txt = mfile .read ()
305- license_fields = email .message .EmailMessage (txt ).get_all ("License" , [])
315+ license_fields = (
316+ email .parser .BytesParser (policy = email .policy .default )
317+ .parsebytes (txt )
318+ .get_all ("License" , [])
319+ )
306320 if license_fields :
307321 msg = f"Should not have anything in the License slot, got { license_fields } "
308322 session .error (msg )
@@ -403,14 +417,16 @@ def pc_bump(session: nox.Session) -> None:
403417
404418 for proj , (old_version , space ) in old_versions .items ():
405419 if proj not in versions :
406- versions [ proj ] = session .run (
420+ versions_proj = session .run (
407421 "lastversion" ,
408422 "--at=github" ,
409423 "--format=tag" ,
410424 "--exclude=~alpha|beta|rc" ,
411425 proj ,
412426 silent = True ,
413- ).strip ()
427+ )
428+ assert versions_proj
429+ versions [proj ] = versions_proj .strip ()
414430 new_version = versions [proj ]
415431
416432 after = PC_REPL_LINE .format (proj , new_version , space , '"' )
@@ -449,7 +465,7 @@ def get_latest_version_tag(repo: str, old_version: str) -> dict[str, Any] | None
449465 and x ["name" ].startswith ("v" ) == old_version .startswith ("v" )
450466 ]
451467 if tags :
452- return tags [0 ]
468+ return tags [0 ] # type: ignore[no-any-return]
453469 return None
454470
455471
@@ -548,3 +564,7 @@ def rr_build(session: nox.Session) -> None:
548564
549565 session .install ("build" )
550566 session .run ("python" , "-m" , "build" )
567+
568+
569+ if __name__ == "__main__" :
570+ nox .main ()
0 commit comments