mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 01:48:04 +03:00 
			
		
		
		
	Merge pull request #7421 from adrianeboyd/bugfix/cli-code-arg
This commit is contained in:
		
						commit
						3466a11e72
					
				| 
						 | 
					@ -20,7 +20,7 @@ def debug_config_cli(
 | 
				
			||||||
    # fmt: off
 | 
					    # fmt: off
 | 
				
			||||||
    ctx: typer.Context,  # This is only used to read additional arguments
 | 
					    ctx: typer.Context,  # This is only used to read additional arguments
 | 
				
			||||||
    config_path: Path = Arg(..., help="Path to config file", exists=True, allow_dash=True),
 | 
					    config_path: Path = Arg(..., help="Path to config file", exists=True, allow_dash=True),
 | 
				
			||||||
    code_path: Optional[Path] = Opt(None, "--code-path", "-c", help="Path to Python file with additional code (registered functions) to be imported"),
 | 
					    code_path: Optional[Path] = Opt(None, "--code-path", "--code", "-c", help="Path to Python file with additional code (registered functions) to be imported"),
 | 
				
			||||||
    show_funcs: bool = Opt(False, "--show-functions", "-F", help="Show an overview of all registered functions used in the config and where they come from (modules, files etc.)"),
 | 
					    show_funcs: bool = Opt(False, "--show-functions", "-F", help="Show an overview of all registered functions used in the config and where they come from (modules, files etc.)"),
 | 
				
			||||||
    show_vars: bool = Opt(False, "--show-variables", "-V", help="Show an overview of all variables referenced in the config and their values. This will also reflect variables overwritten on the CLI.")
 | 
					    show_vars: bool = Opt(False, "--show-variables", "-V", help="Show an overview of all variables referenced in the config and their values. This will also reflect variables overwritten on the CLI.")
 | 
				
			||||||
    # fmt: on
 | 
					    # fmt: on
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,7 @@ def debug_data_cli(
 | 
				
			||||||
    # fmt: off
 | 
					    # fmt: off
 | 
				
			||||||
    ctx: typer.Context,  # This is only used to read additional arguments
 | 
					    ctx: typer.Context,  # This is only used to read additional arguments
 | 
				
			||||||
    config_path: Path = Arg(..., help="Path to config file", exists=True, allow_dash=True),
 | 
					    config_path: Path = Arg(..., help="Path to config file", exists=True, allow_dash=True),
 | 
				
			||||||
    code_path: Optional[Path] = Opt(None, "--code-path", "-c", help="Path to Python file with additional code (registered functions) to be imported"),
 | 
					    code_path: Optional[Path] = Opt(None, "--code-path", "--code", "-c", help="Path to Python file with additional code (registered functions) to be imported"),
 | 
				
			||||||
    ignore_warnings: bool = Opt(False, "--ignore-warnings", "-IW", help="Ignore warnings, only show stats and errors"),
 | 
					    ignore_warnings: bool = Opt(False, "--ignore-warnings", "-IW", help="Ignore warnings, only show stats and errors"),
 | 
				
			||||||
    verbose: bool = Opt(False, "--verbose", "-V", help="Print additional information and explanations"),
 | 
					    verbose: bool = Opt(False, "--verbose", "-V", help="Print additional information and explanations"),
 | 
				
			||||||
    no_format: bool = Opt(False, "--no-format", "-NF", help="Don't pretty-print the results"),
 | 
					    no_format: bool = Opt(False, "--no-format", "-NF", help="Don't pretty-print the results"),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,8 @@ from jinja2 import Template
 | 
				
			||||||
from .. import util
 | 
					from .. import util
 | 
				
			||||||
from ..language import DEFAULT_CONFIG_PRETRAIN_PATH
 | 
					from ..language import DEFAULT_CONFIG_PRETRAIN_PATH
 | 
				
			||||||
from ..schemas import RecommendationSchema
 | 
					from ..schemas import RecommendationSchema
 | 
				
			||||||
from ._util import init_cli, Arg, Opt, show_validation_error, COMMAND, string_to_list
 | 
					from ._util import init_cli, Arg, Opt, show_validation_error, COMMAND
 | 
				
			||||||
 | 
					from ._util import string_to_list, import_code
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ROOT = Path(__file__).parent / "templates"
 | 
					ROOT = Path(__file__).parent / "templates"
 | 
				
			||||||
| 
						 | 
					@ -70,7 +71,8 @@ def init_fill_config_cli(
 | 
				
			||||||
    base_path: Path = Arg(..., help="Base config to fill", exists=True, dir_okay=False),
 | 
					    base_path: Path = Arg(..., help="Base config to fill", exists=True, dir_okay=False),
 | 
				
			||||||
    output_file: Path = Arg("-", help="File to save config.cfg to (or - for stdout)", allow_dash=True),
 | 
					    output_file: Path = Arg("-", help="File to save config.cfg to (or - for stdout)", allow_dash=True),
 | 
				
			||||||
    pretraining: bool = Opt(False, "--pretraining", "-pt", help="Include config for pretraining (with 'spacy pretrain')"),
 | 
					    pretraining: bool = Opt(False, "--pretraining", "-pt", help="Include config for pretraining (with 'spacy pretrain')"),
 | 
				
			||||||
    diff: bool = Opt(False, "--diff", "-D", help="Print a visual diff highlighting the changes")
 | 
					    diff: bool = Opt(False, "--diff", "-D", help="Print a visual diff highlighting the changes"),
 | 
				
			||||||
 | 
					    code_path: Optional[Path] = Opt(None, "--code-path", "--code", "-c", help="Path to Python file with additional code (registered functions) to be imported"),
 | 
				
			||||||
    # fmt: on
 | 
					    # fmt: on
 | 
				
			||||||
):
 | 
					):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
| 
						 | 
					@ -82,6 +84,7 @@ def init_fill_config_cli(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DOCS: https://spacy.io/api/cli#init-fill-config
 | 
					    DOCS: https://spacy.io/api/cli#init-fill-config
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					    import_code(code_path)
 | 
				
			||||||
    fill_config(output_file, base_path, pretraining=pretraining, diff=diff)
 | 
					    fill_config(output_file, base_path, pretraining=pretraining, diff=diff)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -170,14 +170,15 @@ validation error with more details.
 | 
				
			||||||
$ python -m spacy init fill-config [base_path] [output_file] [--diff]
 | 
					$ python -m spacy init fill-config [base_path] [output_file] [--diff]
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| Name                   | Description                                                                                                                         |
 | 
					| Name                   | Description                                                                                                                                                                          |
 | 
				
			||||||
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
 | 
					| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
 | 
				
			||||||
| `base_path`            | Path to base config to fill, e.g. generated by the [quickstart widget](/usage/training#quickstart). ~~Path (positional)~~           |
 | 
					| `base_path`            | Path to base config to fill, e.g. generated by the [quickstart widget](/usage/training#quickstart). ~~Path (positional)~~                                                            |
 | 
				
			||||||
| `output_file`          | Path to output `.cfg` file. If not set, the config is written to stdout so you can pipe it forward to a file. ~~Path (positional)~~ |
 | 
					| `output_file`          | Path to output `.cfg` file. If not set, the config is written to stdout so you can pipe it forward to a file. ~~Path (positional)~~                                                  |
 | 
				
			||||||
| `--pretraining`, `-pt` | Include config for pretraining (with [`spacy pretrain`](/api/cli#pretrain)). Defaults to `False`. ~~bool (flag)~~                   |
 | 
					| `--code`, `-c`         | Path to Python file with additional code to be imported. Allows [registering custom functions](/usage/training#custom-functions) for new architectures. ~~Optional[Path] \(option)~~ |
 | 
				
			||||||
| `--diff`, `-D`         | Print a visual diff highlighting the changes. ~~bool (flag)~~                                                                       |
 | 
					| `--pretraining`, `-pt` | Include config for pretraining (with [`spacy pretrain`](/api/cli#pretrain)). Defaults to `False`. ~~bool (flag)~~                                                                    |
 | 
				
			||||||
| `--help`, `-h`         | Show help message and available arguments. ~~bool (flag)~~                                                                          |
 | 
					| `--diff`, `-D`         | Print a visual diff highlighting the changes. ~~bool (flag)~~                                                                                                                        |
 | 
				
			||||||
| **CREATES**            | Complete and auto-filled config file for training.                                                                                  |
 | 
					| `--help`, `-h`         | Show help message and available arguments. ~~bool (flag)~~                                                                                                                           |
 | 
				
			||||||
 | 
					| **CREATES**            | Complete and auto-filled config file for training.                                                                                                                                   |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### init vectors {#init-vectors new="3" tag="command"}
 | 
					### init vectors {#init-vectors new="3" tag="command"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -805,7 +806,7 @@ $ python -m spacy train [config_path] [--output] [--code] [--verbose] [--gpu-id]
 | 
				
			||||||
| Name              | Description                                                                                                                                                                                                        |
 | 
					| Name              | Description                                                                                                                                                                                                        |
 | 
				
			||||||
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
 | 
					| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
 | 
				
			||||||
| `config_path`     | Path to [training config](/api/data-formats#config) file containing all settings and hyperparameters. If `-`, the data will be [read from stdin](/usage/training#config-stdin). ~~Union[Path, str] \(positional)~~ |
 | 
					| `config_path`     | Path to [training config](/api/data-formats#config) file containing all settings and hyperparameters. If `-`, the data will be [read from stdin](/usage/training#config-stdin). ~~Union[Path, str] \(positional)~~ |
 | 
				
			||||||
| `--output`, `-o`  | Directory to store trained pipeline in. Will be created if it doesn't exist. ~~Optional[Path] \(positional)~~                                                                                                      |
 | 
					| `--output`, `-o`  | Directory to store trained pipeline in. Will be created if it doesn't exist. ~~Optional[Path] \(option)~~                                                                                                          |
 | 
				
			||||||
| `--code`, `-c`    | Path to Python file with additional code to be imported. Allows [registering custom functions](/usage/training#custom-functions) for new architectures. ~~Optional[Path] \(option)~~                               |
 | 
					| `--code`, `-c`    | Path to Python file with additional code to be imported. Allows [registering custom functions](/usage/training#custom-functions) for new architectures. ~~Optional[Path] \(option)~~                               |
 | 
				
			||||||
| `--verbose`, `-V` | Show more detailed messages during training. ~~bool (flag)~~                                                                                                                                                       |
 | 
					| `--verbose`, `-V` | Show more detailed messages during training. ~~bool (flag)~~                                                                                                                                                       |
 | 
				
			||||||
| `--gpu-id`, `-g`  | GPU ID or `-1` for CPU. Defaults to `-1`. ~~int (option)~~                                                                                                                                                         |
 | 
					| `--gpu-id`, `-g`  | GPU ID or `-1` for CPU. Defaults to `-1`. ~~int (option)~~                                                                                                                                                         |
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user