Skip to content

Commit

Permalink
Refactor anchovy.core.Context.process() (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
pydsigner committed Dec 21, 2023
1 parent e48a5db commit a7f3c87
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/anchovy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,11 @@ def find_inputs(self, path: Path):
else:
yield candidate

def process(self, input_paths: list[Path] | None = None):
def match_paths(self, input_paths: list[Path]):
"""
Process a set of files using the Context's defined rules. If
@input_paths is empty or None, `self.find_inputs()` will be used to get
a tree of files to process. If intermediate files are produced,
`self.process()` will be called recursively with them.
Match a set of input paths against the Context's defined Rules, and
associate them with the Steps of those Rules.
"""
input_paths = input_paths or list(self.find_inputs(self.settings['input_dir']))
# We want to handle tasks in the order they're defined!
tasks: dict[Step, list[tuple[Path, list[Path]]]]
tasks = {r.step: [] for r in self.rules if r.step}
Expand Down Expand Up @@ -153,6 +150,19 @@ def process(self, input_paths: list[Path] | None = None):
# surrounding for loop.
break

return tasks

def process(self, input_paths: list[Path] | None = None):
"""
Process a set of files using the Context's defined rules. If
@input_paths is empty or None, `self.find_inputs()` will be used to get
a tree of files to process. If intermediate files are produced,
`self.process()` will be called recursively with them.
"""
input_paths = input_paths or list(self.find_inputs(self.settings['input_dir']))

tasks = self.match_paths(input_paths)

flattened: list[tuple[Step, Path, list[Path]]] = []
for step, paths in tasks.items():
flattened.extend((step, p, ops) for p, ops in paths)
Expand Down

0 comments on commit a7f3c87

Please sign in to comment.