Skip to content

Commit c85c7b0

Browse files
committed
Follow conventions
1 parent 85c951b commit c85c7b0

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

.internal/pre_commit_tools/notebook_pre_commit_collection.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515

1616
DEFAULT_TIMEOUT_SECONDS: float = 20
1717

18-
IS_FILE_VALID = IS_FILE_INVALID = bool
19-
2018

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

2422

25-
def validate_notebook(
26-
file_path: str, automatically_add_timeout: bool = True
27-
) -> IS_FILE_VALID:
23+
def is_valid_notebook(file_path: str, automatically_add_timeout: bool = True) -> bool:
2824
file_name = os.path.basename(file_path)
2925

3026
errors = []
@@ -43,16 +39,16 @@ def validate_notebook(
4339

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

4844
return not errors
4945

5046

51-
def _does_contain_dash_in_file_name(file_name: str) -> IS_FILE_INVALID:
47+
def _does_contain_dash_in_file_name(file_name: str) -> bool:
5248
return "-" in file_name
5349

5450

55-
def _is_file_in_timeouts(file_name: str) -> IS_FILE_VALID:
51+
def _is_file_in_timeouts(file_name: str) -> bool:
5652
with TIMEOUTS_FILE.open("r") as f:
5753
timeouts = yaml.safe_load(f)
5854

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

7874
if duplicate_names:
79-
print(f"notebooks with duplicate names found: {duplicate_names}")
75+
print(f"Notebooks with duplicate names found: {duplicate_names}")
8076

8177
is_ok = not duplicate_names
8278
return is_ok

.internal/pre_commit_tools/qmod_pre_commit_collection.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515

1616
DEFAULT_TIMEOUT_SECONDS: float = 10
1717

18-
IS_FILE_VALID = IS_FILE_INVALID = bool
19-
2018

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

2422

25-
def validate_qmod(
26-
file_path: str, automatically_add_timeout: bool = True
27-
) -> IS_FILE_VALID:
23+
def is_valid_qmod(file_path: str, automatically_add_timeout: bool = True) -> bool:
2824
file_name = os.path.basename(file_path)
2925

3026
errors = []
@@ -43,16 +39,16 @@ def validate_qmod(
4339

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

4844
return not errors
4945

5046

51-
def _does_contain_dash_in_file_name(file_name: str) -> IS_FILE_INVALID:
47+
def _does_contain_dash_in_file_name(file_name: str) -> bool:
5248
return "-" in file_name
5349

5450

55-
def _is_file_in_timeouts(file_name: str) -> IS_FILE_VALID:
51+
def _is_file_in_timeouts(file_name: str) -> bool:
5652
with TIMEOUTS_FILE.open("r") as f:
5753
timeouts = yaml.safe_load(f)
5854

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

8076
if duplicate_names:
81-
print(f"qmods with duplicate names found: {duplicate_names}")
77+
print(f"Qmods with duplicate names found: {duplicate_names}")
8278

8379
is_ok = not duplicate_names
8480
return is_ok

tests/internal/test_pre_commit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_timeouts_missing_files():
2525
#
2626
@pytest.mark.parametrize("notebook_path", map(str, PROJECT_ROOT.rglob("*.ipynb")))
2727
def test_notebooks(notebook_path: str):
28-
assert notebook_pre_commit_collection.validate_notebook(
28+
assert notebook_pre_commit_collection.is_valid_notebook(
2929
notebook_path, automatically_add_timeout=False
3030
)
3131

@@ -44,7 +44,7 @@ def test_notebooks(qmod_path: str):
4444
if "functions/open_library_definitions" in qmod_path:
4545
return # skipped
4646

47-
assert qmod_pre_commit_collection.validate_qmod(
47+
assert qmod_pre_commit_collection.is_valid_qmod(
4848
qmod_path, automatically_add_timeout=False
4949
)
5050

0 commit comments

Comments
 (0)