mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-16 20:25:26 +00:00
Use ruff to format Python files (#658)
This commit is contained in:
@ -10,18 +10,16 @@ Ref: https://github.com/flutter/flutter/issues/27997
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
|
dart_files = Path("lib").rglob("*.dart")
|
||||||
dart_files = Path('lib').rglob('*.dart')
|
|
||||||
|
|
||||||
with open("test/coverage_helper_test.dart", "w") as f:
|
with open("test/coverage_helper_test.dart", "w") as f:
|
||||||
|
|
||||||
f.write("// ignore_for_file: unused_import\n\n")
|
f.write("// ignore_for_file: unused_import\n\n")
|
||||||
|
|
||||||
skips = [
|
skips = [
|
||||||
'generated',
|
"generated",
|
||||||
'l10n',
|
"l10n",
|
||||||
'dsn.dart',
|
"dsn.dart",
|
||||||
]
|
]
|
||||||
|
|
||||||
for path in dart_files:
|
for path in dart_files:
|
||||||
@ -32,15 +30,18 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Remove leading 'lib\' text
|
# Remove leading 'lib\' text
|
||||||
path = path[4:]
|
path = path[4:]
|
||||||
path = path.replace('\\', '/')
|
path = path.replace("\\", "/")
|
||||||
f.write(f'import "package:inventree/{path}";\n')
|
f.write(f'import "package:inventree/{path}";\n')
|
||||||
|
|
||||||
f.write("\n\n")
|
f.write("\n\n")
|
||||||
|
|
||||||
f.write("// DO NOT EDIT THIS FILE - it has been auto-generated by 'find_dart_files.py'\n")
|
f.write(
|
||||||
f.write("// It has been created to ensure that *all* source file are included in coverage data\n")
|
"// DO NOT EDIT THIS FILE - it has been auto-generated by 'find_dart_files.py'\n"
|
||||||
|
)
|
||||||
f.write('import "package:test/test.dart";\n\n');
|
f.write(
|
||||||
|
"// It has been created to ensure that *all* source file are included in coverage data\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
f.write('import "package:test/test.dart";\n\n')
|
||||||
f.write("// Do not actually test anything!\n")
|
f.write("// Do not actually test anything!\n")
|
||||||
f.write("void main() {}\n")
|
f.write("void main() {}\n")
|
||||||
|
@ -16,6 +16,7 @@ from posixpath import dirname
|
|||||||
import shutil
|
import shutil
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def process_locale_file(filename, locale_name):
|
def process_locale_file(filename, locale_name):
|
||||||
"""
|
"""
|
||||||
Process a locale file after copying
|
Process a locale file after copying
|
||||||
@ -26,21 +27,20 @@ def process_locale_file(filename, locale_name):
|
|||||||
# TODO: Use JSON processing instead of manual
|
# TODO: Use JSON processing instead of manual
|
||||||
# Need to work out unicode issues for this to work
|
# Need to work out unicode issues for this to work
|
||||||
|
|
||||||
with open(filename, 'r', encoding='utf-8') as input_file:
|
with open(filename, "r", encoding="utf-8") as input_file:
|
||||||
|
|
||||||
lines = input_file.readlines()
|
lines = input_file.readlines()
|
||||||
|
|
||||||
with open(filename, 'w', encoding='utf-8') as output_file:
|
with open(filename, "w", encoding="utf-8") as output_file:
|
||||||
# Using JSON processing would be simpler here,
|
# Using JSON processing would be simpler here,
|
||||||
# but it does not preserve unicode data!
|
# but it does not preserve unicode data!
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if '@@locale' in line:
|
if "@@locale" in line:
|
||||||
new_line = f' "@@locale": "{locale_name}"'
|
new_line = f' "@@locale": "{locale_name}"'
|
||||||
|
|
||||||
if ',' in line:
|
if "," in line:
|
||||||
new_line += ','
|
new_line += ","
|
||||||
|
|
||||||
new_line += '\n'
|
new_line += "\n"
|
||||||
|
|
||||||
line = new_line
|
line = new_line
|
||||||
|
|
||||||
@ -55,12 +55,10 @@ def copy_locale_file(path):
|
|||||||
here = os.path.abspath(os.path.dirname(__file__))
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
for f in os.listdir(path):
|
for f in os.listdir(path):
|
||||||
|
|
||||||
src = os.path.join(path, f)
|
src = os.path.join(path, f)
|
||||||
dst = os.path.join(here, 'collected', f)
|
dst = os.path.join(here, "collected", f)
|
||||||
|
|
||||||
if os.path.exists(src) and os.path.isfile(src) and f.endswith('.arb'):
|
|
||||||
|
|
||||||
|
if os.path.exists(src) and os.path.isfile(src) and f.endswith(".arb"):
|
||||||
shutil.copyfile(src, dst)
|
shutil.copyfile(src, dst)
|
||||||
print(f"Copied file '{f}'")
|
print(f"Copied file '{f}'")
|
||||||
|
|
||||||
@ -73,7 +71,7 @@ def copy_locale_file(path):
|
|||||||
locale = r.groups()[0]
|
locale = r.groups()[0]
|
||||||
fallback = f"app_{locale}.arb"
|
fallback = f"app_{locale}.arb"
|
||||||
|
|
||||||
fallback_file = os.path.join(here, 'collected', fallback)
|
fallback_file = os.path.join(here, "collected", fallback)
|
||||||
|
|
||||||
if not os.path.exists(fallback_file):
|
if not os.path.exists(fallback_file):
|
||||||
print(f"Creating fallback file:", fallback_file)
|
print(f"Creating fallback file:", fallback_file)
|
||||||
@ -89,16 +87,16 @@ def generate_locale_list(locales):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
with open("supported_locales.dart", "w") as output:
|
with open("supported_locales.dart", "w") as output:
|
||||||
|
output.write(
|
||||||
output.write("// This file is auto-generated by the 'collect_translations.py' script - do not edit it directly!\n\n")
|
"// This file is auto-generated by the 'collect_translations.py' script - do not edit it directly!\n\n"
|
||||||
|
)
|
||||||
output.write('import "package:flutter/material.dart";\n\n')
|
output.write('import "package:flutter/material.dart";\n\n')
|
||||||
output.write("const List<Locale> supported_locales = [\n")
|
output.write("const List<Locale> supported_locales = [\n")
|
||||||
|
|
||||||
locales = sorted(locales)
|
locales = sorted(locales)
|
||||||
|
|
||||||
for locale in locales:
|
for locale in locales:
|
||||||
|
if locale.startswith("."):
|
||||||
if locale.startswith('.'):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
splt = locale.split("_")
|
splt = locale.split("_")
|
||||||
@ -107,19 +105,21 @@ def generate_locale_list(locales):
|
|||||||
lc, cc = splt
|
lc, cc = splt
|
||||||
else:
|
else:
|
||||||
lc = locale
|
lc = locale
|
||||||
cc = ''
|
cc = ""
|
||||||
|
|
||||||
output.write(f' Locale("{lc}", "{cc}"), // Translations available in app_{locale}.arb\n')
|
output.write(
|
||||||
|
f' Locale("{lc}", "{cc}"), // Translations available in app_{locale}.arb\n'
|
||||||
|
)
|
||||||
|
|
||||||
output.write("];\n")
|
output.write("];\n")
|
||||||
output.write("")
|
output.write("")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
here = os.path.abspath(os.path.dirname(__file__))
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
# Ensure the 'collected' output directory exists
|
# Ensure the 'collected' output directory exists
|
||||||
output_dir = os.path.join(here, 'collected')
|
output_dir = os.path.join(here, "collected")
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
# Remove existing .arb files from output directory
|
# Remove existing .arb files from output directory
|
||||||
@ -128,12 +128,11 @@ if __name__ == '__main__':
|
|||||||
for arb in arbs:
|
for arb in arbs:
|
||||||
os.remove(arb)
|
os.remove(arb)
|
||||||
|
|
||||||
locales = ['en']
|
locales = ["en"]
|
||||||
|
|
||||||
for locale in os.listdir(here):
|
for locale in os.listdir(here):
|
||||||
|
|
||||||
# Ignore the output directory
|
# Ignore the output directory
|
||||||
if locale == 'collected':
|
if locale == "collected":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
f = os.path.join(here, locale)
|
f = os.path.join(here, locale)
|
||||||
@ -144,8 +143,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# Ensure the translation source file ('app_en.arb') is copied also
|
# Ensure the translation source file ('app_en.arb') is copied also
|
||||||
# Note that this does not require any further processing
|
# Note that this does not require any further processing
|
||||||
src = os.path.join(here, 'app_en.arb')
|
src = os.path.join(here, "app_en.arb")
|
||||||
dst = os.path.join(here, 'collected', 'app_en.arb')
|
dst = os.path.join(here, "collected", "app_en.arb")
|
||||||
|
|
||||||
shutil.copyfile(src, dst)
|
shutil.copyfile(src, dst)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user