2
2
import shutil
3
3
import sys
4
4
from pathlib import Path
5
- from textwrap import dedent
6
5
7
6
import nox
8
-
9
- try :
10
- from nox_poetry import Session
11
- from nox_poetry import session
12
- except ImportError :
13
- message = f"""\
14
- Nox failed to import the 'nox-poetry' package.
15
-
16
- Please install it using the following command:
17
-
18
- { sys .executable } -m pip install nox-poetry"""
19
- raise SystemExit (dedent (message )) from None
7
+ from nox import Session
8
+ from nox import session
20
9
21
10
22
11
package = "protosym"
23
12
python_versions = ["3.9" , "3.8" ]
24
13
nox .needs_version = ">= 2021.6.6"
25
14
nox .options .sessions = (
26
15
"pre-commit" ,
27
- "safety" ,
28
16
"mypy" ,
29
17
"tests" ,
30
- # "typeguard", disabled because it conflicts with if TYPE_CHECKING
31
- "xdoctest" ,
18
+ "doctest" ,
32
19
"docs-build" ,
33
20
)
34
21
35
22
36
- def activate_virtualenv_in_precommit_hooks (session : Session ) -> None :
37
- """Activate virtualenv in hooks installed by pre-commit.
38
-
39
- This function patches git hooks installed by pre-commit to activate the
40
- session's virtual environment. This allows pre-commit to locate hooks in
41
- that environment when invoked from git.
42
-
43
- Args:
44
- session: The Session object.
45
- """
46
- if session .bin is None :
47
- return
48
-
49
- virtualenv = session .env .get ("VIRTUAL_ENV" )
50
- if virtualenv is None :
51
- return
52
-
53
- hookdir = Path (".git" ) / "hooks"
54
- if not hookdir .is_dir ():
55
- return
56
-
57
- for hook in hookdir .iterdir ():
58
- if hook .name .endswith (".sample" ) or not hook .is_file ():
59
- continue
60
-
61
- text = hook .read_text ()
62
- bindir = repr (session .bin )[1 :- 1 ] # strip quotes
63
- if not (
64
- Path ("A" ) == Path ("a" ) and bindir .lower () in text .lower () or bindir in text
65
- ):
66
- continue
67
-
68
- lines = text .splitlines ()
69
- if not (lines [0 ].startswith ("#!" ) and "python" in lines [0 ].lower ()):
70
- continue
71
-
72
- header = dedent (
73
- f"""\
74
- import os
75
- os.environ["VIRTUAL_ENV"] = { virtualenv !r}
76
- os.environ["PATH"] = os.pathsep.join((
77
- { session .bin !r} ,
78
- os.environ.get("PATH", ""),
79
- ))
80
- """
81
- )
82
-
83
- lines .insert (1 , header )
84
- hook .write_text ("\n " .join (lines ))
85
-
86
-
87
23
@session (name = "pre-commit" , python = "3.9" )
88
24
def precommit (session : Session ) -> None :
89
25
"""Lint using pre-commit."""
90
26
args = session .posargs or ["run" , "--all-files" , "--show-diff-on-failure" ]
91
- session .install (
92
- "black" ,
93
- "darglint" ,
94
- "flake8" ,
95
- "flake8-bandit" ,
96
- "flake8-bugbear" ,
97
- "flake8-docstrings" ,
98
- "flake8-rst-docstrings" ,
99
- "flake8-type-checking" ,
100
- "pep8-naming" ,
101
- "pre-commit" ,
102
- "pre-commit-hooks" ,
103
- "reorder-python-imports" ,
104
- )
27
+ session .install ("-r" , "requirements-lint.txt" )
105
28
session .run ("pre-commit" , * args )
106
- if args and args [0 ] == "install" :
107
- activate_virtualenv_in_precommit_hooks (session )
108
-
109
-
110
- @session (python = "3.9" )
111
- def safety (session : Session ) -> None :
112
- """Scan dependencies for insecure packages."""
113
- requirements = session .poetry .export_requirements ()
114
- session .install ("safety" )
115
- session .run (
116
- "safety" ,
117
- "check" ,
118
- # "--full-report",
119
- # Using --output bare below because otherwise safety is too verbose.
120
- # Unfortunately it means that any failure message is not shown so
121
- # comment these lines oput if safety fails.
122
- "--output" ,
123
- "bare" ,
124
- f"--file={ requirements } " ,
125
- "--ignore=51457" , # https://github.com/pytest-dev/py/issues/287
126
- "--ignore=58755" , # https://github.com/mpmath/mpmath/issues/548
127
- )
128
29
129
30
130
31
@session (python = "3.9" )
@@ -141,8 +42,7 @@ def mypy(session: Session) -> None:
141
42
@session (python = python_versions )
142
43
def tests (session : Session ) -> None :
143
44
"""Run the test suite."""
144
- session .install ("." , "sympy" , "llvmlite" , "numpy" )
145
- session .install ("coverage[toml]" , "pytest" , "pygments" )
45
+ session .install ("." , "-r" , "requirements-test.txt" )
146
46
try :
147
47
session .run ("coverage" , "run" , "--parallel" , "-m" , "pytest" , * session .posargs )
148
48
finally :
@@ -163,33 +63,19 @@ def coverage(session: Session) -> None:
163
63
session .run ("coverage" , * args )
164
64
165
65
166
- # It seems that with typeguard it is not possible to use if TYPE_CHECKING
167
- # blocks and all types in annotations need to be resolvable at runtime. For now
168
- # we disable this runtime type checking feature.
169
- #
170
- # @session(python=python_versions)
171
- # def typeguard(session: Session) -> None:
172
- # """Runtime type checking using Typeguard."""
173
- # session.install(".")
174
- # session.install("pytest", "typeguard", "pygments")
175
- # session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
176
-
177
-
178
66
@session (python = python_versions )
179
- def xdoctest (session : Session ) -> None :
67
+ def doctest (session : Session ) -> None :
180
68
"""Run examples with xdoctest."""
181
69
args = session .posargs or ["all" ]
182
- session .install ("." , "sympy" , "llvmlite" , "numpy" )
183
- session .install ("xdoctest[colors]" )
70
+ session .install ("." , "-r" , "requirements-test.txt" )
184
71
session .run ("python" , "-m" , "xdoctest" , "--quiet" , package , * args )
185
72
186
73
187
74
@session (name = "docs-build" , python = "3.9" )
188
75
def docs_build (session : Session ) -> None :
189
76
"""Build the documentation."""
190
77
args = session .posargs or ["-W" , "docs" , "docs/_build" ]
191
- session .install ("." )
192
- session .install ("sphinx" , "sphinx-rtd-theme" )
78
+ session .install ("." , "-r" , "requirements-docs.txt" )
193
79
194
80
build_dir = Path ("docs" , "_build" )
195
81
if build_dir .exists ():
@@ -202,8 +88,7 @@ def docs_build(session: Session) -> None:
202
88
def docs (session : Session ) -> None :
203
89
"""Build and serve the documentation with live reloading on file changes."""
204
90
args = session .posargs or ["--open-browser" , "docs" , "docs/_build" , "--watch=src" ]
205
- session .install ("." )
206
- session .install ("sphinx" , "sphinx-autobuild" , "sphinx-rtd-theme" )
91
+ session .install ("." , "-r" , "requirements-docs.txt" )
207
92
208
93
build_dir = Path ("docs" , "_build" )
209
94
if build_dir .exists ():
0 commit comments