Skip to content

Commit 992fcd2

Browse files
Merge pull request #70 from nasa/alexrad71/TEMPO-notebooks
Add TEMPO V04 vs Pandora comparison notebooks
2 parents cb6ba8c + 7b9dac9 commit 992fcd2

6 files changed

Lines changed: 16281 additions & 14 deletions

.git-hooks/check-notebook-headers.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ def main():
8888
# Create parser with common arguments
8989
parser = create_base_parser(description="Check notebook structure for required header content")
9090

91-
# Add script-specific arguments
92-
parser.add_argument(
93-
"files", nargs="*", help="Specific files to check (overrides --all-notebooks)"
94-
)
95-
9691
args = parser.parse_args()
9792

9893
# Get notebooks to check using common logic

.git-hooks/check-notebook-imports.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,14 @@ def main():
151151
unauthorized = check_notebook_imports(notebook, allowed_packages)
152152

153153
if unauthorized:
154+
label = "⚠️ " if args.warn_only else "❌"
154155
result.add_error(
155156
notebook,
156157
f"Unauthorized imports: {', '.join(sorted(unauthorized))}",
157158
{"unauthorized_packages": sorted(unauthorized)},
158159
)
159160
if not args.quiet:
160-
print(f" {notebook}")
161+
print(f"{label} {notebook}")
161162
print(f" Unauthorized: {', '.join(sorted(unauthorized))}")
162163
elif args.verbose:
163164
print(f"✅ {notebook}")
@@ -175,7 +176,7 @@ def main():
175176
# Print summary
176177
if not args.quiet:
177178
print()
178-
result.print_summary(verbose=args.verbose)
179+
result.print_summary(verbose=args.verbose, warn_only=args.warn_only)
179180

180181
if result.has_errors():
181182
print()
@@ -184,7 +185,7 @@ def main():
184185
print(" 2. Or remove the imports from notebooks")
185186
print(" 3. Or add to optional dependencies if specialized")
186187

187-
return result.exit_code()
188+
return result.exit_code(warn_only=args.warn_only)
188189

189190

190191
if __name__ == "__main__":

.git-hooks/notebook_utils.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,18 @@ def has_errors(self) -> bool:
134134
"""Return True if any errors were found."""
135135
return len(self.errors) > 0
136136

137-
def print_summary(self, verbose: bool = False):
137+
def print_summary(self, verbose: bool = False, warn_only: bool = False):
138138
"""Print a summary of the results."""
139139
print("=" * 70)
140140

141141
if self.errors:
142-
print(f"\n❌ Found {len(self.errors)} error(s) in {self.checked_count} file(s)")
142+
if warn_only:
143+
print(
144+
f"\n⚠️ Found {len(self.errors)} issue(s) in {self.checked_count}"
145+
f" file(s) (warn-only mode, not blocking)"
146+
)
147+
else:
148+
print(f"\n❌ Found {len(self.errors)} error(s) in {self.checked_count} file(s)")
143149
for error in self.errors:
144150
print(f"\n {error['file']}")
145151
print(f" {error['message']}")
@@ -155,8 +161,14 @@ def print_summary(self, verbose: bool = False):
155161
if not self.errors and not self.warnings:
156162
print(f"✅ All {self.checked_count} file(s) passed")
157163

158-
def exit_code(self) -> int:
159-
"""Return appropriate exit code (1 for errors, 0 for success)."""
164+
def exit_code(self, warn_only: bool = False) -> int:
165+
"""Return appropriate exit code.
166+
167+
Args:
168+
warn_only: If True, always return 0 (issues are advisory).
169+
"""
170+
if warn_only:
171+
return 0
160172
return 1 if self.has_errors() else 0
161173

162174

@@ -209,6 +221,22 @@ def create_base_parser(description: str) -> argparse.ArgumentParser:
209221
"--quiet", "-q", action="store_true", help="Suppress all output except errors"
210222
)
211223

224+
# Behavior arguments
225+
behavior_group = parser.add_argument_group("Behavior")
226+
behavior_group.add_argument(
227+
"--warn-only",
228+
action="store_true",
229+
help="Report issues as warnings instead of errors (always exits 0)",
230+
)
231+
232+
# Positional: filenames passed by pre-commit (or manually)
233+
parser.add_argument(
234+
"files",
235+
nargs="*",
236+
default=[],
237+
help="Notebook files to check (passed automatically by pre-commit)",
238+
)
239+
212240
return parser
213241

214242

@@ -221,7 +249,9 @@ def get_notebooks_from_args(args: argparse.Namespace) -> tuple[List[Path], str]:
221249
Returns:
222250
Tuple of (list of notebook paths, mode description string)
223251
"""
224-
# Check if 'files' argument exists and is populated
252+
# Priority: explicit files (from pre-commit or CLI) > --all-notebooks > staged files.
253+
# When pre-commit passes filenames, they arrive as positional args and take precedence
254+
# over --all-notebooks, which is intended for standalone manual runs.
225255
if hasattr(args, "files") and args.files:
226256
notebooks = [Path(f) for f in args.files if f.endswith(".ipynb")]
227257
mode = "specified"

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ repos:
6969
hooks:
7070
- id: check-notebook-imports
7171
name: Check notebook imports against pyproject.toml
72-
entry: python .git-hooks/check-notebook-imports.py
72+
entry: python .git-hooks/check-notebook-imports.py --warn-only
7373
language: system
7474
types: [jupyter]
75+
verbose: true # Always show output since the hook won't block commits
7576
exclude: "(^|/)(additional_drafts|_archive)/" # Exclude additional_drafts and _archive directories

0 commit comments

Comments
 (0)