33import docker
44import logging
55from localstack_utils .container import Container
6- from localstack_utils .localstack_docker_configuration import LocalstackDockerConfiguration
6+ from localstack_utils .localstack_docker_configuration import (
7+ LocalstackDockerConfiguration ,
8+ )
79from localstack_utils .localstack_logger import LocalstackLogger
810
911ENV_CONFIG_USE_SSL = "USE_SSL"
1214TMP_PATH = "/tmp/localstack"
1315READY_TOKEN = re .compile ("Ready\\ ." )
1416DEFAULT_EDGE_PORT = 4566
15- PORT_CONFIG_FILENAME = "/opt/code/localstack/.venv/lib/python3.8/site-packages/localstack_client/config.py"
17+ PORT_CONFIG_FILENAME = (
18+ "/opt/code/localstack/.venv/lib/python3.8/site-packages/localstack_client/config.py"
19+ )
1620# DEFAULT_PORT_PATTERN = re.compile("'(\\w+)'\\Q: '{proto}://{host}:\\E(\\d+)'")
1721
1822localstack_instance = None
19- logging .basicConfig (level = logging .INFO , format = '%(message)s' )
23+ logging .basicConfig (level = logging .INFO , format = "%(message)s" )
24+
2025
2126class Localstack :
22-
2327 localstack_container = None
2428 service_to_map = {}
2529 locked = False
@@ -28,9 +32,9 @@ class Localstack:
2832 def INSTANCE ():
2933 return Localstack ()
3034
31- external_hostName = ''
35+ external_hostName = ""
3236
33- def startup (self , docker_configuration ) :
37+ def startup (self , docker_configuration ):
3438 if self .locked :
3539 raise Exception ("A docker instance is starting or already started." )
3640 self .locked = True
@@ -48,42 +52,42 @@ def startup(self, docker_configuration) :
4852 docker_configuration .environment_variables ,
4953 docker_configuration .port_mappings ,
5054 docker_configuration .bind_mounts ,
51- docker_configuration .platform
55+ docker_configuration .platform ,
5256 )
5357
5458 self .setup_logger ()
5559
5660 Container .waitForReady (self .localstack_container , READY_TOKEN )
5761
58- except docker .errors .APIError as error :
62+ except docker .errors .APIError :
5963 if not docker_configuration .ignore_docker_runerrors :
6064 raise "Unable to start docker"
6165
62- except :
66+ except Exception :
6367 raise sys .exc_info ()
6468
65-
6669 def stop (self ):
6770 self .localstack_container .stop ()
6871
69-
7072 def setup_logger (self ):
7173 localstack_logger = LocalstackLogger (self .localstack_container )
7274 localstack_logger .start ()
7375
74- def startup_localstack (port = 4566 , services = [], ignore_docker_errors = False ):
76+
77+ def startup_localstack (port = 4566 , services = [], ignore_docker_errors = False ):
7578 global localstack_instance
7679 localstack_instance = Localstack .INSTANCE ()
7780 config = LocalstackDockerConfiguration ()
7881
7982 if len (services ):
80- config .envirement_variables .update ({' SERVICES' : ',' .join (services )})
83+ config .envirement_variables .update ({" SERVICES" : "," .join (services )})
8184 if port != 4566 :
8285 config .port_edge = str (port )
8386 config .ignore_docker_runerrors = ignore_docker_errors
8487
8588 localstack_instance .startup (config )
8689
90+
8791def stop_localstack ():
8892 if localstack_instance :
8993 localstack_instance .stop ()
0 commit comments