@@ -50,7 +50,9 @@ def download_to_local(
5050 data = BytesIO (response .content )
5151 blob .upload_from_file (data , rewind = True )
5252 else :
53- logging .info (f"Blob already exists: gs://{ EMULATOR_STORAGE_BUCKET_NAME } /{ blob_path } " )
53+ logging .info (
54+ f"Blob already exists: gs://{ EMULATOR_STORAGE_BUCKET_NAME } /{ blob_path } "
55+ )
5456
5557
5658@with_db_session
@@ -87,24 +89,29 @@ def setup_local_storage_emulator():
8789 """
8890 from gcp_storage_emulator .server import create_server
8991
90- os .environ ["STORAGE_EMULATOR_HOST" ] = f"http://{ EMULATOR_HOST } :{ EMULATOR_STORAGE_PORT } "
92+ os .environ [
93+ "STORAGE_EMULATOR_HOST"
94+ ] = f"http://{ EMULATOR_HOST } :{ EMULATOR_STORAGE_PORT } "
9195 os .environ ["DATASETS_BUCKET_NAME_GBFS" ] = EMULATOR_STORAGE_BUCKET_NAME
9296 os .environ ["DATASETS_BUCKET_NAME_GTFS" ] = EMULATOR_STORAGE_BUCKET_NAME
9397 os .environ ["DATASTORE_EMULATOR_HOST" ] = "localhost:8081"
9498 server = create_server (
95- host = EMULATOR_HOST , port = EMULATOR_STORAGE_PORT , in_memory = False , default_bucket = EMULATOR_STORAGE_BUCKET_NAME
99+ host = EMULATOR_HOST ,
100+ port = EMULATOR_STORAGE_PORT ,
101+ in_memory = False ,
102+ default_bucket = EMULATOR_STORAGE_BUCKET_NAME ,
96103 )
97104 server .start ()
98105 return server
99106
100107
101108def shutdown_local_storage_emulator (server ):
102- """ Shutdown the Google Cloud Storage emulator."""
109+ """Shutdown the Google Cloud Storage emulator."""
103110 server .stop ()
104111
105112
106113def is_datastore_emulator_running (host = EMULATOR_HOST , port = 8081 ):
107- """ Check if the Google Cloud Datastore emulator is running."""
114+ """Check if the Google Cloud Datastore emulator is running."""
108115 try :
109116 with socket .create_connection ((host , port ), timeout = 2 ):
110117 return True
@@ -113,19 +120,25 @@ def is_datastore_emulator_running(host=EMULATOR_HOST, port=8081):
113120
114121
115122def start_datastore_emulator (project_id = "test-project" ):
116- """ Start the Google Cloud Datastore emulator if it's not already running."""
123+ """Start the Google Cloud Datastore emulator if it's not already running."""
117124 if not is_datastore_emulator_running ():
118- process = subprocess .Popen ([
119- "gcloud" , "beta" , "emulators" , "datastore" , "start" ,
120- "--project={}" .format (project_id ),
121- "--host-port=localhost:8081"
122- ])
125+ process = subprocess .Popen (
126+ [
127+ "gcloud" ,
128+ "beta" ,
129+ "emulators" ,
130+ "datastore" ,
131+ "start" ,
132+ "--project={}" .format (project_id ),
133+ "--host-port=localhost:8081" ,
134+ ]
135+ )
123136 return process
124137 return None # Already running
125138
126139
127140def shutdown_datastore_emulator (process ):
128- """ Shutdown the Google Cloud Datastore emulator."""
141+ """Shutdown the Google Cloud Datastore emulator."""
129142 if process :
130143 process .terminate ()
131- process .wait ()
144+ process .wait ()
0 commit comments