Skip to content

Commit 83e9246

Browse files
author
MomIsBestFriend
committed
Fixes for review
1 parent 10df407 commit 83e9246

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

ci/code_checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
102102

103103
MSG='Check for use of not concatenated strings' ; echo $MSG
104104
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
105-
$BASE_DIR/scripts/validate_string_concatenation.py --format="[error]{source_path}:{line_number}:String unnecessarily split in two by black. Please merge them manually." .
105+
$BASE_DIR/scripts/validate_string_concatenation.py --format="[error]{source_path}:{line_number}:{msg}" .
106106
else
107107
$BASE_DIR/scripts/validate_string_concatenation.py .
108108
fi

scripts/validate_string_concatenation.py

+27-12
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import sys
2727
import token
2828
import tokenize
29-
from typing import Dict, Generator, List
29+
from typing import Generator, List, Tuple
3030

3131
FILE_EXTENSIONS_TO_CHECK = (".py", ".pyx", ".pyx.ini", ".pxd")
3232

@@ -60,22 +60,40 @@ def main(source_path: str, output_format: str) -> bool:
6060
is_failed: bool = False
6161

6262
if os.path.isfile(source_path):
63-
for values in strings_to_concatenate(source_path):
63+
for source_path, line_number in strings_to_concatenate(source_path):
6464
is_failed = True
65-
print(output_format.format(**values))
65+
msg = (
66+
"String unnecessarily split in two by black. "
67+
"Please merge them manually."
68+
)
69+
print(
70+
output_format.format(
71+
source_path=source_path, line_number=line_number, msg=msg
72+
)
73+
)
6674

6775
for subdir, _, files in os.walk(source_path):
6876
for file_name in files:
6977
if any(
7078
file_name.endswith(extension) for extension in FILE_EXTENSIONS_TO_CHECK
7179
):
72-
for values in strings_to_concatenate(os.path.join(subdir, file_name)):
80+
for source_path, line_number in strings_to_concatenate(
81+
os.path.join(subdir, file_name)
82+
):
7383
is_failed = True
74-
print(output_format.format(**values))
84+
msg = (
85+
"String unnecessarily split in two by black. "
86+
"Please merge them manually."
87+
)
88+
print(
89+
output_format.format(
90+
source_path=source_path, line_number=line_number, msg=msg
91+
)
92+
)
7593
return is_failed
7694

7795

78-
def strings_to_concatenate(source_path: str) -> Generator[Dict[str, str], None, None]:
96+
def strings_to_concatenate(source_path: str) -> Generator[Tuple[str, int], None, None]:
7997
"""
8098
Yielding the strings that needs to be concatenated in a given file.
8199
@@ -86,7 +104,7 @@ def strings_to_concatenate(source_path: str) -> Generator[Dict[str, str], None,
86104
87105
Yields
88106
------
89-
dict of {str: str}
107+
Tuple
90108
Containing:
91109
source_path
92110
Source file path.
@@ -98,7 +116,7 @@ def strings_to_concatenate(source_path: str) -> Generator[Dict[str, str], None,
98116

99117
for current_token, next_token in zip(tokens, tokens[1:]):
100118
if current_token[0] == next_token[0] == token.STRING:
101-
yield {"source_path": source_path, "line_number": current_token[2][0]}
119+
yield (source_path, current_token[2][0])
102120

103121

104122
if __name__ == "__main__":
@@ -110,10 +128,7 @@ def strings_to_concatenate(source_path: str) -> Generator[Dict[str, str], None,
110128
parser.add_argument(
111129
"--format",
112130
"-f",
113-
default=(
114-
"{source_path}:{line_number}:String unnecessarily split in two by black. "
115-
"Please merge them manually."
116-
),
131+
default="{source_path}:{line_number}:{msg}",
117132
help="Output format of the unconcatenated strings.",
118133
)
119134

0 commit comments

Comments
 (0)