From dd8c03ccf3b8177ce2609d80c226f5e9f5332cdf Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Thu, 12 May 2022 11:06:08 +0200 Subject: [PATCH 01/15] Workaround for Typer optional default values with Python calls: added test and workaround. --- spacy/cli/init_config.py | 34 +++++++++++++++++++++++++++------- spacy/tests/test_cli.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index d4cd939c25f..fbd6c59651a 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -1,6 +1,9 @@ +from pprint import pprint from typing import Optional, List, Tuple from enum import Enum from pathlib import Path + +import typer.models from wasabi import Printer, diff_strings from thinc.api import Config import srsly @@ -44,20 +47,37 @@ def init_config_cli( DOCS: https://spacy.io/api/cli#init-config """ - pipeline = string_to_list(pipeline) + + # Force default values for arguments, if Typer hasn't resolved them yet (might occur on calls from Python). + # Mandatory arguments are assigned ... as default value in Typer, hence we ignore those. + optional_args = { + arg_name: arg_value.default + if any( + [ + isinstance(arg_value, typer_type) + for typer_type in (typer.models.OptionInfo, typer.models.ArgumentInfo) + ] + ) + and arg_value.default != Ellipsis + else arg_value + for arg_name, arg_value in locals().items() + } + + optional_args["pipeline"] = string_to_list(optional_args["pipeline"]) is_stdout = str(output_file) == "-" - if not is_stdout and output_file.exists() and not force_overwrite: + if not is_stdout and output_file.exists() and not optional_args["force_overwrite"]: msg = Printer() msg.fail( "The provided output file already exists. To force overwriting the config file, set the --force or -F flag.", exits=1, ) + config = init_config( - lang=lang, - pipeline=pipeline, - optimize=optimize.value, - gpu=gpu, - pretraining=pretraining, + lang=optional_args["lang"], + pipeline=optional_args["pipeline"], + optimize=optional_args["optimize"], + gpu=optional_args["gpu"], + pretraining=optional_args["pretraining"], silent=is_stdout, ) save_config(config, output_file, is_stdout=is_stdout) diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 3ef56d9f64a..bb40888b541 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import pytest import srsly @@ -15,7 +16,13 @@ from spacy.cli.debug_data import _compile_gold, _get_labels_from_model from spacy.cli.debug_data import _get_labels_from_spancat from spacy.cli.download import get_compatibility, get_version -from spacy.cli.init_config import RECOMMENDATIONS, init_config, fill_config +from spacy.cli.init_config import ( + RECOMMENDATIONS, + init_config, + fill_config, + init_config_cli, + Optimizations, +) from spacy.cli.package import get_third_party_dependencies from spacy.cli.package import _is_permitted_package_name from spacy.cli.validate import get_model_pkgs @@ -740,3 +747,24 @@ def test_debug_data_compile_gold(): eg = Example(pred, ref) data = _compile_gold([eg], ["ner"], nlp, True) assert data["boundary_cross_ents"] == 1 + + +def test_init_config_from_python_without_optional_args() -> None: + """ + Tests calling init_config_cli() from Python with optional arguments not set. This should detect bugs related to + Typer not automatically setting default values for arguments when decorated functions are called from Python instead + from the CLI. See also https://github.com/explosion/spaCy/issues/10727. + """ + + with make_tempdir() as temp_dir: + init_config_cli(output_file=temp_dir / "config.cfg") + + with make_tempdir() as temp_dir: + init_config_cli( + output_file=temp_dir / "config.cfg", + lang="en", + pipeline="ner", + optimize=Optimizations.efficiency, + gpu=False, + pretraining=False, + ) From fe0730f9f6aec0869442af5c0cf5d5ef35e0ef4a Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Wed, 18 May 2022 09:33:33 +0200 Subject: [PATCH 02/15] @rmitsch Workaround for Typer optional default values with Python calls: reverting some black formatting changes. Co-authored-by: Sofie Van Landeghem --- spacy/tests/test_cli.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index bb40888b541..d85fe2373aa 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -16,13 +16,8 @@ from spacy.cli.debug_data import _compile_gold, _get_labels_from_model from spacy.cli.debug_data import _get_labels_from_spancat from spacy.cli.download import get_compatibility, get_version -from spacy.cli.init_config import ( - RECOMMENDATIONS, - init_config, - fill_config, - init_config_cli, - Optimizations, -) +from spacy.cli.init_config import RECOMMENDATIONS, init_config, fill_config +from spacy.cli.init_config import init_config_cli, Optimizations, from spacy.cli.package import get_third_party_dependencies from spacy.cli.package import _is_permitted_package_name from spacy.cli.validate import get_model_pkgs From 457a5c9103059a5217496114c3df2dbe9f35cf92 Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Wed, 18 May 2022 09:33:54 +0200 Subject: [PATCH 03/15] @rmitsch Workaround for Typer optional default values with Python calls: removing return type hint. Co-authored-by: Sofie Van Landeghem --- spacy/tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index d85fe2373aa..2ec8fca7ba8 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -744,7 +744,7 @@ def test_debug_data_compile_gold(): assert data["boundary_cross_ents"] == 1 -def test_init_config_from_python_without_optional_args() -> None: +def test_init_config_from_python_without_optional_args(): """ Tests calling init_config_cli() from Python with optional arguments not set. This should detect bugs related to Typer not automatically setting default values for arguments when decorated functions are called from Python instead From ef66c3dd2fe27e0dae783c71e90a497842389d8c Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Wed, 18 May 2022 09:46:44 +0200 Subject: [PATCH 04/15] Workaround for Typer optional default values with Python calls: fixed imports, added GitHub issue marker. --- spacy/cli/init_config.py | 1 - spacy/tests/test_cli.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index fbd6c59651a..34f542ef8ea 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -1,4 +1,3 @@ -from pprint import pprint from typing import Optional, List, Tuple from enum import Enum from pathlib import Path diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 2ec8fca7ba8..39e754e5c52 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -1,5 +1,4 @@ import os -from pathlib import Path import pytest import srsly @@ -17,7 +16,7 @@ from spacy.cli.debug_data import _get_labels_from_spancat from spacy.cli.download import get_compatibility, get_version from spacy.cli.init_config import RECOMMENDATIONS, init_config, fill_config -from spacy.cli.init_config import init_config_cli, Optimizations, +from spacy.cli.init_config import init_config_cli, Optimizations from spacy.cli.package import get_third_party_dependencies from spacy.cli.package import _is_permitted_package_name from spacy.cli.validate import get_model_pkgs @@ -744,11 +743,12 @@ def test_debug_data_compile_gold(): assert data["boundary_cross_ents"] == 1 +@pytest.mark.issue(10727) def test_init_config_from_python_without_optional_args(): """ Tests calling init_config_cli() from Python with optional arguments not set. This should detect bugs related to Typer not automatically setting default values for arguments when decorated functions are called from Python instead - from the CLI. See also https://github.com/explosion/spaCy/issues/10727. + from the CLI. """ with make_tempdir() as temp_dir: From 902117658ad6bebb2ddf4ba42caa39eb60eb1889 Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Mon, 23 May 2022 14:52:17 +0200 Subject: [PATCH 05/15] Workaround for Typer optional default values with Python calls: removed forcing of default values for optional arguments in init_config_cli(). Added default values for init_config(). Synchronized default values for init_config_cli() and init_config(). --- spacy/cli/init_config.py | 68 ++++++++++++++++++++-------------------- spacy/tests/test_cli.py | 9 +++--- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 34f542ef8ea..137ace47395 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -14,7 +14,7 @@ from ..schemas import RecommendationSchema from ._util import init_cli, Arg, Opt, show_validation_error, COMMAND from ._util import string_to_list, import_code - +from ..util import SimpleFrozenList ROOT = Path(__file__).parent / "templates" TEMPLATE_PATH = ROOT / "quickstart_training.jinja" @@ -26,16 +26,31 @@ class Optimizations(str, Enum): accuracy = "accuracy" +class InitDefaultValues: + """ + Default values for initialization. Dedicated class to allow synchronized default values for init_config_cli() and + init_config(), i.e. initialization calls via CLI respectively Python. + """ + + output_file: Path = ... + lang = "en" + pipeline = SimpleFrozenList(["tagger", "parser", "ner"]) + optimize = Optimizations.efficiency.value + gpu = False + pretraining = False + force_overwrite = False + + @init_cli.command("config") def init_config_cli( # fmt: off output_file: Path = Arg(..., help="File to save the config to or - for stdout (will only output config and no additional logging info)", allow_dash=True), - lang: str = Opt("en", "--lang", "-l", help="Two-letter code of the language to use"), - pipeline: str = Opt("tagger,parser,ner", "--pipeline", "-p", help="Comma-separated names of trainable pipeline components to include (without 'tok2vec' or 'transformer')"), - optimize: Optimizations = Opt(Optimizations.efficiency.value, "--optimize", "-o", help="Whether to optimize for efficiency (faster inference, smaller model, lower memory consumption) or higher accuracy (potentially larger and slower model). This will impact the choice of architecture, pretrained weights and related hyperparameters."), - gpu: bool = Opt(False, "--gpu", "-G", help="Whether the model can run on GPU. This will impact the choice of architecture, pretrained weights and related hyperparameters."), - pretraining: bool = Opt(False, "--pretraining", "-pt", help="Include config for pretraining (with 'spacy pretrain')"), - force_overwrite: bool = Opt(False, "--force", "-F", help="Force overwriting the output file"), + lang: str = Opt(InitDefaultValues.lang, "--lang", "-l", help="Two-letter code of the language to use"), + pipeline: str = Opt(",".join(InitDefaultValues.pipeline), "--pipeline", "-p", help="Comma-separated names of trainable pipeline components to include (without 'tok2vec' or 'transformer')"), + optimize: Optimizations = Opt(InitDefaultValues.optimize, "--optimize", "-o", help="Whether to optimize for efficiency (faster inference, smaller model, lower memory consumption) or higher accuracy (potentially larger and slower model). This will impact the choice of architecture, pretrained weights and related hyperparameters."), + gpu: bool = Opt(InitDefaultValues.gpu, "--gpu", "-G", help="Whether the model can run on GPU. This will impact the choice of architecture, pretrained weights and related hyperparameters."), + pretraining: bool = Opt(InitDefaultValues.pretraining, "--pretraining", "-pt", help="Include config for pretraining (with 'spacy pretrain')"), + force_overwrite: bool = Opt(InitDefaultValues.force_overwrite, "--force", "-F", help="Force overwriting the output file"), # fmt: on ): """ @@ -47,24 +62,9 @@ def init_config_cli( DOCS: https://spacy.io/api/cli#init-config """ - # Force default values for arguments, if Typer hasn't resolved them yet (might occur on calls from Python). - # Mandatory arguments are assigned ... as default value in Typer, hence we ignore those. - optional_args = { - arg_name: arg_value.default - if any( - [ - isinstance(arg_value, typer_type) - for typer_type in (typer.models.OptionInfo, typer.models.ArgumentInfo) - ] - ) - and arg_value.default != Ellipsis - else arg_value - for arg_name, arg_value in locals().items() - } - - optional_args["pipeline"] = string_to_list(optional_args["pipeline"]) + pipeline = string_to_list(pipeline) is_stdout = str(output_file) == "-" - if not is_stdout and output_file.exists() and not optional_args["force_overwrite"]: + if not is_stdout and output_file.exists() and not force_overwrite: msg = Printer() msg.fail( "The provided output file already exists. To force overwriting the config file, set the --force or -F flag.", @@ -72,11 +72,11 @@ def init_config_cli( ) config = init_config( - lang=optional_args["lang"], - pipeline=optional_args["pipeline"], - optimize=optional_args["optimize"], - gpu=optional_args["gpu"], - pretraining=optional_args["pretraining"], + lang=lang, + pipeline=pipeline, + optimize=optimize, + gpu=gpu, + pretraining=pretraining, silent=is_stdout, ) save_config(config, output_file, is_stdout=is_stdout) @@ -152,11 +152,11 @@ def fill_config( def init_config( *, - lang: str, - pipeline: List[str], - optimize: str, - gpu: bool, - pretraining: bool = False, + lang: str = InitDefaultValues.lang, + pipeline: List[str] = InitDefaultValues.pipeline, + optimize: str = InitDefaultValues.optimize, + gpu: bool = InitDefaultValues.gpu, + pretraining: bool = InitDefaultValues.pretraining, silent: bool = True, ) -> Config: msg = Printer(no_print=silent) diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 39e754e5c52..e12dc4831a3 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -746,13 +746,14 @@ def test_debug_data_compile_gold(): @pytest.mark.issue(10727) def test_init_config_from_python_without_optional_args(): """ - Tests calling init_config_cli() from Python with optional arguments not set. This should detect bugs related to - Typer not automatically setting default values for arguments when decorated functions are called from Python instead + Tests calling init_config_cli() from Python with optional arguments not set. This should detect whether Typer + automatically sets default values for arguments when decorated functions are called from Python instead from the CLI. """ - with make_tempdir() as temp_dir: - init_config_cli(output_file=temp_dir / "config.cfg") + with pytest.raises(AttributeError): + with make_tempdir() as temp_dir: + init_config_cli(output_file=temp_dir / "config.cfg") with make_tempdir() as temp_dir: init_config_cli( From e19a14b1e5ef2919a2ac5a9a1b66e7f9ac9a85c6 Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Mon, 23 May 2022 15:30:06 +0200 Subject: [PATCH 06/15] Workaround for Typer optional default values with Python calls: removed unused import. --- spacy/cli/init_config.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 137ace47395..42084fc4607 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -2,7 +2,6 @@ from enum import Enum from pathlib import Path -import typer.models from wasabi import Printer, diff_strings from thinc.api import Config import srsly @@ -32,7 +31,7 @@ class InitDefaultValues: init_config(), i.e. initialization calls via CLI respectively Python. """ - output_file: Path = ... + output_file: Path = ... # type: ignore lang = "en" pipeline = SimpleFrozenList(["tagger", "parser", "ner"]) optimize = Optimizations.efficiency.value From e2555e51d5ecb71061be694eafdd8f1326e5f064 Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Mon, 23 May 2022 15:43:10 +0200 Subject: [PATCH 07/15] Workaround for Typer optional default values with Python calls: fixed usage of optimize in init_config_cli(). --- spacy/cli/init_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 42084fc4607..215ef9370df 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -34,7 +34,7 @@ class InitDefaultValues: output_file: Path = ... # type: ignore lang = "en" pipeline = SimpleFrozenList(["tagger", "parser", "ner"]) - optimize = Optimizations.efficiency.value + optimize = Optimizations.efficiency gpu = False pretraining = False force_overwrite = False @@ -73,7 +73,7 @@ def init_config_cli( config = init_config( lang=lang, pipeline=pipeline, - optimize=optimize, + optimize=optimize.value, gpu=gpu, pretraining=pretraining, silent=is_stdout, From 5c7eed28c4ccd2d49bf1c4ba1dcce34bcb3dbf1d Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Tue, 24 May 2022 11:33:41 +0200 Subject: [PATCH 08/15] Workaround for Typer optional default values with Pythhon calls: remove output_file from InitDefaultValues. --- spacy/cli/init_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 215ef9370df..d413ac62cb0 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -31,7 +31,6 @@ class InitDefaultValues: init_config(), i.e. initialization calls via CLI respectively Python. """ - output_file: Path = ... # type: ignore lang = "en" pipeline = SimpleFrozenList(["tagger", "parser", "ner"]) optimize = Optimizations.efficiency From 2abe11e73ba73b6437deb225d154a3001950bcee Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Wed, 25 May 2022 10:08:39 +0200 Subject: [PATCH 09/15] Workaround for Typer optional default values with Python calls: rename class for default init values. --- spacy/cli/init_config.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index d413ac62cb0..7f8c0070db0 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -25,7 +25,7 @@ class Optimizations(str, Enum): accuracy = "accuracy" -class InitDefaultValues: +class InitValues: """ Default values for initialization. Dedicated class to allow synchronized default values for init_config_cli() and init_config(), i.e. initialization calls via CLI respectively Python. @@ -43,12 +43,12 @@ class InitDefaultValues: def init_config_cli( # fmt: off output_file: Path = Arg(..., help="File to save the config to or - for stdout (will only output config and no additional logging info)", allow_dash=True), - lang: str = Opt(InitDefaultValues.lang, "--lang", "-l", help="Two-letter code of the language to use"), - pipeline: str = Opt(",".join(InitDefaultValues.pipeline), "--pipeline", "-p", help="Comma-separated names of trainable pipeline components to include (without 'tok2vec' or 'transformer')"), - optimize: Optimizations = Opt(InitDefaultValues.optimize, "--optimize", "-o", help="Whether to optimize for efficiency (faster inference, smaller model, lower memory consumption) or higher accuracy (potentially larger and slower model). This will impact the choice of architecture, pretrained weights and related hyperparameters."), - gpu: bool = Opt(InitDefaultValues.gpu, "--gpu", "-G", help="Whether the model can run on GPU. This will impact the choice of architecture, pretrained weights and related hyperparameters."), - pretraining: bool = Opt(InitDefaultValues.pretraining, "--pretraining", "-pt", help="Include config for pretraining (with 'spacy pretrain')"), - force_overwrite: bool = Opt(InitDefaultValues.force_overwrite, "--force", "-F", help="Force overwriting the output file"), + lang: str = Opt(InitValues.lang, "--lang", "-l", help="Two-letter code of the language to use"), + pipeline: str = Opt(",".join(InitValues.pipeline), "--pipeline", "-p", help="Comma-separated names of trainable pipeline components to include (without 'tok2vec' or 'transformer')"), + optimize: Optimizations = Opt(InitValues.optimize, "--optimize", "-o", help="Whether to optimize for efficiency (faster inference, smaller model, lower memory consumption) or higher accuracy (potentially larger and slower model). This will impact the choice of architecture, pretrained weights and related hyperparameters."), + gpu: bool = Opt(InitValues.gpu, "--gpu", "-G", help="Whether the model can run on GPU. This will impact the choice of architecture, pretrained weights and related hyperparameters."), + pretraining: bool = Opt(InitValues.pretraining, "--pretraining", "-pt", help="Include config for pretraining (with 'spacy pretrain')"), + force_overwrite: bool = Opt(InitValues.force_overwrite, "--force", "-F", help="Force overwriting the output file"), # fmt: on ): """ @@ -150,11 +150,11 @@ def fill_config( def init_config( *, - lang: str = InitDefaultValues.lang, - pipeline: List[str] = InitDefaultValues.pipeline, - optimize: str = InitDefaultValues.optimize, - gpu: bool = InitDefaultValues.gpu, - pretraining: bool = InitDefaultValues.pretraining, + lang: str = InitValues.lang, + pipeline: List[str] = InitValues.pipeline, + optimize: str = InitValues.optimize, + gpu: bool = InitValues.gpu, + pretraining: bool = InitValues.pretraining, silent: bool = True, ) -> Config: msg = Printer(no_print=silent) From 527bee1d741382cf08b730f6fbe91715903b03ae Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Wed, 25 May 2022 10:30:48 +0200 Subject: [PATCH 10/15] Workaround for Typer optional default values with Python calls: remove newline. --- spacy/cli/init_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 7f8c0070db0..4f3929395fa 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -59,7 +59,6 @@ def init_config_cli( DOCS: https://spacy.io/api/cli#init-config """ - pipeline = string_to_list(pipeline) is_stdout = str(output_file) == "-" if not is_stdout and output_file.exists() and not force_overwrite: From da5ae2e3451ca04e6addaac5632cafced16bf580 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Thu, 9 Jun 2022 10:25:23 +0200 Subject: [PATCH 11/15] remove introduced newlines --- spacy/cli/init_config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 4f3929395fa..83162e9fbbc 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -1,7 +1,6 @@ from typing import Optional, List, Tuple from enum import Enum from pathlib import Path - from wasabi import Printer, diff_strings from thinc.api import Config import srsly @@ -67,7 +66,6 @@ def init_config_cli( "The provided output file already exists. To force overwriting the config file, set the --force or -F flag.", exits=1, ) - config = init_config( lang=lang, pipeline=pipeline, From 19a4d7afcffd37dbc24e6861a88691986e9c133c Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Thu, 9 Jun 2022 13:10:21 +0200 Subject: [PATCH 12/15] Remove test_init_config_from_python_without_optional_args(). --- spacy/tests/test_cli.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 79f1ba9e2fe..a9caac2d0ab 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -751,28 +751,6 @@ def test_debug_data_compile_gold(): assert data["boundary_cross_ents"] == 1 -@pytest.mark.issue(10727) -def test_init_config_from_python_without_optional_args(): - """ - Tests calling init_config_cli() from Python with optional arguments not set. This should detect whether Typer - automatically sets default values for arguments when decorated functions are called from Python instead - from the CLI. - """ - - with pytest.raises(AttributeError): - with make_tempdir() as temp_dir: - init_config_cli(output_file=temp_dir / "config.cfg") - - with make_tempdir() as temp_dir: - init_config_cli( - output_file=temp_dir / "config.cfg", - lang="en", - pipeline="ner", - optimize=Optimizations.efficiency, - gpu=False, - pretraining=False, - ) - def test_debug_data_compile_gold_for_spans(): nlp = English() spans_key = "sc" From 16f8944db516ba58483dff7886306c1cf8054a61 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Fri, 10 Jun 2022 18:34:54 +0200 Subject: [PATCH 13/15] remove leftover import --- spacy/tests/test_cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index a9caac2d0ab..838e003698f 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -23,7 +23,6 @@ from spacy.cli.debug_data import _get_spans_length_freq_dist from spacy.cli.download import get_compatibility, get_version from spacy.cli.init_config import RECOMMENDATIONS, init_config, fill_config -from spacy.cli.init_config import init_config_cli, Optimizations from spacy.cli.package import get_third_party_dependencies from spacy.cli.package import _is_permitted_package_name from spacy.cli.validate import get_model_pkgs From 58047f809576ab9504186512c3056f12c5d79e77 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Fri, 10 Jun 2022 18:36:18 +0200 Subject: [PATCH 14/15] reformat import --- spacy/cli/init_config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 83162e9fbbc..4018095c9fe 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -10,8 +10,10 @@ from .. import util from ..language import DEFAULT_CONFIG_PRETRAIN_PATH from ..schemas import RecommendationSchema +from ..util import SimpleFrozenList from ._util import init_cli, Arg, Opt, show_validation_error, COMMAND from ._util import string_to_list, import_code + from ..util import SimpleFrozenList ROOT = Path(__file__).parent / "templates" From 64db12ef17a93d32b4c314f24930c7d75d3b8586 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Fri, 10 Jun 2022 18:36:42 +0200 Subject: [PATCH 15/15] remove duplicate --- spacy/cli/init_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 4018095c9fe..b634caa4ce3 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -14,7 +14,6 @@ from ._util import init_cli, Arg, Opt, show_validation_error, COMMAND from ._util import string_to_list, import_code -from ..util import SimpleFrozenList ROOT = Path(__file__).parent / "templates" TEMPLATE_PATH = ROOT / "quickstart_training.jinja"