Skip to content

Commit

Permalink
Merge branch 'async' of github.com:C2SM/processing-chain into async
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Jan 16, 2024
2 parents dee4c0e + 4a08212 commit 726be9b
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def __init__(self, casename):
self.set_account()

self.chain_src_dir = Path.cwd()
self.case_path = self.chain_src_dir / 'cases' / casename
self.case_path = self.chain_src_dir / 'cases' / self.casename
self.work_root = self.chain_src_dir / 'work'

# User-defined attributes from config file
self.load_config_file(casename)
self.load_config_file()

# Set case root
self.case_root = self.work_root / self.casename
Expand All @@ -66,17 +66,12 @@ def __init__(self, casename):
# Specific settings based on the node type ('gpu' or 'mc')
self.set_node_info()

def load_config_file(self, casename):
def load_config_file(self):
"""Load configuration settings from a YAML file and set them as attributes.
This method reads the configuration settings from a YAML file located in
the 'cases/casename' directory and sets them as attributes of the instance.
Parameters
----------
casename : str
Name of the folder in 'cases/' where the configuration files are stored.
Returns
-------
Config
Expand All @@ -94,17 +89,17 @@ def load_config_file(self, casename):
existing case directories. The method directly assigns values from the
configuration file to instance attributes for easy access.
"""
cfg_file = Path('cases', casename, 'config.yaml').resolve()
cfg_file = Path('cases', self.casename, 'config.yaml').resolve()

if not cfg_file.is_file():
all_cases = [
path.name for path in os.scandir('cases') if path.is_dir()
]
closest_name = min([(tools.levenshtein(casename, name), name)
closest_name = min([(tools.levenshtein(self.casename, name), name)
for name in all_cases],
key=lambda x: x[0])[1]
raise FileNotFoundError(
f"Case-directory '{casename}' not found, did you mean '{closest_name}'?"
f"Case-directory '{self.casename}' not found, did you mean '{closest_name}'?"
)

try:
Expand All @@ -118,11 +113,6 @@ def load_config_file(self, casename):
for key, value in cfg_data.items():
setattr(self, key, value)

# rename the workflow attribute to avoid name clash
self.workflow_name = self.workflow

return self

def set_account(self):
"""Set the compute account based on user information.
Expand Down Expand Up @@ -193,6 +183,7 @@ def set_workflow(self):
"""set workflow and async attr, initiate job ids dict"""
# If a workflow name is specified, load from workflows.yaml
if isinstance(self.workflow, str):
self.workflow_name = self.workflow
with open('workflows.yaml') as file:
workflows = yaml.safe_load(file)
self.workflow = workflows[self.workflow_name]
Expand Down

0 comments on commit 726be9b

Please sign in to comment.