Skip to content
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
59 changes: 0 additions & 59 deletions .internal/pre_commit_tools/clean_timeouts.py

This file was deleted.

43 changes: 0 additions & 43 deletions .internal/pre_commit_tools/notebook_pre_commit_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
import yaml

PROJECT_ROOT = Path(subprocess.getoutput("git rev-parse --show-toplevel")) # noqa: S605
TIMEOUTS_FILE = PROJECT_ROOT / "tests" / "resources" / "timeouts.yaml"

DEFAULT_TIMEOUT_SECONDS: float = 20

ENFORCE_TIMEOUTS: bool = False


def main(full_file_paths: Iterable[str]) -> bool:
Expand All @@ -41,27 +36,6 @@ def is_valid_notebook(file_path: str, automatically_add_timeout: bool = True) ->
f" for example, you may change '{file_path}' to '{file_path.replace(' ', '_')}'."
)

if (
ENFORCE_TIMEOUTS
and not _is_file_in_timeouts(file_name)
and should_notebook_be_tested(file_path)
):
if automatically_add_timeout:
_add_file_to_timeouts(file_name)
errors.append(
"A new notebook was detected.\n"
f" Automatically adding a timeout entry {{{file_name} : {DEFAULT_TIMEOUT_SECONDS}}}.\n"
f" Please make sure to add the changes done to '{TIMEOUTS_FILE}'"
)
else:
errors.append(
"A new notebook was detected.\n"
" However, a coresponding entry in the timeouts file is missing.\n"
f" Please add an entry. You may add '{{{file_name} : {DEFAULT_TIMEOUT_SECONDS}}}'\n"
f" to {TIMEOUTS_FILE}\n"
" Alternatively, you may install pre-commit. It will automatically add a timeout entry in the next time you run 'git commit'."
)

if errors:
spacing = "\n\t" # f-string cannot include backslash
print(f"File `{file_path}` has error(s):{spacing}{spacing.join(errors)}")
Expand All @@ -81,23 +55,6 @@ def _does_contain_space_in_file_name(file_name: str) -> bool:
return " " in file_name


def _is_file_in_timeouts(file_name: str) -> bool:
with TIMEOUTS_FILE.open("r") as f:
timeouts = yaml.safe_load(f)

return file_name in timeouts


def _add_file_to_timeouts(file_name: str) -> None:
with TIMEOUTS_FILE.open("r") as f:
timeouts = yaml.safe_load(f)

timeouts[file_name] = DEFAULT_TIMEOUT_SECONDS

with TIMEOUTS_FILE.open("w") as f:
yaml.dump(timeouts, f, sort_keys=True)


def validate_unique_names() -> bool:
all_files = PROJECT_ROOT.rglob("*.ipynb")
base_names = [
Expand Down
43 changes: 0 additions & 43 deletions .internal/pre_commit_tools/qmod_pre_commit_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
import yaml

PROJECT_ROOT = Path(subprocess.getoutput("git rev-parse --show-toplevel")) # noqa: S605
TIMEOUTS_FILE = PROJECT_ROOT / "tests" / "resources" / "timeouts.yaml"

DEFAULT_TIMEOUT_SECONDS: float = 10

ENFORCE_TIMEOUTS: bool = False


def main(full_file_paths: Iterable[str]) -> bool:
Expand Down Expand Up @@ -45,27 +40,6 @@ def is_valid_qmod(
f" for example, you may change '{file_path}' to '{file_path.replace(' ', '_')}'."
)

if (
ENFORCE_TIMEOUTS
and not _is_file_in_timeouts(file_name)
and should_notebook_be_tested(file_path)
):
if automatically_add_timeout:
_add_file_to_timeouts(file_name)
errors.append(
"A new qmod was detected.\n"
f" Automatically adding a timeout entry {{{file_name} : {DEFAULT_TIMEOUT_SECONDS}}}.\n"
f" Please make sure to add the changes done to '{TIMEOUTS_FILE}'"
)
else:
errors.append(
"A new qmod was detected.\n"
" However, a coresponding entry in the timeouts file is missing.\n"
f" Please add an entry. You may add '{{{file_name} : {DEFAULT_TIMEOUT_SECONDS}}}'\n"
f" to {TIMEOUTS_FILE}\n"
" Alternatively, you may install pre-commit. It will automatically add a timeout entry in the next time you run 'git commit'."
)

spacing = "\n\t" # f-string cannot include backslash
errors_combined_message = (
f"File `{file_path}` has error(s):{spacing}{spacing.join(errors)}"
Expand All @@ -92,23 +66,6 @@ def _does_contain_space_in_file_name(file_name: str) -> bool:
return " " in file_name


def _is_file_in_timeouts(file_name: str) -> bool:
with TIMEOUTS_FILE.open("r") as f:
timeouts = yaml.safe_load(f)

return file_name in timeouts


def _add_file_to_timeouts(file_name: str) -> None:
with TIMEOUTS_FILE.open("r") as f:
timeouts = yaml.safe_load(f)

timeouts[file_name] = DEFAULT_TIMEOUT_SECONDS

with TIMEOUTS_FILE.open("w") as f:
yaml.dump(timeouts, f, sort_keys=True)


def validate_unique_names() -> bool:
all_files: Iterable[Path] = PROJECT_ROOT.rglob("*.qmod")
# exclude `functions/`
Expand Down
9 changes: 0 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ repos:
additional_dependencies:
- "pyyaml==6.0"
require_serial: true
# - id: clean-demo-timeouts
# name: Clean demo timeouts
# description: Remove unexisting entries and verify unique keys
# entry: .internal/pre_commit_tools/clean_timeouts.py
# language: python
# files: \.(qmod|ipynb|yaml)$
# additional_dependencies:
# - "pyyaml==6.0"
# require_serial: true
- id: validate-metadata-file
name: Validate Metadata file
description: Add file if non existant and validate value otherwise
Expand Down
Loading