44import shlex
55import shutil
66import sys
7+ import tempfile
78from pathlib import Path
89from textwrap import dedent
910
2526package = "vaskify"
2627python_versions = ["3.11" , "3.12" , "3.13" ]
2728python_versions_for_test = python_versions + ["3.10" ]
28- nox .needs_version = ">= 2021.6.6 "
29+ nox .needs_version = ">= 2025.2.9 "
2930nox .options .sessions = (
3031 "pre-commit" ,
3132 "mypy" ,
3637)
3738
3839
40+ def install_poetry_groups (session : Session , * groups : str ) -> None :
41+ """Install dependencies from poetry groups, pinned to poetry.lock
42+
43+ Using this as a workaround until this PR is merged in:
44+ https://github.com/cjolowicz/nox-poetry/pull/1080
45+ """
46+ with tempfile .TemporaryDirectory () as tempdir :
47+ requirements_path = os .path .join (tempdir , "requirements.txt" )
48+ session .run (
49+ "poetry" ,
50+ "export" ,
51+ * [f"--only={ group } " for group in groups ],
52+ "--format=requirements.txt" ,
53+ "--without-hashes" ,
54+ f"--output={ requirements_path } " ,
55+ external = True ,
56+ )
57+ session .install ("-r" , requirements_path )
58+
59+
3960def activate_virtualenv_in_precommit_hooks (session : Session ) -> None :
4061 """Activate virtualenv in hooks installed by pre-commit.
4162
@@ -128,13 +149,7 @@ def precommit(session: Session) -> None:
128149 "--hook-stage=manual" ,
129150 "--show-diff-on-failure" ,
130151 ]
131- session .install (
132- "pre-commit" ,
133- "pre-commit-hooks" ,
134- "darglint" ,
135- "ruff" ,
136- "black" ,
137- )
152+ install_poetry_groups (session , "lint" )
138153 session .run ("pre-commit" , * args )
139154 if args and args [0 ] == "install" :
140155 activate_virtualenv_in_precommit_hooks (session )
@@ -145,7 +160,7 @@ def mypy(session: Session) -> None:
145160 """Type-check using mypy."""
146161 args = session .posargs or ["src" , "tests" ]
147162 session .install ("." )
148- session . install ( "mypy" , "pytest " )
163+ install_poetry_groups ( session , "dev " )
149164 session .run ("mypy" , * args )
150165 if not session .posargs :
151166 session .run ("mypy" , f"--python-executable={ sys .executable } " , "noxfile.py" )
@@ -155,7 +170,7 @@ def mypy(session: Session) -> None:
155170def tests (session : Session ) -> None :
156171 """Run the test suite."""
157172 session .install ("." )
158- session . install ( "coverage[toml]" , "pytest" , "pygments " )
173+ install_poetry_groups ( session , "dev " )
159174 try :
160175 session .run (
161176 "coverage" ,
@@ -176,9 +191,7 @@ def tests(session: Session) -> None:
176191def coverage (session : Session ) -> None :
177192 """Produce the coverage report."""
178193 args = session .posargs or ["report" , "--skip-empty" ]
179-
180- session .install ("coverage[toml]" )
181-
194+ install_poetry_groups (session , "dev" )
182195 if not session .posargs and any (Path ().glob (".coverage.*" )):
183196 session .run ("coverage" , "combine" )
184197
@@ -189,7 +202,7 @@ def coverage(session: Session) -> None:
189202def typeguard (session : Session ) -> None :
190203 """Runtime type checking using Typeguard."""
191204 session .install ("." )
192- session . install ( "pytest" , "typeguard" , "pygments " )
205+ install_poetry_groups ( session , "dev " )
193206 session .run ("pytest" , f"--typeguard-packages={ package } " , * session .posargs )
194207
195208
@@ -204,7 +217,7 @@ def xdoctest(session: Session) -> None:
204217 args .append ("--colored=1" )
205218
206219 session .install ("." )
207- session . install ( "xdoctest[colors] " )
220+ install_poetry_groups ( session , "dev " )
208221 session .run ("python" , "-m" , "xdoctest" , * args )
209222
210223
@@ -216,9 +229,7 @@ def docs_build(session: Session) -> None:
216229 args .insert (0 , "--color" )
217230
218231 session .install ("." )
219- session .install (
220- "sphinx" , "sphinx-autodoc-typehints" , "sphinx-click" , "furo" , "myst-parser"
221- )
232+ install_poetry_groups (session , "doc" )
222233
223234 build_dir = Path ("docs" , "_build" )
224235 if build_dir .exists ():
@@ -232,14 +243,7 @@ def docs(session: Session) -> None:
232243 """Build and serve the documentation with live reloading on file changes."""
233244 args = session .posargs or ["--open-browser" , "docs" , "docs/_build" ]
234245 session .install ("." )
235- session .install (
236- "sphinx" ,
237- "sphinx-autobuild" ,
238- "sphinx-autodoc-typehints" ,
239- "sphinx-click" ,
240- "furo" ,
241- "myst-parser" ,
242- )
246+ install_poetry_groups (session , "doc" )
243247
244248 build_dir = Path ("docs" , "_build" )
245249 if build_dir .exists ():
0 commit comments