1
1
import re
2
+ from pathlib import Path
2
3
from typing import List
3
4
4
5
import nox
5
6
from nox .sessions import Session
6
7
7
8
8
- posargs_pattern = re .compile (r"^(\w+)\[(.+)\]$" )
9
+ HERE = Path (__file__ ).parent
10
+ POSARGS_PATTERN = re .compile (r"^(\w+)\[(.+)\]$" )
9
11
10
12
11
13
def get_posargs (name : str , session : Session ) -> List [str ]:
@@ -21,7 +23,7 @@ def get_posargs(name: str, session: Session) -> List[str]:
21
23
"""
22
24
collected_args : List [str ] = []
23
25
for arg in session .posargs :
24
- match = posargs_pattern .match (arg )
26
+ match = POSARGS_PATTERN .match (arg )
25
27
if match is not None :
26
28
found_name , found_args = match .groups ()
27
29
if name == found_name :
@@ -34,16 +36,22 @@ def get_posargs(name: str, session: Session) -> List[str]:
34
36
@nox .session (reuse_venv = True )
35
37
def example (session : Session ) -> None :
36
38
"""Run an example"""
39
+ if not session .posargs :
40
+ print ("No example name given. Choose from:" )
41
+ for found_example_file in (HERE / "docs" / "source" / "examples" ).glob ("*.py" ):
42
+ print ("-" , found_example_file .stem )
43
+ return None
44
+
37
45
session .install ("matplotlib" )
38
- session . install ( "-e" , ".[stable]" )
46
+ install_idom_dev ( session )
39
47
session .run ("python" , "scripts/one_example.py" , * session .posargs )
40
48
41
49
42
50
@nox .session (reuse_venv = True )
43
51
def docs (session : Session ) -> None :
44
52
"""Build and display documentation in the browser (automatically reloads on change)"""
45
53
session .install ("-r" , "requirements/build-docs.txt" )
46
- session . install ( "-e" , ".[ all] " )
54
+ install_idom_dev ( session , extras = " all" )
47
55
session .run (
48
56
"python" ,
49
57
"scripts/live_docs.py" ,
@@ -93,7 +101,7 @@ def test_python(session: Session) -> None:
93
101
if "--no-cov" in pytest_args :
94
102
session .install (".[all]" )
95
103
else :
96
- session . install ( "-e" , ".[ all] " )
104
+ install_idom_dev ( session , extras = " all" )
97
105
98
106
session .run ("pytest" , "tests" , * pytest_args )
99
107
@@ -127,6 +135,11 @@ def test_style(session: Session) -> None:
127
135
def test_docs (session : Session ) -> None :
128
136
"""Verify that the docs build and that doctests pass"""
129
137
session .install ("-r" , "requirements/build-docs.txt" )
130
- session . install ( "-e" , ".[ all] " )
138
+ install_idom_dev ( session , extras = " all" )
131
139
session .run ("sphinx-build" , "-b" , "html" , "docs/source" , "docs/build" )
132
140
session .run ("sphinx-build" , "-b" , "doctest" , "docs/source" , "docs/build" )
141
+
142
+
143
+ def install_idom_dev (session : Session , extras : str = "stable" ) -> None :
144
+ session .install ("-e" , f".[{ extras } ]" )
145
+ session .run ("idom" , "restore" )
0 commit comments