From d0f63e7d4ded7e6bec8fcaef821a3f5268d5e809 Mon Sep 17 00:00:00 2001 From: edxu96 Date: Mon, 24 May 2021 11:11:28 +0200 Subject: [PATCH 1/6] Option indicates German word in search (#1) --- src/cmdict/run_script.py | 40 ++++++++++++++++++++++++++++----- tests/cmdict/test_run_script.py | 4 ++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/cmdict/run_script.py b/src/cmdict/run_script.py index d75cb67..139d9d6 100644 --- a/src/cmdict/run_script.py +++ b/src/cmdict/run_script.py @@ -80,19 +80,27 @@ def download(): @cli.command() @click.argument("words", nargs=-1) -def search(words): +@click.option( + "--german", "-de", is_flag=True, help="Whether it is German word." +) +def search(words, german): """Type in one English word and echo its Chinese translation. Args: words (str): one English word to be searched. For example, "a lot" or "mirror". + german (bool): whether it is German word. """ - if _valid_db_exists(): - db_engine = ECDICTConnector() - for i, word in enumerate(words): - _echo_item(word, db_engine.query(word)) + if german: + for _, word in enumerate(words): + _echo_item_de(word, None) else: - _echo_warn_download() + if _valid_db_exists(): + db_engine = ECDICTConnector() + for _, word in enumerate(words): + _echo_item(word, db_engine.query(word)) + else: + _echo_warn_download() @cli.command() @@ -184,6 +192,26 @@ def _echo_item(word, res): ) +def _echo_item_de(word, res): + """Echo a German word search result to cli. + + Args: + word (str): The word. + res (dict): The word search result. + """ + _echo_divider() + if res: + click.echo(Fore.CYAN + Style.BRIGHT + res + "\n") + else: + click.echo( + Fore.RED + + Style.BRIGHT + + word + + Style.RESET_ALL + + " can not be returned successfully!" + ) + + def _valid_db_exists(): """Return if a valid database is found. diff --git a/tests/cmdict/test_run_script.py b/tests/cmdict/test_run_script.py index ccec61a..000de65 100644 --- a/tests/cmdict/test_run_script.py +++ b/tests/cmdict/test_run_script.py @@ -22,6 +22,10 @@ def test_cli_search(): """Test cli word search.""" res = CliRunner().invoke(search, "play") assert "theatrical performance of a drama" in res.output + res = CliRunner().invoke(search, ["play", "-de"]) + assert "play can not be returned successfully" in res.output + res = CliRunner().invoke(search, ["play", "--german"]) + assert "play can not be returned successfully" in res.output def test_cli_search_non_exist_word(): From 3dbc673fe968e07b8d909154afe4f5697b51f03b Mon Sep 17 00:00:00 2001 From: edxu96 Date: Sun, 30 May 2021 13:08:55 +0200 Subject: [PATCH 2/6] pre-commit hook same versions as pyproject --- .pre-commit-config.yaml | 8 +++++--- .python-version | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .python-version diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9736283..3f411b2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,6 @@ +default_language_version: + python: python3.6 + repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.1.0 @@ -8,10 +11,9 @@ repos: - id: trailing-whitespace - repo: https://github.com/ambv/black - rev: stable + rev: 19.10b0 hooks: - id: black - language_version: python3.7 - repo: https://gitlab.com/pycqa/flake8 rev: 3.8.2 @@ -25,6 +27,6 @@ repos: - 'pydocstyle' - repo: https://github.com/terrencepreilly/darglint - rev: master + rev: v1.4.1 hooks: - id: darglint diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..9575d51 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.6.1 From d29a97b811048d43261b0783fab8532e3b69e4aa Mon Sep 17 00:00:00 2001 From: Edward Xu Date: Sun, 30 May 2021 21:48:13 +0200 Subject: [PATCH 3/6] remove python version specification --- .pre-commit-config.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f411b2..61f4b1f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,3 @@ -default_language_version: - python: python3.6 - repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.1.0 From deee4ebc5cd6c220cf58cc2f5914db7cd79747cf Mon Sep 17 00:00:00 2001 From: Edward Xu Date: Sun, 30 May 2021 21:54:02 +0200 Subject: [PATCH 4/6] use python 3.6 in GH Actions --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 792cd3b..4ec6c2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - python-version: [3.7] + python-version: [3.6] poetry-version: [1.1.4] steps: From cba935bd65beb25d2416b3e4c50197fd215ac282 Mon Sep 17 00:00:00 2001 From: Edward Xu Date: Sun, 30 May 2021 22:11:09 +0200 Subject: [PATCH 5/6] specify python version for black --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61f4b1f..e2f6688 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,6 +11,7 @@ repos: rev: 19.10b0 hooks: - id: black + language_version: python3.6 - repo: https://gitlab.com/pycqa/flake8 rev: 3.8.2 From 73d071ee9d288e33b930de665bf301fd92c56373 Mon Sep 17 00:00:00 2001 From: Edward Xu Date: Mon, 31 May 2021 07:05:48 +0200 Subject: [PATCH 6/6] use flake8 3.9.0 to support indent-size option --- .pre-commit-config.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e2f6688..51e878a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,10 +11,9 @@ repos: rev: 19.10b0 hooks: - id: black - language_version: python3.6 - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.2 + rev: 3.9.0 hooks: - id: flake8 additional_dependencies: