2
2
3
3
import argparse
4
4
import os
5
+ import shutil
5
6
import subprocess
6
7
import sys
7
8
from pathlib import Path
@@ -24,8 +25,9 @@ def nightly():
24
25
return b"-nightly " in proc .stdout
25
26
26
27
27
- def example_manifests (manifest ):
28
- return [dir_ / manifest for dir_ in Path ("examples" ).iterdir ()]
28
+ def gen_examples (manifest ):
29
+ for dir_ in Path ("examples" ).iterdir ():
30
+ yield dir_ / manifest
29
31
30
32
31
33
def default (args ):
@@ -36,7 +38,7 @@ def default(args):
36
38
else :
37
39
run ("cargo" , "clippy" , "--all-features" , "--tests" )
38
40
39
- for manifest in example_manifests ("Cargo.toml" ):
41
+ for manifest in gen_examples ("Cargo.toml" ):
40
42
run ("cargo" , "clippy" , "--manifest-path" , manifest )
41
43
42
44
run ("cargo" , "test" , "--all-features" , "--lib" , "--tests" )
@@ -55,7 +57,7 @@ def check(args):
55
57
"warnings" ,
56
58
)
57
59
58
- for manifest in example_manifests ("Cargo.toml" ):
60
+ for manifest in gen_examples ("Cargo.toml" ):
59
61
run ("cargo" , "fmt" , "--manifest-path" , manifest , "--" , "--check" )
60
62
61
63
run ("cargo" , "clippy" , "--manifest-path" , manifest , "--" , "--deny" , "warnings" )
@@ -97,7 +99,7 @@ def examples(args):
97
99
sys .exit ("Examples require the Nox tool (https://nox.thea.codes)" )
98
100
99
101
if args .name is None :
100
- for manifest in example_manifests ("noxfile.py" ):
102
+ for manifest in gen_examples ("noxfile.py" ):
101
103
run ("nox" , "--noxfile" , manifest )
102
104
else :
103
105
run ("nox" , "--noxfile" , f"examples/{ args .name } /noxfile.py" )
@@ -111,12 +113,22 @@ def format_(args):
111
113
112
114
run ("cargo" , "fmt" )
113
115
114
- for manifest in example_manifests ("Cargo.toml" ):
116
+ for manifest in gen_examples ("Cargo.toml" ):
115
117
run ("cargo" , "fmt" , "--manifest-path" , manifest )
116
118
117
119
run ("black" , "." )
118
120
119
121
122
+ def prune (args ):
123
+ shutil .rmtree ("target" , ignore_errors = True )
124
+
125
+ for target_dir in gen_examples ("target" ):
126
+ shutil .rmtree (target_dir , ignore_errors = True )
127
+
128
+ for nox_dir in gen_examples (".nox" ):
129
+ shutil .rmtree (nox_dir , ignore_errors = True )
130
+
131
+
120
132
if __name__ == "__main__" :
121
133
parser = argparse .ArgumentParser ()
122
134
subparsers = parser .add_subparsers (
@@ -159,6 +171,11 @@ def format_(args):
159
171
)
160
172
format_parser .set_defaults (func = format_ )
161
173
174
+ prune_parser = subparsers .add_parser (
175
+ "prune" , aliases = ["p" ], help = "Remove target and venv directories"
176
+ )
177
+ prune_parser .set_defaults (func = prune )
178
+
162
179
args = parser .parse_args ()
163
180
os .chdir (Path (__file__ ).parent )
164
181
args .func (args )
0 commit comments