Skip to content

Commit

Permalink
FEAT: implement --allowed-cell-metadata flag (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Aug 9, 2024
1 parent 1e0f886 commit 064446b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/compwa_policy/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def main(argv: Sequence[str] | None = None) -> int:
)
if has_notebooks:
do(jupyter.main, args.no_ruff)
do(nbstripout.main, precommit_config)
do(nbstripout.main, precommit_config, _to_list(args.allowed_cell_metadata))
do(toml.main, precommit_config) # has to run before pre-commit
do(prettier.main, precommit_config, args.no_prettierrc)
if is_python_repo:
Expand Down Expand Up @@ -123,6 +123,13 @@ def _create_argparse() -> ArgumentParser:
default=False,
help="Allow deprecated CI workflows, such as ci-docs.yml.",
)
parser.add_argument(
"--allowed-cell-metadata",
default="",
help="Comma-separated list of allowed metadata in Jupyter notebook cells, e.g. editable,slideshow.",
required=False,
type=str,
)
parser.add_argument(
"--ci-skipped-tests",
default="",
Expand Down Expand Up @@ -301,6 +308,8 @@ def _to_list(arg: str) -> list[str]:
>>> _to_list("a c , test,b")
['a', 'b', 'c', 'test']
>>> _to_list("d")
['d']
>>> _to_list(" ")
[]
>>> _to_list("")
Expand Down
3 changes: 2 additions & 1 deletion src/compwa_policy/check_dev_files/nbstripout.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from compwa_policy.utilities.precommit import ModifiablePrecommit


def main(precommit: ModifiablePrecommit) -> None:
def main(precommit: ModifiablePrecommit, allowed_cell_metadata: list[str]) -> None:
repo_url = "https://github.com/kynan/nbstripout"
repo = precommit.find_repo(repo_url)
if repo is None:
Expand All @@ -38,6 +38,7 @@ def main(precommit: ModifiablePrecommit) -> None:
"metadata.varInspector",
"metadata.vscode",
}
extra_keys_argument -= {f"cell.metadata.{key}" for key in allowed_cell_metadata}
existing_hooks = repo["hooks"]
if existing_hooks:
args = existing_hooks[0].get("args", [])
Expand Down

0 comments on commit 064446b

Please sign in to comment.