mirror of
https://github.com/tiennm99/serena.git
synced 2026-09-03 12:22:04 +00:00
Config handling: autogenerate project.yml when path to project was entered manually
We should not assume that a project is not available just if the project.yml is missing, since a user might have added a path manually without creating the project.yml
This commit is contained in:
+11
-2
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user