Skip to content

Commit 5725566

Browse files
authored
Make functions in clean.py private. (#22)
1 parent 0523da0 commit 5725566

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

docs/changes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ all releases are available on `Anaconda.org <https://anaconda.org/pytask/pytask>
1212
- :gh:`16` reduces the traceback generated from tasks, failure section in report, fix
1313
error passing a file path to pytask, add demo to README.
1414
- :gh:`17` changes the interface to subcommands, adds ``"-c/--config"`` option to pass a
15-
path to a configuration file and adds ``pytask clean``, a command to clean your
16-
project.
15+
path to a configuration file and adds ``pytask clean`` (:gh:`22` as well), a command
16+
to clean your project.
1717
- :gh:`18` changes the documentation theme to alabaster.
1818
- :gh:`19` adds some changes related to ignored folders.
1919
- :gh:`20` fixes copying code examples in the documentation.

src/_pytask/clean.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from _pytask.shared import to_path
1717

1818

19-
HELP_TEXT_MODE = (
19+
_HELP_TEXT_MODE = (
2020
"Choose 'dry-run' to print the paths of files/directories which would be removed, "
2121
"'interactive' for a confirmation prompt for every path, and 'force' to remove all "
2222
"unknown paths at once. [default: dry-run]"
@@ -49,7 +49,7 @@ def pytask_parse_config(config, config_from_cli):
4949
"-m",
5050
"--mode",
5151
type=click.Choice(["dry-run", "interactive", "force"]),
52-
help=HELP_TEXT_MODE,
52+
help=_HELP_TEXT_MODE,
5353
)
5454
@click.option("-d", "--directories", is_flag=True, help="Remove whole directories.")
5555
@click.option(
@@ -83,9 +83,9 @@ def clean(**config_from_cli):
8383
session.hook.pytask_log_session_header(session=session)
8484
session.hook.pytask_collect(session=session)
8585

86-
known_paths = collect_all_paths_known_to_pytask(session)
86+
known_paths = _collect_all_paths_known_to_pytask(session)
8787
include_directories = session.config["directories"]
88-
unknown_paths = find_all_unknown_paths(
88+
unknown_paths = _find_all_unknown_paths(
8989
session, known_paths, include_directories
9090
)
9191

@@ -120,15 +120,15 @@ def clean(**config_from_cli):
120120
return session
121121

122122

123-
def collect_all_paths_known_to_pytask(session):
123+
def _collect_all_paths_known_to_pytask(session):
124124
"""Collect all paths from the session which are known to pytask.
125125
126126
Paths belong to tasks and nodes and configuration values.
127127
128128
"""
129129
known_files = set()
130130
for task in session.tasks:
131-
for path in yield_paths_from_task(task):
131+
for path in _yield_paths_from_task(task):
132132
known_files.add(path)
133133

134134
known_directories = set()
@@ -145,7 +145,7 @@ def collect_all_paths_known_to_pytask(session):
145145
return known_paths
146146

147147

148-
def yield_paths_from_task(task):
148+
def _yield_paths_from_task(task):
149149
"""Yield all paths attached to a task."""
150150
yield task.path
151151
for attribute in ["depends_on", "produces"]:
@@ -154,44 +154,44 @@ def yield_paths_from_task(task):
154154
yield node.value
155155

156156

157-
def find_all_unknown_paths(session, known_paths, include_directories):
157+
def _find_all_unknown_paths(session, known_paths, include_directories):
158158
"""Find all unknown paths.
159159
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
161161
paths and potentially take short-cuts if complete directories can be deleted.
162162
163163
"""
164164
recursive_nodes = [
165-
RecursivePathNode.from_path(path, known_paths)
165+
_RecursivePathNode.from_path(path, known_paths)
166166
for path in session.config["paths"]
167167
]
168168
unknown_paths = list(
169169
itertools.chain.from_iterable(
170170
[
171-
find_all_unkown_paths_per_recursive_node(node, include_directories)
171+
_find_all_unkown_paths_per_recursive_node(node, include_directories)
172172
for node in recursive_nodes
173173
]
174174
)
175175
)
176176
return unknown_paths
177177

178178

179-
def find_all_unkown_paths_per_recursive_node(node, include_directories):
179+
def _find_all_unkown_paths_per_recursive_node(node, include_directories):
180180
"""Return unknown paths per recursive file node.
181181
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
183183
directory and not the path of every single file in it.
184184
185185
"""
186186
if node.is_unknown and (node.is_file or (node.is_dir and include_directories)):
187187
yield node.path
188188
else:
189189
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)
191191

192192

193193
@attr.s(repr=False)
194-
class RecursivePathNode:
194+
class _RecursivePathNode:
195195
"""A class for a path to a file or directory which recursively instantiates itself.
196196
197197
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):
219219
220220
"""
221221
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()]
223223
if path.is_dir()
224224
else []
225225
)

0 commit comments

Comments
 (0)