@@ -84,7 +84,7 @@ def make_simple(
84
84
port : typing .Optional [int ] = None ,
85
85
set_replication : bool = False ,
86
86
ptrack_enable : bool = False ,
87
- initdb_params : T_LIST_STR = [] ,
87
+ initdb_params : typing . Optional [ T_LIST_STR ] = None ,
88
88
pg_options : typing .Optional [T_DICT_STR_STR ] = None ,
89
89
checksum : bool = True ,
90
90
bin_dir : typing .Optional [str ] = None
@@ -93,22 +93,31 @@ def make_simple(
93
93
assert port is None or type (port ) == int # noqa: E721
94
94
assert type (set_replication ) == bool # noqa: E721
95
95
assert type (ptrack_enable ) == bool # noqa: E721
96
- assert type (initdb_params ) == list # noqa: E721
96
+ assert initdb_params is None or type (initdb_params ) == list # noqa: E721
97
97
assert pg_options is None or type (pg_options ) == dict # noqa: E721
98
98
assert type (checksum ) == bool # noqa: E721
99
99
assert bin_dir is None or type (bin_dir ) == str # noqa: E721
100
100
101
- if checksum and '--data-checksums' not in initdb_params :
102
- initdb_params .append ('--data-checksums' )
103
-
104
101
node = self .make_empty (
105
102
base_dir ,
106
103
port ,
107
104
bin_dir = bin_dir
108
105
)
109
106
107
+ final_initdb_params = initdb_params
108
+
109
+ if checksum :
110
+ final_initdb_params = __class__ ._paramlist_append_is_not_exist (
111
+ initdb_params ,
112
+ final_initdb_params ,
113
+ '--data-checksums'
114
+ )
115
+ assert final_initdb_params is not initdb_params
116
+ assert final_initdb_params is not None
117
+ assert '--data-checksums' in final_initdb_params
118
+
110
119
node .init (
111
- initdb_params = initdb_params ,
120
+ initdb_params = final_initdb_params ,
112
121
allow_streaming = set_replication
113
122
)
114
123
@@ -150,7 +159,7 @@ def make_simple(
150
159
151
160
# Apply given parameters
152
161
if pg_options is not None :
153
- assert type (pg_options ) == dict
162
+ assert type (pg_options ) == dict # noqa: E721
154
163
for option_name , option_value in pg_options .items ():
155
164
options [option_name ] = option_value
156
165
@@ -169,6 +178,56 @@ def make_simple(
169
178
170
179
return node
171
180
181
+ @staticmethod
182
+ def _paramlist_has_param (
183
+ params : typing .Optional [T_LIST_STR ],
184
+ param : str
185
+ ) -> bool :
186
+ assert type (param ) == str # noqa: E721
187
+
188
+ if params is None :
189
+ return False
190
+
191
+ assert type (params ) == list # noqa: E721
192
+
193
+ if param in params :
194
+ return True
195
+
196
+ return False
197
+
198
+ @staticmethod
199
+ def _paramlist_append (
200
+ user_params : typing .Optional [T_LIST_STR ],
201
+ updated_params : typing .Optional [T_LIST_STR ],
202
+ param : str ,
203
+ ) -> T_LIST_STR :
204
+ assert user_params is None or type (user_params ) == list # noqa: E721
205
+ assert updated_params is None or type (updated_params ) == list # noqa: E721
206
+ assert type (param ) == str # noqa: E721
207
+
208
+ if updated_params is None :
209
+ if user_params is None :
210
+ return [param ]
211
+
212
+ return [* user_params , param ]
213
+
214
+ assert updated_params is not None
215
+ if updated_params is user_params :
216
+ return [* user_params , param ]
217
+
218
+ updated_params .append (param )
219
+ return updated_params
220
+
221
+ @staticmethod
222
+ def _paramlist_append_is_not_exist (
223
+ user_params : typing .Optional [T_LIST_STR ],
224
+ updated_params : typing .Optional [T_LIST_STR ],
225
+ param : str ,
226
+ ) -> typing .Optional [T_LIST_STR ]:
227
+ if __class__ ._paramlist_has_param (updated_params , param ):
228
+ return updated_params
229
+ return __class__ ._paramlist_append (user_params , updated_params , param )
230
+
172
231
@staticmethod
173
232
def _gettempdir_for_socket () -> str :
174
233
platform_system_name = platform .system ().lower ()
0 commit comments