Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: implement --allowed-cell-metadata flag #366

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading