1313
1414class GlobalConfig (object ):
1515 """
16- Global config (override default settings).
17-
18- Attributes:
19- cache_initdb: shall we use cached initdb instance?
20- cached_initdb_dir: shall we create a temp dir for cached initdb?
21- cached_initdb_unique: shall we assign new node a unique system id?
22-
23- cache_pg_config: shall we cache pg_config results?
24-
25- temp_dir: base temp dir for nodes with default 'base_dir'.
26-
27- use_python_logging: use python logging configuration for all nodes.
28- error_log_lines: N of log lines to be shown in exception (0=inf).
29-
30- node_cleanup_full: shall we remove EVERYTHING (including logs)?
31- node_cleanup_on_good_exit: remove base_dir on nominal __exit__().
32- node_cleanup_on_bad_exit: remove base_dir on __exit__() via exception.
33-
34- NOTE: attributes must not be callable or begin with __.
16+ Global configuration object which allows user to override default settings.
3517 """
18+ # NOTE: attributes must not be callable or begin with __.
3619
3720 cache_initdb = True
38- _cached_initdb_dir = None
21+ """ shall we use cached initdb instance? """
22+
3923 cached_initdb_unique = False
24+ """ shall we give new node a unique system id? """
4025
4126 cache_pg_config = True
27+ """ shall we cache pg_config results? """
4228
4329 use_python_logging = False
30+ """ enable python logging subsystem (see logger.py). """
31+
4432 error_log_lines = 20
33+ """ N of log lines to be shown in exceptions (0=inf). """
4534
4635 node_cleanup_full = True
36+ """ shall we remove EVERYTHING (including logs)? """
37+
4738 node_cleanup_on_good_exit = True
39+ """ remove base_dir on nominal __exit__(). """
40+
4841 node_cleanup_on_bad_exit = False
42+ """ remove base_dir on __exit__() via exception. """
43+
44+ _cached_initdb_dir = None
45+ """ underlying class attribute for cached_initdb_dir property """
4946
5047 @property
5148 def cached_initdb_dir (self ):
49+ """ path to a temp directory for cached initdb. """
5250 return self ._cached_initdb_dir
5351
5452 @cached_initdb_dir .setter
@@ -60,6 +58,7 @@ def cached_initdb_dir(self, value):
6058
6159 @property
6260 def temp_dir (self ):
61+ """ path to temp dir containing nodes with default 'base_dir'. """
6362 return tempfile .tempdir
6463
6564 @temp_dir .setter
@@ -82,6 +81,10 @@ def __setattr__(self, name, value):
8281 super (GlobalConfig , self ).__setattr__ (name , value )
8382
8483 def keys (self ):
84+ """
85+ Return a list of all available settings.
86+ """
87+
8588 keys = []
8689
8790 for key in dir (GlobalConfig ):
@@ -91,15 +94,29 @@ def keys(self):
9194 return keys
9295
9396 def items (self ):
97+ """
98+ Return setting-value pairs.
99+ """
100+
94101 return ((key , self [key ]) for key in self .keys ())
95102
96103 def update (self , config ):
104+ """
105+ Extract setting-value pairs from 'config' and
106+ assign those values to corresponding settings
107+ of this GlobalConfig object.
108+ """
109+
97110 for key , value in config .items ():
98111 self [key ] = value
99112
100113 return self
101114
102115 def copy (self ):
116+ """
117+ Return a copy of this object.
118+ """
119+
103120 return copy .copy (self )
104121
105122
@@ -124,8 +141,8 @@ def _rm_cached_initdb_dirs():
124141
125142def push_config (** options ):
126143 """
127- Permanently set custom GlobalConfig options
128- and put previous settings on top of stack.
144+ Permanently set custom GlobalConfig options and
145+ put previous settings on top of the config stack.
129146 """
130147
131148 # push current config to stack
@@ -150,10 +167,12 @@ def pop_config():
150167def scoped_config (** options ):
151168 """
152169 Temporarily set custom GlobalConfig options for this context.
170+ Previous options are pushed to the config stack.
153171
154172 Example:
155173 >>> from .api import get_new_node
156174 >>> with scoped_config(cache_initdb=False):
175+ ... # create a new node with fresh initdb
157176 ... with get_new_node().init().start() as node:
158177 ... print(node.execute('select 1'))
159178 [(1,)]
@@ -173,7 +192,7 @@ def scoped_config(**options):
173192def configure_testgres (** options ):
174193 """
175194 Adjust current global options.
176- Look at GlobalConfig to learn what can be set .
195+ Look at the GlobalConfig to learn about existing settings .
177196 """
178197
179198 testgres_config .update (options )
0 commit comments