Skip to content

Commit 9d2f50b

Browse files
committed
Follow conventions
1 parent b047316 commit 9d2f50b

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

.internal/pre_commit_tools/notebook_pre_commit_collection.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@
1313
PROJECT_ROOT = Path(subprocess.getoutput("git rev-parse --show-toplevel")) # noqa: S605
1414
TIMEOUTS_FILE = PROJECT_ROOT / "tests" / "resources" / "timeouts.yaml"
1515

16-
Seconds = float
17-
DEFAULT_TIMEOUT: Seconds = 20
16+
DEFAULT_TIMEOUT_SECONDS: float = 20
1817

19-
IS_FILE_VALID = bool
18+
IS_FILE_VALID = IS_FILE_INVALID = bool
2019

2120

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

2524

26-
def validate_notebook(file_path: str, automatically_add_timeout: bool = True) -> bool:
25+
def validate_notebook(
26+
file_path: str, automatically_add_timeout: bool = True
27+
) -> IS_FILE_VALID:
2728
file_name = os.path.basename(file_path)
28-
with open(file_path) as f:
29-
file_content = f.read()
3029

3130
errors = []
3231

33-
if not _forbid_dash_in_file_name(file_name):
32+
if _does_contain_dash_in_file_name(file_name):
3433
errors.append(
3534
"Dash (-) is not allowed in file named. please use underscore (_)"
3635
)
@@ -43,16 +42,14 @@ def validate_notebook(file_path: str, automatically_add_timeout: bool = True) ->
4342
errors.append("File is missing timeout in the timeouts.yaml file.")
4443

4544
if errors:
46-
print(f"file `{file_path}` has error:")
47-
for error in errors:
48-
print(f'\t"{error}"')
45+
spacing = "\n\t" # f-string cannot include backslash
46+
print(f"file `{file_path}` has error:{spacing}{spacing.join(errors)}")
4947

50-
is_ok = not errors
51-
return is_ok
48+
return not errors
5249

5350

54-
def _forbid_dash_in_file_name(file_name: str) -> IS_FILE_VALID:
55-
return not ("-" in file_name)
51+
def _does_contain_dash_in_file_name(file_name: str) -> IS_FILE_INVALID:
52+
return "-" in file_name
5653

5754

5855
def _is_file_in_timeouts(file_name: str) -> IS_FILE_VALID:
@@ -66,7 +63,7 @@ def _add_file_to_timeouts(file_name: str) -> None:
6663
with TIMEOUTS_FILE.open("r") as f:
6764
timeouts = yaml.safe_load(f)
6865

69-
timeouts[file_name] = DEFAULT_TIMEOUT
66+
timeouts[file_name] = DEFAULT_TIMEOUT_SECONDS
7067

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

.internal/pre_commit_tools/qmod_pre_commit_collection.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@
1313
PROJECT_ROOT = Path(subprocess.getoutput("git rev-parse --show-toplevel")) # noqa: S605
1414
TIMEOUTS_FILE = PROJECT_ROOT / "tests" / "resources" / "timeouts.yaml"
1515

16-
Seconds = float
17-
DEFAULT_TIMEOUT: Seconds = 10
16+
DEFAULT_TIMEOUT_SECONDS: float = 10
1817

19-
IS_FILE_VALID = bool
18+
IS_FILE_VALID = IS_FILE_INVALID = bool
2019

2120

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

2524

26-
def validate_qmod(file_path: str, automatically_add_timeout: bool = True) -> bool:
25+
def validate_qmod(
26+
file_path: str, automatically_add_timeout: bool = True
27+
) -> IS_FILE_VALID:
2728
file_name = os.path.basename(file_path)
28-
with open(file_path) as f:
29-
file_content = f.read()
3029

3130
errors = []
3231

33-
if not _forbid_dash_in_file_name(file_name):
32+
if _does_contain_dash_in_file_name(file_name):
3433
errors.append(
3534
"Dash (-) is not allowed in file named. please use underscore (_)"
3635
)
@@ -43,20 +42,14 @@ def validate_qmod(file_path: str, automatically_add_timeout: bool = True) -> boo
4342
errors.append("File is missing timeout in the timeouts.yaml file.")
4443

4544
if errors:
46-
print(f"file `{file_path}` has error:")
47-
for error in errors:
48-
print(f'\t"{error}"')
45+
spacing = "\n\t" # f-string cannot include backslash
46+
print(f"file `{file_path}` has error:{spacing}{spacing.join(errors)}")
4947

50-
is_ok = not errors
51-
return is_ok
52-
53-
54-
def _demand_internal_prefix(file_name: str) -> IS_FILE_VALID:
55-
return file_name.startswith("internal_")
48+
return not errors
5649

5750

58-
def _forbid_dash_in_file_name(file_name: str) -> IS_FILE_VALID:
59-
return not ("-" in file_name)
51+
def _does_contain_dash_in_file_name(file_name: str) -> IS_FILE_INVALID:
52+
return "-" in file_name
6053

6154

6255
def _is_file_in_timeouts(file_name: str) -> IS_FILE_VALID:
@@ -70,7 +63,7 @@ def _add_file_to_timeouts(file_name: str) -> None:
7063
with TIMEOUTS_FILE.open("r") as f:
7164
timeouts = yaml.safe_load(f)
7265

73-
timeouts[file_name] = DEFAULT_TIMEOUT
66+
timeouts[file_name] = DEFAULT_TIMEOUT_SECONDS
7467

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

0 commit comments

Comments
 (0)