1919
2020
2121# set the default activated sessions, minimal for CI
22- nox .options .sessions = ["tests" , "flake8" , "docs" ] # , "docs", "gh_pages"
22+ nox .options .sessions = ["tests" , "flake8" , "docs" , "build" ] # , "docs", "gh_pages"
2323nox .options .error_on_missing_interpreters = True
2424nox .options .reuse_existing_virtualenvs = True # this can be done using -r
2525# if platform.system() == "Windows": >> always use this for better control
@@ -208,11 +208,9 @@ def publish(session):
208208 # session.run2('codecov -t %s -f %s' % (codecov_token, Folders.coverage_xml))
209209
210210
211- @nox .session (python = PY39 )
212- def release (session ):
213- """Create a release on github corresponding to the latest tag"""
214-
215- install_reqs (session , phase = "setup.py#dist" , phase_reqs = ["setuptools_scm" ])
211+ def _build (session ):
212+ """Common code used by build and release sessions"""
213+ install_reqs (session , setup = True , phase = "setup.py#dist" , phase_reqs = ["setuptools_scm" ])
216214
217215 # Get current tag using setuptools_scm and make sure this is not a dirty/dev one
218216 from setuptools_scm import get_version # (note that this import is not from the session env but the main nox env)
@@ -222,12 +220,40 @@ def release(session):
222220 def my_scheme (version_ ):
223221 version .append (version_ )
224222 return guess_next_dev_version (version_ )
223+
225224 current_tag = get_version ("." , version_scheme = my_scheme )
226225
227226 # create the package
228227 rm_folder (Folders .dist )
228+
229229 session .run ("python" , "setup.py" , "sdist" , "bdist_wheel" )
230230
231+ # Make sure that the generated _version.py file exists and is compliant with python 2.7
232+ version_py = Path (f"src/{ pkg_name } /_version.py" )
233+ if not version_py .exists ():
234+ raise ValueError ("Error with setuptools_scm: _version.py file not generated" )
235+
236+ if ":" in version_py .read_text ():
237+ raise ValueError ("Error with setuptools_scm: _version.py file contains annotations" )
238+
239+ return current_tag , version
240+
241+
242+ @nox .session (python = PY39 )
243+ def build (session ):
244+ """Same as release but just builds"""
245+
246+ current_tag , version = _build (session )
247+ print (f"current tag: { current_tag } " )
248+ print (f"version: { version } " )
249+
250+
251+ @nox .session (python = PY39 )
252+ def release (session ):
253+ """Create a release on github corresponding to the latest tag"""
254+
255+ current_tag , version = _build (session )
256+
231257 if version [0 ].dirty or not version [0 ].exact :
232258 raise ValueError ("You need to execute this action on a clean tag version with no local changes." )
233259
0 commit comments