Skip to content

Commit a20d87c

Browse files
Add flake8 check to GitLab CI, and fix style problems identified by flake8
1 parent fe95bc3 commit a20d87c

13 files changed

+271
-277
lines changed

.gitlab-ci.yml

+5-11
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ before_script:
3131

3232
# stage: check ----------------------
3333

34-
formatting:
34+
black:
3535
stage: check
3636
script: poetry run black --check .
3737

38+
flake8:
39+
stage: check
40+
script: poetry run flake8 deepl tests
41+
3842
# stage: build ----------------------
3943

4044
package:
@@ -56,16 +60,6 @@ package:
5660
vault: jenkins/client_libraries/test_server_url@backend
5761
file: false
5862

59-
#.use-mock-server-template: &use_mock_server_template
60-
# variables:
61-
# DEEPL_SERVER_URL: http://localhost:3000
62-
# DEEPL_MOCK_SERVER_PORT: 3000
63-
# DEEPL_PROXY_URL: http://localhost:3001
64-
# DEEPL_MOCK_PROXY_SERVER_PORT: 3001
65-
#
66-
# after_script:
67-
# - docker stop deepl-mock
68-
6963
test:
7064
<<: *use_test_server_template
7165
stage: test

deepl/__main__.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def action_languages(translator: deepl.Translator, glossary: bool):
4242
for language in target_languages:
4343
if language.supports_formality:
4444
print(f"{language.code}: {language.name} (supports formality)")
45-
else:
46-
print(f"{language.code}: {language.name}")
45+
else:
46+
print(f"{language.code}: {language.name}")
4747

4848

4949
def action_document(
@@ -206,8 +206,9 @@ def get_parser(prog_name):
206206
"--proxy-url",
207207
default=None,
208208
metavar="URL",
209-
help=f"proxy server URL to use for all connections; the {env_proxy_url} "
210-
f"environment variable may be used as secondary fallback",
209+
help="proxy server URL to use for all connections; the "
210+
f"{env_proxy_url} environment variable may be used as secondary "
211+
"fallback",
211212
)
212213

213214
# Note: add_subparsers param 'required' is not available in py36
@@ -255,7 +256,8 @@ def add_common_arguments(subparser: argparse.ArgumentParser):
255256
type=str,
256257
choices=[enum.value for enum in deepl.SplitSentences],
257258
default=deepl.SplitSentences.DEFAULT.value,
258-
help="control sentence splitting before translation, see API for information",
259+
help="control sentence splitting before translation, see API for "
260+
"information",
259261
)
260262
parser_text.add_argument(
261263
"--preserve-formatting",
@@ -399,16 +401,17 @@ def add_common_arguments(subparser: argparse.ArgumentParser):
399401
"--file",
400402
type=str,
401403
help="file to read glossary entries from. File must be in "
402-
"tab-separated values (TSV) format: one entry-pair per line, each line "
403-
"contains the source entry, a tab, then the target entry. Empty lines "
404-
"are ignored.",
404+
"tab-separated values (TSV) format: one entry-pair per line, each "
405+
"line contains the source entry, a tab, then the target entry. Empty "
406+
"lines are ignored.",
405407
)
406408

407409
parser_glossary_list = glossary_subparsers.add_parser(
408410
"list",
409411
help="list available glossaries",
410412
description="list available glossaries",
411413
)
414+
_ = parser_glossary_list # Suppress unused variable warning
412415

