3434def create_parser () -> argparse .ArgumentParser :
3535 """Create the argument parser."""
3636 parser = argparse .ArgumentParser (description = "make a release" )
37- parser .add_argument (
37+ mutex = parser .add_mutually_exclusive_group (required = True )
38+ mutex .add_argument (
39+ "--version" ,
40+ help = "set the version" ,
41+ )
42+ mutex .add_argument (
3843 "--bump" ,
39- required = True ,
4044 help = "update the version using the given semantics" ,
4145 )
4246 parser .add_argument (
@@ -57,20 +61,18 @@ def check_repository() -> None:
5761 raise SystemExit (1 ) from None
5862
5963
60- def bump_version (bump : str ) -> str :
61- """Bump the version and return the new version."""
64+ def update_version (version : str | None = None , bump : str | None = None ) -> str :
65+ """Update the version and return the new version."""
66+ args = ["uv" , "version" , "--no-sync" , "--output-format" , "json" ]
67+
68+ if version :
69+ args .append (version )
70+
71+ if bump :
72+ args .extend (("--bump" , bump ))
73+
6274 try :
63- version_json = subprocess .check_output (
64- (
65- "uv" ,
66- "version" ,
67- "--no-sync" ,
68- "--output-format" ,
69- "json" ,
70- "--bump" ,
71- bump ,
72- )
73- )
75+ version_json = subprocess .check_output (args )
7476
7577 except subprocess .CalledProcessError :
7678 print_error ("An error occurred while bumping the version." )
@@ -80,17 +82,16 @@ def bump_version(bump: str) -> str:
8082 return version ["version" ]
8183
8284
83- @contextmanager
84- def switch_to_branch (branch : str ) -> Generator [None ]:
85- """Create a new branch and switch to it.
86-
87- It is removed on exit.
88- """
89- base_branch = subprocess .check_output (
85+ def get_branch () -> str :
86+ """Get the current branch."""
87+ return subprocess .check_output (
9088 ("git" , "rev-parse" , "--abbrev-ref" , "HEAD" ),
9189 text = True ,
9290 ).rstrip ()
9391
92+
93+ def create_branch (branch : str ) -> None :
94+ """Create a new branch."""
9495 try :
9596 run (("git" , "branch" , branch ))
9697
@@ -100,6 +101,16 @@ def switch_to_branch(branch: str) -> Generator[None]:
100101
101102 print (f"Created new branch { branch !r} ." )
102103
104+
105+ @contextmanager
106+ def switch_to_branch (branch : str ) -> Generator [None ]:
107+ """Create a new branch and switch to it.
108+
109+ It is removed on exit.
110+ """
111+ base_branch = get_branch ()
112+ create_branch (branch )
113+
103114 try :
104115 run (("git" , "checkout" , branch ))
105116 print (f"Switched from branch { base_branch !r} to branch { branch !r} ." )
@@ -150,7 +161,7 @@ def main(argv: Sequence[str] | None = None) -> None:
150161
151162 check_repository ()
152163
153- version = bump_version ( args .bump )
164+ version = update_version ( args . version , args .bump )
154165
155166 release_branch = f"release/{ version } "
156167
@@ -182,4 +193,4 @@ def main(argv: Sequence[str] | None = None) -> None:
182193
183194
184195if __name__ == "__main__" :
185- raise SystemExit ( main () )
196+ main ()
0 commit comments