1010from nox .sessions import Session
1111
1212
13- HERE = Path (__file__ ).parent
13+ ROOT = Path (__file__ ).parent
1414POSARGS_PATTERN = re .compile (r"^(\w+)\[(.+)\]$" )
1515
1616
@@ -39,7 +39,7 @@ def example(session: Session) -> None:
3939 """Run an example"""
4040 if not session .posargs :
4141 print ("No example name given. Choose from:" )
42- for found_example_file in (HERE / "docs" / "source" / "examples" ).glob ("*.py" ):
42+ for found_example_file in (ROOT / "docs" / "source" / "examples" ).glob ("*.py" ):
4343 print ("-" , found_example_file .stem )
4444 return None
4545
@@ -175,6 +175,51 @@ def test_docs(session: Session) -> None:
175175 session .run ("sphinx-build" , "-b" , "doctest" , "docs/source" , "docs/build" )
176176
177177
178+ @nox .session
179+ def tag (session : Session ):
180+ try :
181+ session .run (
182+ "git" ,
183+ "diff" ,
184+ "--cached" ,
185+ "--exit-code" ,
186+ silent = True ,
187+ external = True ,
188+ )
189+ except Exception :
190+ session .error ("Cannot create a tag - tROOT are uncommited changes" )
191+
192+ version = (ROOT / "VERSION" ).read_text ().strip ()
193+ install_requirements_file (session , "make-release" )
194+ session .run ("pysemver" , "check" , version )
195+
196+ changelog_file = ROOT / "docs" / "source" / "changelog.rst"
197+ for line in changelog_file .read_text ().splitlines ():
198+ if line == version :
199+ break
200+ else :
201+ session .error (f"No changelog entry for { version } in { changelog_file } " )
202+
203+ session .run ("git" , "tag" , version , external = True )
204+
205+ if "push" in session .posargs :
206+ session .run ("git" , "push" , "--tags" , external = True )
207+
208+
209+ @nox .session
210+ def update_version (session : Session ) -> None :
211+ if len (session .posargs ) > 1 :
212+ session .error ("To many arguments" )
213+
214+ try :
215+ version = session .posargs [0 ]
216+ except IndexError :
217+ session .error ("No version tag given" )
218+
219+ install_requirements_file (session , "make-release" )
220+ session .run ("python" , "scripts/update_versions.py" , version )
221+
222+
178223@nox .session (reuse_venv = True )
179224def latest_pull_requests (session : Session ) -> None :
180225 """A basic script for outputing changelog info"""
@@ -190,7 +235,7 @@ def latest_closed_issues(session: Session) -> None:
190235
191236
192237def install_requirements_file (session : Session , name : str ) -> None :
193- file_path = HERE / "requirements" / (name + ".txt" )
238+ file_path = ROOT / "requirements" / (name + ".txt" )
194239 assert file_path .exists (), f"requirements file { file_path } does not exist"
195240 session .install ("-r" , str (file_path ))
196241
0 commit comments