refactor(treewide): formatting and ruff fixes, + manually enabled F401
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
diff --git a/.github/helper/documentation.py b/.github/helper/documentation.py
index 8334604..b4f9c39 100644
--- a/.github/helper/documentation.py
+++ b/.github/helper/documentation.py
@@ -1,7 +1,7 @@
import sys
-import requests
from urllib.parse import urlparse
+import requests
WEBSITE_REPOS = [
"erpnext_com",
@@ -36,11 +36,7 @@
def contains_documentation_link(body: str) -> bool:
- return any(
- is_documentation_link(word)
- for line in body.splitlines()
- for word in line.split()
- )
+ return any(is_documentation_link(word) for line in body.splitlines() for word in line.split())
def check_pull_request(number: str) -> "tuple[int, str]":
@@ -53,12 +49,7 @@
head_sha = (payload.get("head") or {}).get("sha")
body = (payload.get("body") or "").lower()
- if (
- not title.startswith("feat")
- or not head_sha
- or "no-docs" in body
- or "backport" in body
- ):
+ if not title.startswith("feat") or not head_sha or "no-docs" in body or "backport" in body:
return 0, "Skipping documentation checks... 🏃"
if contains_documentation_link(body):
diff --git a/.github/helper/translation.py b/.github/helper/translation.py
index 9146b3b..2918f78 100644
--- a/.github/helper/translation.py
+++ b/.github/helper/translation.py
@@ -2,7 +2,9 @@
import sys
errors_encounter = 0
-pattern = re.compile(r"_\(([\"']{,3})(?P<message>((?!\1).)*)\1(\s*,\s*context\s*=\s*([\"'])(?P<py_context>((?!\5).)*)\5)*(\s*,(\s*?.*?\n*?)*(,\s*([\"'])(?P<js_context>((?!\11).)*)\11)*)*\)")
+pattern = re.compile(
+ r"_\(([\"']{,3})(?P<message>((?!\1).)*)\1(\s*,\s*context\s*=\s*([\"'])(?P<py_context>((?!\5).)*)\5)*(\s*,(\s*?.*?\n*?)*(,\s*([\"'])(?P<js_context>((?!\11).)*)\11)*)*\)"
+)
words_pattern = re.compile(r"_{1,2}\([\"'`]{1,3}.*?[a-zA-Z]")
start_pattern = re.compile(r"_{1,2}\([f\"'`]{1,3}")
f_string_pattern = re.compile(r"_\(f[\"']")
@@ -10,14 +12,14 @@
# skip first argument
files = sys.argv[1:]
-files_to_scan = [_file for _file in files if _file.endswith(('.py', '.js'))]
+files_to_scan = [_file for _file in files if _file.endswith((".py", ".js"))]
for _file in files_to_scan:
- with open(_file, 'r') as f:
- print(f'Checking: {_file}')
+ with open(_file) as f:
+ print(f"Checking: {_file}")
file_lines = f.readlines()
for line_number, line in enumerate(file_lines, 1):
- if 'frappe-lint: disable-translate' in line:
+ if "frappe-lint: disable-translate" in line:
continue
start_matches = start_pattern.search(line)
@@ -28,7 +30,9 @@
has_f_string = f_string_pattern.search(line)
if has_f_string:
errors_encounter += 1
- print(f'\nF-strings are not supported for translations at line number {line_number}\n{line.strip()[:100]}')
+ print(
+ f"\nF-strings are not supported for translations at line number {line_number}\n{line.strip()[:100]}"
+ )
continue
else:
continue
@@ -36,25 +40,29 @@
match = pattern.search(line)
error_found = False
- if not match and line.endswith((',\n', '[\n')):
+ if not match and line.endswith((",\n", "[\n")):
# concat remaining text to validate multiline pattern
- line = "".join(file_lines[line_number - 1:])
- line = line[start_matches.start() + 1:]
+ line = "".join(file_lines[line_number - 1 :])
+ line = line[start_matches.start() + 1 :]
match = pattern.match(line)
if not match:
error_found = True
- print(f'\nTranslation syntax error at line number {line_number}\n{line.strip()[:100]}')
+ print(f"\nTranslation syntax error at line number {line_number}\n{line.strip()[:100]}")
if not error_found and not words_pattern.search(line):
error_found = True
- print(f'\nTranslation is useless because it has no words at line number {line_number}\n{line.strip()[:100]}')
+ print(
+ f"\nTranslation is useless because it has no words at line number {line_number}\n{line.strip()[:100]}"
+ )
if error_found:
errors_encounter += 1
if errors_encounter > 0:
- print('\nVisit "https://frappeframework.com/docs/user/en/translations" to learn about valid translation strings.')
+ print(
+ '\nVisit "https://frappeframework.com/docs/user/en/translations" to learn about valid translation strings.'
+ )
sys.exit(1)
else:
- print('\nGood To Go!')
+ print("\nGood To Go!")