Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move configuration.py to pygw #1153

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env python3

import glob
import os
import random
import glob
import subprocess
from pprint import pprint
from datetime import datetime
from pathlib import Path
from pprint import pprint
from typing import Union, List, Dict, Any

from pygw.attrdict import AttrDict

__all__ = ['Configuration']

Expand Down Expand Up @@ -85,7 +84,7 @@ def parse_config(self, files: Union[str, bytes, list]) -> Dict[str, Any]:
if isinstance(files, (str, bytes)):
files = [files]
files = [self.find_config(file) for file in files]
varbles = dict()
varbles = AttrDict()
for key, value in self._get_script_env(files).items():
if key in self.DATE_ENV_VARS: # likely a date, convert to datetime
varbles[key] = datetime.strptime(value, '%Y%m%d%H')
Expand Down
14 changes: 7 additions & 7 deletions workflow/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from typing import Dict, Any
from datetime import timedelta
from configuration import Configuration
from hosts import Host
from pygw.configuration import Configuration

__all__ = ['AppConfig']

Expand Down Expand Up @@ -78,11 +78,11 @@ class AppConfig:

VALID_MODES = ['cycled', 'forecast-only']

def __init__(self, configuration: Configuration) -> None:
def __init__(self, conf: Configuration) -> None:

self.scheduler = Host().scheduler

_base = configuration.parse_config('config.base')
_base = conf.parse_config('config.base')

self.mode = _base['MODE']

Expand Down Expand Up @@ -134,7 +134,7 @@ def __init__(self, configuration: Configuration) -> None:
self.configs_names = self._get_app_configs()

# Source the config_files for the jobs in the application
self.configs = self._source_configs(configuration)
self.configs = self._source_configs(conf)

# Update the base config dictionary based on application
upd_base_map = {'cycled': self._cycled_upd_base,
Expand Down Expand Up @@ -286,7 +286,7 @@ def _forecast_only_upd_base(base_in):

return base_out

def _source_configs(self, configuration: Configuration) -> Dict[str, Any]:
def _source_configs(self, conf: Configuration) -> Dict[str, Any]:
"""
Given the configuration object and jobs,
source the configurations for each config and return a dictionary
Expand All @@ -296,7 +296,7 @@ def _source_configs(self, configuration: Configuration) -> Dict[str, Any]:
configs = dict()

# Return config.base as well
configs['base'] = configuration.parse_config('config.base')
configs['base'] = conf.parse_config('config.base')

# Source the list of all config_files involved in the application
for config in self.configs_names:
Expand All @@ -316,7 +316,7 @@ def _source_configs(self, configuration: Configuration) -> Dict[str, Any]:
files += [f'config.{config}']

print(f'sourcing config.{config}')
configs[config] = configuration.parse_config(files)
configs[config] = conf.parse_config(files)

return configs

Expand Down
2 changes: 1 addition & 1 deletion workflow/setup_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import os
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter

from configuration import Configuration
from applications import AppConfig
from rocoto.workflow_xml import RocotoXML
from pygw.configuration import Configuration


def input_args():
Expand Down
4 changes: 3 additions & 1 deletion workflow/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from configuration import Configuration
from pygw.configuration import Configuration


expdir = sys.argv[1]
Expand All @@ -18,6 +18,8 @@
print('config.base ...')
base = cfg.parse_config('config.base')
cfg.print_config('config.base')
print(type(base))
print(base.HOMEgfs)

print('*'*80)
print('config.anal...')
Expand Down