diff options
author | Calum Lind <calumlind@gmail.com> | 2018-10-02 16:39:51 +0200 |
---|---|---|
committer | Calum Lind <calumlind@gmail.com> | 2018-10-03 16:21:53 +0200 |
commit | b1cdc32f7357e9777eb6cc2d90094c7d122af2eb (patch) | |
tree | 9106ac399a7df178c8dbed6fe58009d36b18159a /gen_web_gettext.py | |
parent | [Common] Fix config missing value assignment (diff) | |
download | deluge-b1cdc32f7357e9777eb6cc2d90094c7d122af2eb.tar.xz deluge-b1cdc32f7357e9777eb6cc2d90094c7d122af2eb.zip |
[Lint] Use Black to auto-format code
The move to using auto-formatter makes it easier to read, submit and
speeds up development time. https://github.com/ambv/black/
Although I would prefer 79 chars, the default line length of 88 chars
used by black suffices. The flake8 line length remains at 120 chars
since black does not touch comments or docstrings and this will require
another round of fixes.
The only black setting that is not standard is the use of double-quotes
for strings so disabled any formatting of these. Note however that
flake8 will still flag usage of double-quotes. I may change my mind on
double vs single quotes but for now leave them.
A new pyproject.toml file has been created for black configuration.
Diffstat (limited to 'gen_web_gettext.py')
-rwxr-xr-x | gen_web_gettext.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/gen_web_gettext.py b/gen_web_gettext.py index a769ae3aa..fac509736 100755 --- a/gen_web_gettext.py +++ b/gen_web_gettext.py @@ -46,7 +46,10 @@ def check_missing_markup(js_dir): # Create a list of the matching strings to search for with the except_chars appended to each one. string_re = re.compile( - '(' + ')|('.join(['%s[^' + except_chars + "].*'"] * len(attr_list)) % tuple(attr_list) + ')', + '(' + + ')|('.join(['%s[^' + except_chars + "].*'"] * len(attr_list)) + % tuple(attr_list) + + ')' ) strings = {} @@ -58,10 +61,16 @@ def check_missing_markup(js_dir): for match in string_re.finditer(line): for string in match.groups(): # Ignore string that contains only digits or specificied strings in skip. - if not string or string.split('\'')[1].isdigit() or any(x in string for x in skip): + if ( + not string + or string.split('\'')[1].isdigit() + or any(x in string for x in skip) + ): continue locations = strings.get(string, []) - locations.append((os.path.join(root, filename), str(lineno + 1))) + locations.append( + (os.path.join(root, filename), str(lineno + 1)) + ) strings[string] = locations return strings @@ -70,8 +79,9 @@ GETTEXT_TPL = ( 'GetText={maps:{},' 'add:function(string,translation){this.maps[string]=translation},' 'get:function(string){if (this.maps[string]){string=this.maps[string]} return string}};' - 'function _(string){return GetText.get(string)}') -GETTEXT_SUBST_TPL = ("GetText.add('{key}','${{escape(_(\"{key}\"))}}')\n") + 'function _(string){return GetText.get(string)}' +) +GETTEXT_SUBST_TPL = "GetText.add('{key}','${{escape(_(\"{key}\"))}}')\n" def create_gettext_js(js_dir): @@ -94,7 +104,9 @@ def create_gettext_js(js_dir): fp.write(GETTEXT_TPL) for key in sorted(strings): if DEBUG: - fp.write('\n//: %s' % '//: '.join(['%s:%s\n' % x for x in strings[key]])) + fp.write( + '\n//: %s' % '//: '.join(['%s:%s\n' % x for x in strings[key]]) + ) fp.write(GETTEXT_SUBST_TPL.format(key=key)) return gettext_file |