diff --git a/localstack-core/localstack/dev/debugger/__init__.py b/localstack-core/localstack/dev/debugger/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/localstack-core/localstack/dev/debugger/plugins.py b/localstack-core/localstack/dev/debugger/plugins.py new file mode 100644 index 0000000000000..aa1d163f57b85 --- /dev/null +++ b/localstack-core/localstack/dev/debugger/plugins.py @@ -0,0 +1,25 @@ +import logging + +from localstack import config, constants +from localstack.runtime import hooks + +LOG = logging.getLogger(__name__) + + +def enable_debugger(): + from localstack.packages.debugpy import debugpy_package + + debugpy_package.install() + import debugpy # noqa: T100 + + LOG.info("Starting debug server at: %s:%s", constants.BIND_HOST, config.DEVELOP_PORT) + debugpy.listen((constants.BIND_HOST, config.DEVELOP_PORT)) # noqa: T100 + + if config.WAIT_FOR_DEBUGGER: + debugpy.wait_for_client() # noqa: T100 + + +@hooks.on_infra_start() +def conditionally_enable_debugger(): + if config.DEVELOP: + enable_debugger() diff --git a/localstack-core/localstack/dev/run/configurators.py b/localstack-core/localstack/dev/run/configurators.py index 8b1b585e3ae50..08cba9ae0b4fa 100644 --- a/localstack-core/localstack/dev/run/configurators.py +++ b/localstack-core/localstack/dev/run/configurators.py @@ -124,7 +124,7 @@ def __init__( def __call__(self, cfg: ContainerConfiguration): # localstack source code if available - source = self.host_paths.localstack_project_dir / "localstack-core" / "localstack" + source = self.host_paths.aws_community_package_dir if source.exists(): cfg.volumes.add( # read_only=False is a temporary workaround to make the mounting of the pro source work @@ -134,13 +134,7 @@ def __call__(self, cfg: ContainerConfiguration): # ext source code if available if self.pro: - source = ( - self.host_paths.localstack_pro_project_dir - / "localstack-pro-core" - / "localstack" - / "pro" - / "core" - ) + source = self.host_paths.aws_pro_package_dir if source.exists(): cfg.volumes.add( VolumeBind( @@ -220,11 +214,7 @@ def __init__( def __call__(self, cfg: ContainerConfiguration): # special case for community code if not self.pro: - host_path = ( - self.host_paths.localstack_project_dir - / "localstack_core.egg-info" - / "entry_points.txt" - ) + host_path = self.host_paths.aws_community_package_dir if host_path.exists(): cfg.volumes.append( VolumeBind( @@ -243,6 +233,38 @@ def __call__(self, cfg: ContainerConfiguration): dep_path = container_path.parent.name.removesuffix(".dist-info") dep, ver = dep_path.split("-") + if dep == "localstack_core": + host_path = ( + self.host_paths.localstack_project_dir + / "localstack-core" + / "localstack_core.egg-info" + / "entry_points.txt" + ) + if host_path.is_file(): + cfg.volumes.add( + VolumeBind( + str(host_path), + str(container_path), + read_only=True, + ) + ) + continue + elif dep == "localstack_ext": + host_path = ( + self.host_paths.localstack_pro_project_dir + / "localstack-pro-core" + / "localstack_ext.egg-info" + / "entry_points.txt" + ) + if host_path.is_file(): + cfg.volumes.add( + VolumeBind( + str(host_path), + str(container_path), + read_only=True, + ) + ) + continue for host_path in self.host_paths.workspace_dir.glob( f"*/{dep}.egg-info/entry_points.txt" ): diff --git a/localstack-core/localstack/dev/run/paths.py b/localstack-core/localstack/dev/run/paths.py index 9689c32c75dbd..8379186c0b3ad 100644 --- a/localstack-core/localstack/dev/run/paths.py +++ b/localstack-core/localstack/dev/run/paths.py @@ -38,6 +38,16 @@ def __init__( or os.path.join(os.getcwd(), ".venv") ) + @property + def aws_community_package_dir(self) -> Path: + return self.localstack_project_dir / "localstack-core" / "localstack" + + @property + def aws_pro_package_dir(self) -> Path: + return ( + self.localstack_pro_project_dir / "localstack-pro-core" / "localstack" / "pro" / "core" + ) + class ContainerPaths: """Important paths in the container"""