413416
parser_glossary_get = glossary_subparsers.add_parser(
414417
"get",
@@ -459,7 +462,7 @@ def main(args=None, prog_name=None):
459462

460463
if args.command is None:
461464
# Support for Python 3.6 - subcommands cannot be required
462-
sys.stderr.write(f"Error: command is required\n")
465+
sys.stderr.write("Error: command is required\n")
463466
parser.print_help(sys.stderr)
464467
sys.exit(1)
465468

@@ -500,7 +503,7 @@ def main(args=None, prog_name=None):
500503
elif args.command == "glossary":
501504
if args.subcommand is None:
502505
# Support for Python 3.6 - subcommands cannot be required
503-
sys.stderr.write(f"Error: glossary subcommand is required\n")
506+
sys.stderr.write("Error: glossary subcommand is required\n")
504507
parser_glossary.print_help(sys.stderr)
505508
sys.exit(1)
506509

deepl/http_client.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ def request_with_backoff(
124124
)
125125

126126
log_info(
127-
f"Starting retry {backoff.get_num_retries() + 1} for request {method} {url} "
128-
f"after sleeping for {backoff.get_time_until_deadline():.2f} seconds."
127+
f"Starting retry {backoff.get_num_retries() + 1} for request "
128+
f"{method} {url} after sleeping for "
129+
f"{backoff.get_time_until_deadline():.2f} seconds."
129130
)
130131
backoff.sleep_until_deadline()
131132

deepl/translator.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ def limit(self) -> Optional[int]:
227227

228228
@property
229229
def valid(self) -> bool:
230-
"""True iff both the count and limit are set for this usage type."""
230+
"""True iff both the count and limit are set for this usage
231+
type."""
231232
return self._count is not None and self._limit is not None
232233

233234
@property
@@ -546,11 +547,13 @@ def _check_valid_languages(
546547
"""Internal function to check given languages are valid."""
547548
if target_lang == "EN":
548549
raise DeepLException(
549-
'target_lang="EN" is deprecated, please use "EN-GB" or "EN-US" instead.'
550+
'target_lang="EN" is deprecated, please use "EN-GB" or "EN-US"'
551+
"instead."
550552
)
551553
elif target_lang == "PT":
552554
raise DeepLException(
553-
'target_lang="PT" is deprecated, please use "PT-PT" or "PT-BR" instead.'
555+
'target_lang="PT" is deprecated, please use "PT-PT" or "PT-BR"'
556+
"instead."
554557
)
555558

556559
def _check_language_and_formality(
@@ -758,17 +761,19 @@ def translate_document_from_filepath(
758761
759762
:param input_path: Path to document to be translated.
760763
:param output_path: Path to store translated document.
761-
:param source_lang: (Optional) Language code of input document, for example "DE",
762-
"EN", "FR". If omitted, DeepL will auto-detect the input language.
763-
:param target_lang: Language code to translate document into, for example "DE",
764-
"EN-US", "FR".
765-
:param formality: (Optional) Desired formality for translation, as Formality
766-
enum, "less" or "more".
764+
:param source_lang: (Optional) Language code of input document, for
765+
example "DE", "EN", "FR". If omitted, DeepL will auto-detect the
766+
input language.
767+
:param target_lang: Language code to translate document into, for
768+
example "DE", "EN-US", "FR".
769+
:param formality: (Optional) Desired formality for translation, as
770+
Formality enum, "less" or "more".
767771
:param glossary: (Optional) glossary or glossary ID to use for
768772
translation. Must match specified source_lang and target_lang.
769773
770-
:raises DocumentTranslationException: If an error occurs during translation,
771-
The exception includes information about the document request.
774+
:raises DocumentTranslationException: If an error occurs during
775+
translation. The exception includes information about the document
776+
request.
772777
"""
773778
with open(input_path, "rb") as in_file:
774779
with open(output_path, "wb") as out_file:
@@ -801,7 +806,8 @@ def translate_document(
801806
802807
:param input_document: Document to translate as a file-like object. It
803808
is recommended to open files in binary mode.
804-
:param output_document: File-like object to receive translated document.
809+
:param output_document: File-like object to receive translated
810+
document.
805811
:param source_lang: (Optional) Language code of input document, for
806812
example "DE", "EN", "FR". If omitted, DeepL will auto-detect the
807813
input language.

0 commit comments

Comments
 (0)