22
33import argparse
44import os
5+ import shutil
56import subprocess
67import sys
78from pathlib import Path
@@ -24,13 +25,21 @@ def nightly():
2425 return b"-nightly " in proc .stdout
2526
2627
28+ def gen_examples (manifest ):
29+ for dir_ in Path ("examples" ).iterdir ():
30+ yield dir_ / manifest
31+
32+
2733def default (args ):
28- run ( "cargo" , "fmt" )
34+ format_ ( args )
2935
3036 if nightly ():
31- run ("cargo" , "clippy" , "--workspace" , "-- all-features" , "--tests" , "--benches" )
37+ run ("cargo" , "clippy" , "--all-features" , "--tests" , "--benches" )
3238 else :
33- run ("cargo" , "clippy" , "--workspace" , "--all-features" , "--tests" )
39+ run ("cargo" , "clippy" , "--all-features" , "--tests" )
40+
41+ for manifest in gen_examples ("Cargo.toml" ):
42+ run ("cargo" , "clippy" , "--manifest-path" , manifest )
3443
3544 run ("cargo" , "test" , "--all-features" , "--lib" , "--tests" )
3645
@@ -41,14 +50,18 @@ def check(args):
4150 run (
4251 "cargo" ,
4352 "clippy" ,
44- "--workspace" ,
4553 "--all-features" ,
4654 "--tests" ,
4755 "--" ,
4856 "--deny" ,
4957 "warnings" ,
5058 )
5159
60+ for manifest in gen_examples ("Cargo.toml" ):
61+ run ("cargo" , "fmt" , "--manifest-path" , manifest , "--" , "--check" )
62+
63+ run ("cargo" , "clippy" , "--manifest-path" , manifest , "--" , "--deny" , "warnings" )
64+
5265
5366def doc (args ):
5467 if args .name is None :
@@ -63,6 +76,8 @@ def doc(args):
6376
6477
6578def test (args ):
79+ run ("cargo" , "test" , "--all-features" , "--lib" )
80+
6681 if args .name is None :
6782 run ("cargo" , "test" , "--all-features" , "--tests" )
6883 else :
@@ -84,16 +99,10 @@ def examples(args):
8499 sys .exit ("Examples require the Nox tool (https://nox.thea.codes)" )
85100
86101 if args .name is None :
87- dirs = [
88- dir_ .name
89- for dir_ in Path ("examples" ).iterdir ()
90- if (dir_ / "noxfile.py" ).exists ()
91- ]
102+ for manifest in gen_examples ("noxfile.py" ):
103+ run ("nox" , "--noxfile" , manifest )
92104 else :
93- dirs = [args .name ]
94-
95- for dir in dirs :
96- run ("nox" , "--noxfile" , f"examples/{ dir } /noxfile.py" )
105+ run ("nox" , "--noxfile" , f"examples/{ args .name } /noxfile.py" )
97106
98107
99108def format_ (args ):
@@ -104,9 +113,22 @@ def format_(args):
104113
105114 run ("cargo" , "fmt" )
106115
116+ for manifest in gen_examples ("Cargo.toml" ):
117+ run ("cargo" , "fmt" , "--manifest-path" , manifest )
118+
107119 run ("black" , "." )
108120
109121
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+
110132if __name__ == "__main__" :
111133 parser = argparse .ArgumentParser ()
112134 subparsers = parser .add_subparsers (
@@ -149,6 +171,11 @@ def format_(args):
149171 )
150172 format_parser .set_defaults (func = format_ )
151173
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+
152179 args = parser .parse_args ()
153180 os .chdir (Path (__file__ ).parent )
154181 args .func (args )
0 commit comments