@@ -104,6 +104,21 @@ def __next__(self):
104104 return self ._iter_keys .popleft ()
105105
106106 def __getitem__ (self , key ):
107+ """
108+ Emulates dictionry key get action.
109+
110+ Emulates the act of getting a key in a dictionary structure. Most importantly,
111+ keys in the Config object can receive it's value from one of multiple sources.
112+
113+ The currently supported sources are: manually assigned values, environment variable
114+ values, and hard-coded default values, with priority matching this order.
115+
116+ Args:
117+ key (str): The key name for which to return the value for.
118+
119+ Raises:
120+ KeyError: Given key is not valid for the Config object.
121+ """
107122 detl = self ._attr .get (key )
108123 if not detl :
109124 raise KeyError ('Config object does not store key: {}' .format (key ))
@@ -124,6 +139,20 @@ def __getitem__(self, key):
124139 return None
125140
126141 def __setitem__ (self , key , value ):
142+ """
143+ Emulates dictionry key set action.
144+
145+ Emulates the act of setting a key in a dictionary structure. Additionally,
146+ key names and variable values/types are validated upon set. If invalid key
147+ name or invalid value type, an exception will be thrown.
148+
149+ Args:
150+ key (str): The key name for which to assign the incoming value to.
151+ value (mixed): The value to assign key with.
152+
153+ Raises:
154+ KeyError: Given key is not valid for the Config object.
155+ """
127156 if key not in self ._attr :
128157 raise KeyError ('Config object does not store key: {}' .format (key ))
129158 else :
@@ -140,26 +169,70 @@ def __setitem__(self, key, value):
140169 self ._attr [key ]['value' ] = self ._attr [key ]['type' ](value )
141170
142171 def __delitem__ (self , key ):
172+ """
173+ Emulates dictionry key delete action.
174+
175+ Emulates the act of deleting a key in a dictionary structure.
176+
177+ Args:
178+ key (str): The key name for which to delete the current.
179+
180+ Raises:
181+ KeyError: Given key is not valid for the Config object.
182+ """
143183 if key not in self ._attr :
144184 raise KeyError ('Config object does not store key: {}' .format (key ))
145185 else :
146186 self ._attr [key ]['value' ] = None
147187
148188 def __contains__ (self , key ):
189+ """
190+ Determines if key is stored in the Config object.
191+
192+ Args:
193+ key (str): The key name for which to check for existence.
194+
195+ Returns:
196+ Boolean True/False indicating if key exists in Config.
197+ """
149198 return key in self ._attr
150199
151200 def items (self , only_preserve = True ):
201+ """
202+ Converts the Config object into a simple dictionary containing only simple key:value pairs.
203+
204+ Converts the internal representation of Config object and returns a simple dictionary
205+ containing each key and it's highest priority value currently assigned. Optionally allows
206+ for selection of only key:value pairs marked for preservation, rather than returning
207+ all pairs. By default, only returns preserved pairs.
208+
209+ Preserved pairs aare those designated for persisting into longer term storage in case
210+ of job failure.
211+
212+ Args:
213+ only_preserve (bool, optional): Indicates if only keys marked for preservation
214+ should be returned. Default: True
215+
216+ Returns:
217+ Dictionary containing keys assigned with their highest priority value in Config object.
218+ """
152219 return { k :v ['value' ] for k ,v in self ._attr .items () if v ['preserve' ] }
153220
154221 @property
155222 def ctllog_file (self ):
223+ """
224+ Path/filename of job's .ctllog file.
225+ """
156226 if not self ['temp_dir' ] or not self ['app_name' ]:
157227 return None
158228 else :
159229 return '{}/{}.ctllog' .format (self ['temp_dir' ], self ['app_name' ])
160230
161231 @property
162232 def ctx_file (self ):
233+ """
234+ Path/filename of job's .ctx file.
235+ """
163236 if not self ['temp_dir' ] or not self ['app_name' ]:
164237 return None
165238 else :
@@ -173,6 +246,9 @@ def source_config_file(self, config_file):
173246 prior to executing app/job instance. Only variables beginning with
174247 'APP_' will be preserved/exported, while other vars will be lost.
175248
249+ Args:
250+ config_file (str): The path to the application profile/config to source.
251+
176252 Raises:
177253 FileNotFoundError: Could not find specified file or is not a file.
178254 """
@@ -192,6 +268,9 @@ def source_config_file(self, config_file):
192268 proc .communicate ()
193269
194270 def print_attributes (self ):
271+ """
272+ Prints out the Contig object's key:value pairs, using the highest
273+ priority source as value.
274+ """
195275 for k in self ._attr :
196- print ('{} : {}' .format (k , self ._attr [k ]))
197- return
276+ print ('{} : {}' .format (k , self ._attr [k ]))
0 commit comments