diff --git a/src/serena/agent.py b/src/serena/agent.py index 59b98f1..4c50174 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -327,10 +327,19 @@ class SerenaConfig(SerenaConfigBase): num_project_migrations = 0 for path in loaded_commented_yaml["projects"]: path = Path(path).resolve() - if not path.exists() or (path.is_dir() and not (path / ProjectConfig.rel_path_to_project_yml()).exists()): - log.warning(f"Project path {path} does not exist or does not contain a project configuration file, skipping.") + if not path.exists(): + log.warning(f"Project path {path} does not exist, skipping.") continue + if path.is_dir(): + project_yml_path = path / ProjectConfig.rel_path_to_project_yml() + if not project_yml_path.exists(): + log.info(f"Project path {path} does not contain a project configuration file, creating one.") + ProjectConfig.autogenerate(path, save_to_disk=True) + continue if path.is_file(): + log.info( + f"Project path {path} is a file, migrating to in-project configuration. This is a legacy feature for backwards compatibility." + ) path = cls._migrate_out_of_project_config_file(path) if path is None: continue diff --git a/src/serena/util/general.py b/src/serena/util/general.py index bfddaf4..b350ae1 100644 --- a/src/serena/util/general.py +++ b/src/serena/util/general.py @@ -1,3 +1,4 @@ +import os from typing import Literal, overload from ruamel.yaml import YAML @@ -26,5 +27,6 @@ def load_yaml(path: str, preserve_comments: bool = False) -> dict | CommentedMap def save_yaml(path: str, data: dict | CommentedMap, preserve_comments: bool = False) -> None: yaml = _create_YAML(preserve_comments) + os.makedirs(os.path.dirname(path), exist_ok=True) with open(path, "w", encoding="utf-8") as f: yaml.dump(data, f)