11"""Nox sessions."""
22import tempfile
3+ from typing import Any
34
45import nox
6+ from nox .sessions import Session
7+
58
69nox .options .sessions = "lint" , "safety" , "mypy" , "tests"
710locations = "src" , "tests" , "noxfile.py"
811
912
10- def install_with_constraints (session , * args , ** kwargs ):
13+ def install_with_constraints (session : Session , * args : str , ** kwargs : Any ) -> None :
14+ """Install packages constrained by Poetry's lock file.
15+ This function is a wrapper for nox.sessions.Session.install. It
16+ invokes pip to install packages inside of the session's virtualenv.
17+ Additionally, pip is passed a constraints file generated from
18+ Poetry's lock file, to ensure that the packages are pinned to the
19+ versions specified in poetry.lock. This allows you to manage the
20+ packages as Poetry development dependencies.
21+ Arguments:
22+ session: The Session object.
23+ args: Command-line arguments for pip.
24+ kwargs: Additional keyword arguments for Session.install.
25+ """
1126 with tempfile .NamedTemporaryFile () as requirements :
1227 session .run (
1328 "poetry" ,
@@ -21,14 +36,16 @@ def install_with_constraints(session, *args, **kwargs):
2136
2237
2338@nox .session (python = "3.8" )
24- def black (session ):
39+ def black (session : Session ) -> None :
40+ """Run black code formatter."""
2541 args = session .posargs or locations
2642 install_with_constraints (session , "black" )
2743 session .run ("black" , * args )
2844
2945
3046@nox .session (python = ["3.8" , "3.7" ])
31- def lint (session ):
47+ def lint (session : Session ) -> None :
48+ """Lint using flake8."""
3249 args = session .posargs or locations
3350 install_with_constraints (
3451 session ,
@@ -42,7 +59,8 @@ def lint(session):
4259
4360
4461@nox .session (python = "3.8" )
45- def safety (session ):
62+ def safety (session : Session ) -> None :
63+ """Scan dependencies for insecure packages."""
4664 with tempfile .NamedTemporaryFile () as requirements :
4765 session .run (
4866 "poetry" ,
@@ -66,7 +84,8 @@ def mypy(session: Session) -> None:
6684
6785
6886@nox .session (python = ["3.8" , "3.7" ])
69- def tests (session ):
87+ def tests (session : Session ) -> None :
88+ """Run the test suite."""
7089 args = session .posargs or ["--cov" , "-m" , "not e2e" ]
7190 session .run ("poetry" , "install" , "--no-dev" , external = True )
7291 install_with_constraints (session , "coverage[toml]" , "pytest" , "pytest-cov" )
0 commit comments