Skip to content

Commit

Permalink
Extract common code paths in constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Sep 25, 2024
1 parent 7b9066b commit e581b2e
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,34 +158,56 @@ def from_file(cls, user_config_file: str) -> Self:
when the user should be notified with non-fatal configuration problems.
"""
user_config_contents = read_file(user_config_file)
site_config_dict = cls.read_site_config()
user_config_dict = cls._read_user_config_and_apply_site_config(
user_config_contents, user_config_file, site_config_dict
)
config_dir = path.abspath(path.dirname(user_config_file))
cls._log_config_file(user_config_file, user_config_contents)
site_config_file = site_config_location()
site_config_contents = read_file(site_config_file)
user_config_dict = cls._config_dict_from_contents(
user_config_contents,
site_config_contents,
user_config_file,
site_config_file,
)
cls._log_config_dict(user_config_dict)
cls.apply_config_content_defaults(user_config_dict, config_dir)
return cls.from_dict(user_config_dict)

@classmethod
def from_file_contents(
def _config_dict_from_contents(
cls,
user_config_contents: str,
site_config_contents: str = "QUEUE_SYSTEM LOCAL\n",
) -> Self:
site_config_contents: str,
config_file_name: str,
site_config_name: str,
) -> ConfigDict:
site_config_dict = parse_contents(
site_config_contents,
file_name="site_config.ert",
file_name=site_config_name,
schema=init_site_config_schema(),
)
user_config_dict = cls._read_user_config_and_apply_site_config(
user_config_contents,
"./config.ert",
config_file_name,
site_config_dict,
)
cls.apply_config_content_defaults(user_config_dict, ".")
return cls.from_dict(user_config_dict)
config_dir = path.abspath(path.dirname(config_file_name))
cls.apply_config_content_defaults(user_config_dict, config_dir)
return user_config_dict

@classmethod
def from_file_contents(
cls,
user_config_contents: str,
site_config_contents: str = "QUEUE_SYSTEM LOCAL\n",
config_file_name="./config.ert",
site_config_name="site_config.ert",
) -> Self:
return cls.from_dict(
cls._config_dict_from_contents(
user_config_contents,
site_config_contents,
config_file_name,
site_config_name,
)
)

@classmethod
def from_dict(cls, config_dict) -> Self:
Expand Down

0 comments on commit e581b2e

Please sign in to comment.