Skip to content

Commit

Permalink
Follow conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
classiqdor committed Mar 6, 2025
1 parent 9d2f50b commit 5fe71db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
16 changes: 6 additions & 10 deletions .internal/pre_commit_tools/notebook_pre_commit_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@

DEFAULT_TIMEOUT_SECONDS: float = 20

IS_FILE_VALID = IS_FILE_INVALID = bool


def main(full_file_paths: Iterable[str]) -> bool:
return validate_unique_names() and all(map(validate_notebook, full_file_paths))
return validate_unique_names() and all(map(is_valid_notebook, full_file_paths))


def validate_notebook(
file_path: str, automatically_add_timeout: bool = True
) -> IS_FILE_VALID:
def is_valid_notebook(file_path: str, automatically_add_timeout: bool = True) -> bool:
file_name = os.path.basename(file_path)

errors = []
Expand All @@ -43,16 +39,16 @@ def validate_notebook(

if errors:
spacing = "\n\t" # f-string cannot include backslash
print(f"file `{file_path}` has error:{spacing}{spacing.join(errors)}")
print(f"File `{file_path}` has error(s):{spacing}{spacing.join(errors)}")

return not errors


def _does_contain_dash_in_file_name(file_name: str) -> IS_FILE_INVALID:
def _does_contain_dash_in_file_name(file_name: str) -> bool:
return "-" in file_name


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

Expand All @@ -76,7 +72,7 @@ def validate_unique_names() -> bool:
duplicate_names = [name for name, count in Counter(base_names).items() if count > 1]

if duplicate_names:
print(f"notebooks with duplicate names found: {duplicate_names}")
print(f"Notebooks with duplicate names found: {duplicate_names}")

is_ok = not duplicate_names
return is_ok
Expand Down
16 changes: 6 additions & 10 deletions .internal/pre_commit_tools/qmod_pre_commit_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@

DEFAULT_TIMEOUT_SECONDS: float = 10

IS_FILE_VALID = IS_FILE_INVALID = bool


def main(full_file_paths: Iterable[str]) -> bool:
return validate_unique_names() and all(map(validate_qmod, full_file_paths))
return validate_unique_names() and all(map(is_valid_qmod, full_file_paths))


def validate_qmod(
file_path: str, automatically_add_timeout: bool = True
) -> IS_FILE_VALID:
def is_valid_qmod(file_path: str, automatically_add_timeout: bool = True) -> bool:
file_name = os.path.basename(file_path)

errors = []
Expand All @@ -43,16 +39,16 @@ def validate_qmod(

if errors:
spacing = "\n\t" # f-string cannot include backslash
print(f"file `{file_path}` has error:{spacing}{spacing.join(errors)}")
print(f"File `{file_path}` has error(s):{spacing}{spacing.join(errors)}")

return not errors


def _does_contain_dash_in_file_name(file_name: str) -> IS_FILE_INVALID:
def _does_contain_dash_in_file_name(file_name: str) -> bool:
return "-" in file_name


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

Expand All @@ -78,7 +74,7 @@ def validate_unique_names() -> bool:
duplicate_names = [name for name, count in Counter(base_names).items() if count > 1]

if duplicate_names:
print(f"qmods with duplicate names found: {duplicate_names}")
print(f"Qmods with duplicate names found: {duplicate_names}")

is_ok = not duplicate_names
return is_ok
Expand Down

0 comments on commit 5fe71db

Please sign in to comment.