mirror of https://github.com/explosion/spaCy.git
Allow reading config from sdtin in spacy train
This commit is contained in:
parent
2c27093c5f
commit
d25b1606d6
|
@ -18,7 +18,7 @@ from .. import util
|
|||
def train_cli(
|
||||
# fmt: off
|
||||
ctx: typer.Context, # This is only used to read additional arguments
|
||||
config_path: Path = Arg(..., help="Path to config file", exists=True),
|
||||
config_path: Path = Arg(..., help="Path to config file", exists=True, allow_dash=True),
|
||||
output_path: Optional[Path] = Opt(None, "--output", "--output-path", "-o", help="Output directory to store trained pipeline in"),
|
||||
code_path: Optional[Path] = Opt(None, "--code", "-c", help="Path to Python file with additional code (registered functions) to be imported"),
|
||||
verbose: bool = Opt(False, "--verbose", "-V", "-VV", help="Display more information for debugging purposes"),
|
||||
|
@ -41,7 +41,7 @@ def train_cli(
|
|||
"""
|
||||
util.logger.setLevel(logging.DEBUG if verbose else logging.INFO)
|
||||
# Make sure all files and paths exists if they are needed
|
||||
if not config_path or not config_path.exists():
|
||||
if not config_path or (str(config_path) != "-" and not config_path.exists()):
|
||||
msg.fail("Config file not found", config_path, exits=1)
|
||||
if output_path is not None and not output_path.exists():
|
||||
output_path.mkdir(parents=True)
|
||||
|
|
|
@ -465,18 +465,24 @@ def load_config(
|
|||
) -> Config:
|
||||
"""Load a config file. Takes care of path validation and section order.
|
||||
|
||||
path (Union[str, Path]): Path to the config file.
|
||||
path (Union[str, Path]): Path to the config file or "-" to read from stdin.
|
||||
overrides: (Dict[str, Any]): Config overrides as nested dict or
|
||||
dict keyed by section values in dot notation.
|
||||
interpolate (bool): Whether to interpolate and resolve variables.
|
||||
RETURNS (Config): The loaded config.
|
||||
"""
|
||||
config_path = ensure_path(path)
|
||||
if not config_path.exists() or not config_path.is_file():
|
||||
raise IOError(Errors.E053.format(path=config_path, name="config.cfg"))
|
||||
return Config(section_order=CONFIG_SECTION_ORDER).from_disk(
|
||||
config_path, overrides=overrides, interpolate=interpolate
|
||||
)
|
||||
config = Config(section_order=CONFIG_SECTION_ORDER)
|
||||
if str(config_path) == "-": # read from standard input
|
||||
return config.from_str(
|
||||
sys.stdin.read(), overrides=overrides, interpolate=interpolate
|
||||
)
|
||||
else:
|
||||
if not config_path or not config_path.exists() or not config_path.is_file():
|
||||
raise IOError(Errors.E053.format(path=config_path, name="config.cfg"))
|
||||
return config.from_disk(
|
||||
config_path, overrides=overrides, interpolate=interpolate
|
||||
)
|
||||
|
||||
|
||||
def load_config_from_str(
|
||||
|
|
Loading…
Reference in New Issue