From 6a7f1752aa8305376259ae562997648554ae7376 Mon Sep 17 00:00:00 2001 From: DavidNew-NOAA Date: Fri, 7 Jun 2024 08:44:11 -0500 Subject: [PATCH 1/8] Initial commit --- src/wxflow/task.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index ee8712b..78166f2 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -30,7 +30,7 @@ def __init__(self, config: Dict, *args, **kwargs): """ # Store the config and arguments as attributes of the object - self.config = AttrDict(config) + self._config = AttrDict(config) for arg in args: setattr(self, str(arg), arg) @@ -39,13 +39,13 @@ def __init__(self, config: Dict, *args, **kwargs): setattr(self, key, value) # Pull out basic runtime keys values from config into its own runtime config - self.runtime_config = AttrDict() + self._runtime_config = AttrDict() runtime_keys = ['PDY', 'cyc', 'DATA', 'RUN', 'CDUMP'] # TODO: eliminate CDUMP and use RUN instead for kk in runtime_keys: try: - self.runtime_config[kk] = config[kk] + self._runtime_config[kk] = config[kk] logger.debug(f'Deleting runtime_key {kk} from config') - del self.config[kk] + del self._config[kk] except KeyError: raise KeyError(f"Encountered an unreferenced runtime_key {kk} in 'config'") @@ -53,12 +53,16 @@ def __init__(self, config: Dict, *args, **kwargs): # can be constructed here # Construct the current cycle datetime object - self.runtime_config['current_cycle'] = add_to_datetime(self.runtime_config['PDY'], to_timedelta(f"{self.runtime_config.cyc}H")) - logger.debug(f"current cycle: {self.runtime_config['current_cycle']}") + self._runtime_config['current_cycle'] = add_to_datetime(self._runtime_config['PDY'], to_timedelta(f"{self._runtime_config.cyc}H")) + logger.debug(f"current cycle: {self._runtime_config['current_cycle']}") # Construct the previous cycle datetime object - self.runtime_config['previous_cycle'] = add_to_datetime(self.runtime_config.current_cycle, -to_timedelta(f"{self.config['assim_freq']}H")) - logger.debug(f"previous cycle: {self.runtime_config['previous_cycle']}") + self._runtime_config['previous_cycle'] = add_to_datetime(self._runtime_config.current_cycle, -to_timedelta(f"{self._config['assim_freq']}H")) + logger.debug(f"previous cycle: {self._runtime_config['previous_cycle']}") + + # Create task_config which combines the contents of config and runtime_config. + # Only task_config should be accessed from this point on. + self.task_config = AttrDict(**self._config, **self._runtime_config pass From ec0bdc9081e31dab16e3e4724e186f65271b2d3e Mon Sep 17 00:00:00 2001 From: DavidNew-NOAA Date: Fri, 7 Jun 2024 12:41:48 -0500 Subject: [PATCH 2/8] Forgot a parenthesis --- src/wxflow/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index 78166f2..a7eebc2 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -62,7 +62,7 @@ def __init__(self, config: Dict, *args, **kwargs): # Create task_config which combines the contents of config and runtime_config. # Only task_config should be accessed from this point on. - self.task_config = AttrDict(**self._config, **self._runtime_config + self.task_config = AttrDict(**self._config, **self._runtime_config) pass From c62196fb2ae8885724e052ff0676b70d811670ea Mon Sep 17 00:00:00 2001 From: DavidNew-NOAA Date: Fri, 7 Jun 2024 12:53:41 -0500 Subject: [PATCH 3/8] Coding norms --- src/wxflow/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index a7eebc2..bfecb89 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -60,7 +60,7 @@ def __init__(self, config: Dict, *args, **kwargs): self._runtime_config['previous_cycle'] = add_to_datetime(self._runtime_config.current_cycle, -to_timedelta(f"{self._config['assim_freq']}H")) logger.debug(f"previous cycle: {self._runtime_config['previous_cycle']}") - # Create task_config which combines the contents of config and runtime_config. + # Create task_config which combines the contents of config and runtime_config. # Only task_config should be accessed from this point on. self.task_config = AttrDict(**self._config, **self._runtime_config) From 0a7d200d88c178440da7afd4722027eefdef27b4 Mon Sep 17 00:00:00 2001 From: DavidNew-NOAA Date: Fri, 7 Jun 2024 14:03:21 -0500 Subject: [PATCH 4/8] Eliminated _runtime_config based on feedback from Rahul --- src/wxflow/task.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index bfecb89..fb2297f 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -38,12 +38,15 @@ def __init__(self, config: Dict, *args, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) - # Pull out basic runtime keys values from config into its own runtime config - self._runtime_config = AttrDict() + # Create task_config with everything that is inside _config and whatever the user chooses to + # extend it with when initializing a child subclass of Task. Only task_config should be referenced + # in any application, not _config. + self.task_config = self._config.copy + + # Pull out basic runtime keys values from config into its own runti runtime_keys = ['PDY', 'cyc', 'DATA', 'RUN', 'CDUMP'] # TODO: eliminate CDUMP and use RUN instead for kk in runtime_keys: try: - self._runtime_config[kk] = config[kk] logger.debug(f'Deleting runtime_key {kk} from config') del self._config[kk] except KeyError: @@ -53,16 +56,12 @@ def __init__(self, config: Dict, *args, **kwargs): # can be constructed here # Construct the current cycle datetime object - self._runtime_config['current_cycle'] = add_to_datetime(self._runtime_config['PDY'], to_timedelta(f"{self._runtime_config.cyc}H")) - logger.debug(f"current cycle: {self._runtime_config['current_cycle']}") + self.task_config['current_cycle'] = add_to_datetime(self.task_config['PDY'], to_timedelta(f"{self.task_config.cyc}H")) + logger.debug(f"current cycle: {self.task_config['current_cycle']}") # Construct the previous cycle datetime object - self._runtime_config['previous_cycle'] = add_to_datetime(self._runtime_config.current_cycle, -to_timedelta(f"{self._config['assim_freq']}H")) - logger.debug(f"previous cycle: {self._runtime_config['previous_cycle']}") - - # Create task_config which combines the contents of config and runtime_config. - # Only task_config should be accessed from this point on. - self.task_config = AttrDict(**self._config, **self._runtime_config) + self.task_config['previous_cycle'] = add_to_datetime(self.task_config.current_cycle, -to_timedelta(f"{self._config['assim_freq']}H")) + logger.debug(f"previous cycle: {self.task_config['previous_cycle']}") pass From 2fae77d2154a3878fe35d4d896267cf9e6c4b761 Mon Sep 17 00:00:00 2001 From: DavidNew-NOAA Date: Fri, 7 Jun 2024 14:08:43 -0500 Subject: [PATCH 5/8] Coding norms --- src/wxflow/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index fb2297f..26bdb98 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -38,7 +38,7 @@ def __init__(self, config: Dict, *args, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) - # Create task_config with everything that is inside _config and whatever the user chooses to + # Create task_config with everything that is inside _config and whatever the user chooses to # extend it with when initializing a child subclass of Task. Only task_config should be referenced # in any application, not _config. self.task_config = self._config.copy From 1bd96b51d3cca5ce1de81411bbf884d576877b30 Mon Sep 17 00:00:00 2001 From: DavidNew-NOAA Date: Fri, 7 Jun 2024 14:27:45 -0500 Subject: [PATCH 6/8] Remove some unnecessary stuff based on more feedback from Rahul --- src/wxflow/task.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index 26bdb98..d7c5166 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -43,15 +43,6 @@ def __init__(self, config: Dict, *args, **kwargs): # in any application, not _config. self.task_config = self._config.copy - # Pull out basic runtime keys values from config into its own runti - runtime_keys = ['PDY', 'cyc', 'DATA', 'RUN', 'CDUMP'] # TODO: eliminate CDUMP and use RUN instead - for kk in runtime_keys: - try: - logger.debug(f'Deleting runtime_key {kk} from config') - del self._config[kk] - except KeyError: - raise KeyError(f"Encountered an unreferenced runtime_key {kk} in 'config'") - # Any other composite runtime variables that may be needed for the duration of the task # can be constructed here From d68b1edde2192a3aa40d27ab494139c1e3b49345 Mon Sep 17 00:00:00 2001 From: DavidNew-NOAA Date: Fri, 7 Jun 2024 14:43:33 -0500 Subject: [PATCH 7/8] Forgot parenthesis --- src/wxflow/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index d7c5166..81863f0 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -41,7 +41,7 @@ def __init__(self, config: Dict, *args, **kwargs): # Create task_config with everything that is inside _config and whatever the user chooses to # extend it with when initializing a child subclass of Task. Only task_config should be referenced # in any application, not _config. - self.task_config = self._config.copy + self.task_config = self._config.copy() # Any other composite runtime variables that may be needed for the duration of the task # can be constructed here From c710e9fb888b20f39a6a7e4be7ab6355e7f8db0b Mon Sep 17 00:00:00 2001 From: Rahul Mahajan Date: Fri, 7 Jun 2024 17:23:04 -0400 Subject: [PATCH 8/8] Update src/wxflow/task.py --- src/wxflow/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wxflow/task.py b/src/wxflow/task.py index 81863f0..80ef4a2 100644 --- a/src/wxflow/task.py +++ b/src/wxflow/task.py @@ -47,7 +47,7 @@ def __init__(self, config: Dict, *args, **kwargs): # can be constructed here # Construct the current cycle datetime object - self.task_config['current_cycle'] = add_to_datetime(self.task_config['PDY'], to_timedelta(f"{self.task_config.cyc}H")) + self.task_config['current_cycle'] = add_to_datetime(self._config['PDY'], to_timedelta(f"{self._config.cyc}H")) logger.debug(f"current cycle: {self.task_config['current_cycle']}") # Construct the previous cycle datetime object