@@ -98,11 +98,13 @@ def parse_arguments():
9898
9999
100100def is_local_file (url ):
101+ """Check if URL points to a local file."""
101102 url_parsed = urlparse (url )
102103 return url_parsed .scheme in ("file" , "" ) and exists (url_parsed .path )
103104
104105
105106def run_command (cmd , timeout = None ):
107+ """Execute command and raise error on failure."""
106108 try :
107109 subprocess .check_output (cmd , env = os .environ , timeout = timeout )
108110 except subprocess .CalledProcessError as ex :
@@ -111,18 +113,21 @@ def run_command(cmd, timeout=None):
111113
112114
113115def run_command_no_fail (cmd , timeout = None ):
116+ """Execute command and ignore failures."""
114117 try :
115118 subprocess .check_output (cmd , env = os .environ , timeout = timeout )
116119 except subprocess .CalledProcessError as ex :
117120 print (ex .output )
118121
119122
120123def run_parallel_commands (cmds ):
124+ """Execute multiple commands in parallel."""
121125 with Pool (processes = len (cmds )) as pool :
122126 pool .map (run_command , cmds )
123127
124128
125129def download_file (download_dir , source_path ):
130+ """Download file from URL to directory."""
126131 filename = os .path .basename (source_path )
127132 target_path = os .path .join (download_dir , filename )
128133
@@ -142,11 +147,13 @@ def download_file(download_dir, source_path):
142147
143148
144149def get_resource_path (relative_path ):
150+ """Get absolute path to resource file."""
145151 base_dir = os .path .dirname (__file__ )
146152 return os .path .join (base_dir , relative_path )
147153
148154
149155def run_psql_query (query , dbname = "postgres" , host = None , port = None , user = None ):
156+ """Execute PostgreSQL query using psql."""
150157 cmd = ["psql" , "-h" , host , "-p" , port , "-U" , user , "-d" , dbname , "-tAc" , query ]
151158 try :
152159 result = subprocess .check_output (cmd , env = os .environ , stderr = subprocess .DEVNULL )
@@ -156,6 +163,7 @@ def run_psql_query(query, dbname="postgres", host=None, port=None, user=None):
156163
157164
158165def create_database (dbname , host , port , user ):
166+ """Create PostgreSQL database if it doesn't exist."""
159167 cmd = [
160168 "psql" ,
161169 "-h" ,
@@ -173,6 +181,7 @@ def create_database(dbname, host, port, user):
173181
174182
175183def enable_extension (extension , dbname , host , port , user , cascade = False ):
184+ """Enable PostgreSQL extension in database."""
176185 cascade_sql = " CASCADE" if cascade else ""
177186 cmd = [
178187 "psql" ,
@@ -191,6 +200,7 @@ def enable_extension(extension, dbname, host, port, user, cascade=False):
191200
192201
193202def setup_database_prerequisites (dbname , host , port , user ):
203+ """Set up database with required extensions."""
194204 if (
195205 run_psql_query (
196206 f"SELECT 1 FROM pg_database WHERE datname='{ dbname } '" ,
0 commit comments