16
16
from _pytask .shared import to_path
17
17
18
18
19
- HELP_TEXT_MODE = (
19
+ _HELP_TEXT_MODE = (
20
20
"Choose 'dry-run' to print the paths of files/directories which would be removed, "
21
21
"'interactive' for a confirmation prompt for every path, and 'force' to remove all "
22
22
"unknown paths at once. [default: dry-run]"
@@ -49,7 +49,7 @@ def pytask_parse_config(config, config_from_cli):
49
49
"-m" ,
50
50
"--mode" ,
51
51
type = click .Choice (["dry-run" , "interactive" , "force" ]),
52
- help = HELP_TEXT_MODE ,
52
+ help = _HELP_TEXT_MODE ,
53
53
)
54
54
@click .option ("-d" , "--directories" , is_flag = True , help = "Remove whole directories." )
55
55
@click .option (
@@ -83,9 +83,9 @@ def clean(**config_from_cli):
83
83
session .hook .pytask_log_session_header (session = session )
84
84
session .hook .pytask_collect (session = session )
85
85
86
- known_paths = collect_all_paths_known_to_pytask (session )
86
+ known_paths = _collect_all_paths_known_to_pytask (session )
87
87
include_directories = session .config ["directories" ]
88
- unknown_paths = find_all_unknown_paths (
88
+ unknown_paths = _find_all_unknown_paths (
89
89
session , known_paths , include_directories
90
90
)
91
91
@@ -120,15 +120,15 @@ def clean(**config_from_cli):
120
120
return session
121
121
122
122
123
- def collect_all_paths_known_to_pytask (session ):
123
+ def _collect_all_paths_known_to_pytask (session ):
124
124
"""Collect all paths from the session which are known to pytask.
125
125
126
126
Paths belong to tasks and nodes and configuration values.
127
127
128
128
"""
129
129
known_files = set ()
130
130
for task in session .tasks :
131
- for path in yield_paths_from_task (task ):
131
+ for path in _yield_paths_from_task (task ):
132
132
known_files .add (path )
133
133
134
134
known_directories = set ()
@@ -145,7 +145,7 @@ def collect_all_paths_known_to_pytask(session):
145
145
return known_paths
146
146
147
147
148
- def yield_paths_from_task (task ):
148
+ def _yield_paths_from_task (task ):
149
149
"""Yield all paths attached to a task."""
150
150
yield task .path
151
151
for attribute in ["depends_on" , "produces" ]:
@@ -154,44 +154,44 @@ def yield_paths_from_task(task):
154
154
yield node .value
155
155
156
156
157
- def find_all_unknown_paths (session , known_paths , include_directories ):
157
+ def _find_all_unknown_paths (session , known_paths , include_directories ):
158
158
"""Find all unknown paths.
159
159
160
- First, create a tree of :class:`RecursivePathNode `. Then, create a list of unknown
160
+ First, create a tree of :class:`_RecursivePathNode `. Then, create a list of unknown
161
161
paths and potentially take short-cuts if complete directories can be deleted.
162
162
163
163
"""
164
164
recursive_nodes = [
165
- RecursivePathNode .from_path (path , known_paths )
165
+ _RecursivePathNode .from_path (path , known_paths )
166
166
for path in session .config ["paths" ]
167
167
]
168
168
unknown_paths = list (
169
169
itertools .chain .from_iterable (
170
170
[
171
- find_all_unkown_paths_per_recursive_node (node , include_directories )
171
+ _find_all_unkown_paths_per_recursive_node (node , include_directories )
172
172
for node in recursive_nodes
173
173
]
174
174
)
175
175
)
176
176
return unknown_paths
177
177
178
178
179
- def find_all_unkown_paths_per_recursive_node (node , include_directories ):
179
+ def _find_all_unkown_paths_per_recursive_node (node , include_directories ):
180
180
"""Return unknown paths per recursive file node.
181
181
182
- If ``" --directories" `` is given, take a short-cut and return only the path of the
182
+ If ``--directories`` is given, take a short-cut and return only the path of the
183
183
directory and not the path of every single file in it.
184
184
185
185
"""
186
186
if node .is_unknown and (node .is_file or (node .is_dir and include_directories )):
187
187
yield node .path
188
188
else :
189
189
for n in node .sub_nodes :
190
- yield from find_all_unkown_paths_per_recursive_node (n , include_directories )
190
+ yield from _find_all_unkown_paths_per_recursive_node (n , include_directories )
191
191
192
192
193
193
@attr .s (repr = False )
194
- class RecursivePathNode :
194
+ class _RecursivePathNode :
195
195
"""A class for a path to a file or directory which recursively instantiates itself.
196
196
197
197
The problem is that we want to take a short-cut for unknown directories with only
@@ -219,7 +219,7 @@ def from_path(cls, path: Path, known_paths: list):
219
219
220
220
"""
221
221
sub_nodes = (
222
- [RecursivePathNode .from_path (p , known_paths ) for p in path .glob ( "*" )]
222
+ [_RecursivePathNode .from_path (p , known_paths ) for p in path .iterdir ( )]
223
223
if path .is_dir ()
224
224
else []
225
225
)
0 commit comments