def test_project_config_interpolation_override(greeting): variables = {"a": "world"} commands = [ {"name": "x", "script": ["hello ${vars.a}"]}, ] overrides = {"vars.a": greeting} project = {"commands": commands, "vars": variables} with make_tempdir() as d: srsly.write_yaml(d / "project.yml", project) cfg = load_project_config(d, overrides=overrides) assert type(cfg) == dict assert type(cfg["commands"]) == list assert cfg["commands"][0]["script"][0] == f"hello {greeting}"
def test_project_config_interpolation_env(): variables = {"a": 10} env_var = "SPACY_TEST_FOO" env_vars = {"foo": env_var} commands = [{"name": "x", "script": ["hello ${vars.a} ${env.foo}"]}] project = {"commands": commands, "vars": variables, "env": env_vars} with make_tempdir() as d: srsly.write_yaml(d / "project.yml", project) cfg = load_project_config(d) assert cfg["commands"][0]["script"][0] == "hello 10 " os.environ[env_var] = "123" with make_tempdir() as d: srsly.write_yaml(d / "project.yml", project) cfg = load_project_config(d) assert cfg["commands"][0]["script"][0] == "hello 10 123"
def update_lockfile(project_dir: Path, command: Dict[str, Any]) -> None: """Update the lockfile after running a command. Will create a lockfile if it doesn't yet exist and will add an entry for the current command, its script and dependencies/outputs. project_dir (Path): The current project directory. command (Dict[str, Any]): The command, as defined in the project.yml. """ lock_path = project_dir / PROJECT_LOCK if not lock_path.exists(): srsly.write_yaml(lock_path, {}) data = {} else: data = srsly.read_yaml(lock_path) data[command["name"]] = get_lock_entry(project_dir, command) srsly.write_yaml(lock_path, data)
def test_project_config_interpolation(int_value): variables = {"a": int_value, "b": {"c": "foo", "d": True}} commands = [ {"name": "x", "script": ["hello ${vars.a} ${vars.b.c}"]}, {"name": "y", "script": ["${vars.b.c} ${vars.b.d}"]}, ] project = {"commands": commands, "vars": variables} with make_tempdir() as d: srsly.write_yaml(d / "project.yml", project) cfg = load_project_config(d) assert type(cfg) == dict assert type(cfg["commands"]) == list assert cfg["commands"][0]["script"][0] == "hello 10 foo" assert cfg["commands"][1]["script"][0] == "foo true" commands = [{"name": "x", "script": ["hello ${vars.a} ${vars.b.e}"]}] project = {"commands": commands, "vars": variables} with pytest.raises(ConfigValidationError): substitute_project_variables(project)
{ "name": "delete_temporary_file", "help": "Print listed files (EXAMPLE)", "script": ["rm -f temporaryfile"], "deps": ["temporaryfile"], }, ] project_yaml["commands"] = commands workflow_example = questionary.confirm( "Would you like to add a workflow example?" ).ask() if workflow_example: workflow = {"all": ["make_temporary_file", "delete_temporary_file"]} project_yaml["workflows"] = workflow output_path = Path(project_directory) / "project.yml" srsly.write_yaml(output_path, project_yaml) with output_path.open("a") as output_yaml: output_yaml.write("\n") output_yaml.write( "\n# This project.yml generated with https://github.com/pmbaumgartner/spacy-v3-project-startup" ) output_yaml.write( "\n# For more on spaCy projects, see: https://spacy.io/usage/projects and https://spacy.io/api/cli#project" ) output_yaml.write( "\n# And see the templates at: https://github.com/explosion/projects" ) questionary.print(f"Project yml output to {output_path}.")