Skip to content

Commit

Permalink
ENH: check if notebooks and jupyter exist
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Oct 16, 2024
1 parent e22511a commit c11859e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/compwa_policy/check_dev_files/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from compwa_policy.utilities import CONFIG_PATH
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.match import git_ls_files
from compwa_policy.utilities.pyproject import Pyproject

if TYPE_CHECKING:
from pathlib import Path
Expand All @@ -22,12 +23,35 @@

def main(python_version: PythonVersion, apt_packages: list[str]) -> None:
with Executor() as do:
do(_check_optional_dependencies)
do(_update_apt_txt, apt_packages)
do(_update_post_build)
do(_make_executable, CONFIG_PATH.binder / "postBuild")
do(_update_runtime_txt, python_version)


def _check_optional_dependencies() -> None:
required_for_binder = "This is required for Binder."
if not CONFIG_PATH.pyproject.exists():
msg = f"{CONFIG_PATH.pyproject} does not exist. {required_for_binder}"
raise PrecommitError(msg)
pyproject = Pyproject.load()
table_key = "project.optional-dependencies"
if not pyproject.has_table(table_key):
msg = f"Missing [{table_key}] in {CONFIG_PATH.pyproject}. {required_for_binder}"
raise PrecommitError
optional_dependencies = pyproject.get_table(table_key)
optional_dependency_sections = set(optional_dependencies)
expected_sections = {"jupyter", "notebooks"}
missing_sections = expected_sections - optional_dependency_sections
if missing_sections:
msg = (
f"Missing sections in [{table_key}]: {', '.join(sorted(missing_sections))}"
f". {required_for_binder}"
)
raise PrecommitError(msg)


def _update_apt_txt(apt_packages: list[str]) -> None:
apt_txt = CONFIG_PATH.binder / "apt.txt"
if not apt_packages and apt_txt.exists():
Expand Down

0 comments on commit c11859e

Please sign in to comment.