Skip to content

Commit 445f57d

Browse files
committed
Split main() into helper functions.
1 parent 609c4d0 commit 445f57d

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

ci/clean_notebooks.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ def clean_notebook(file: pathlib.Path, check_only=False) -> None:
7171
nbformat.write(nb, f)
7272
print(f"Cleaned {file}")
7373

74-
def main():
75-
"""Clean all notebooks in the repository, or check that they are clean."""
74+
75+
def parse_args():
76+
"""Parse command-line arguments."""
7677
# if the argument --check has been passed, check if the notebooks are clean
7778
# otherwise, clean them in-place
7879
parser = argparse.ArgumentParser()
@@ -85,13 +86,13 @@ def main():
8586
)
8687
parser.add_argument("--check", action="store_true")
8788
args = parser.parse_args()
88-
check_only = args.check
89-
# build list of files to scan from list of paths and files
89+
return parser, args
90+
91+
92+
def get_files(input_paths: List):
93+
"""build list of files to scan from list of paths and files"""
9094
files = []
91-
if len(args.files) == 0:
92-
parser.print_help()
93-
exit(1)
94-
for file in args.files:
95+
for file in input_paths:
9596
if file.is_dir():
9697
files.extend(file.glob("**/*.ipynb"))
9798
else:
@@ -102,6 +103,21 @@ def main():
102103
if not files:
103104
print("No notebooks found")
104105
sys.exit(1)
106+
return files
107+
108+
109+
def main():
110+
"""Clean all notebooks in the repository, or check that they are clean."""
111+
parser, args = parse_args()
112+
check_only = args.check
113+
input_paths = args.files
114+
115+
if len(input_paths) == 0:
116+
parser.print_help()
117+
sys.exit(1)
118+
119+
files = get_files(input_paths)
120+
105121
for file in files:
106122
try:
107123
clean_notebook(file, check_only=check_only)

0 commit comments

Comments
 (0)