From d4f74e7b2685bc314bf80c6855678b391282ecf6 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Tue, 30 Jul 2024 11:59:23 +0100 Subject: [PATCH 1/5] fix: use correct community entrypoints path --- localstack-core/localstack/dev/run/configurators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/localstack-core/localstack/dev/run/configurators.py b/localstack-core/localstack/dev/run/configurators.py index 8b1b585e3ae50..42182321dc5ca 100644 --- a/localstack-core/localstack/dev/run/configurators.py +++ b/localstack-core/localstack/dev/run/configurators.py @@ -222,6 +222,7 @@ def __call__(self, cfg: ContainerConfiguration): if not self.pro: host_path = ( self.host_paths.localstack_project_dir + / "localstack-core" / "localstack_core.egg-info" / "entry_points.txt" ) From 8ab6ebafc8ff32075ab66cdb179a49d0bf98d1ab Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Tue, 30 Jul 2024 12:01:04 +0100 Subject: [PATCH 2/5] fix: add `DEVELOP` mode as plugin --- .../localstack/debugger/__init__.py | 0 .../localstack/debugger/plugins.py | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 localstack-core/localstack/debugger/__init__.py create mode 100644 localstack-core/localstack/debugger/plugins.py diff --git a/localstack-core/localstack/debugger/__init__.py b/localstack-core/localstack/debugger/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/localstack-core/localstack/debugger/plugins.py b/localstack-core/localstack/debugger/plugins.py new file mode 100644 index 0000000000000..aa1d163f57b85 --- /dev/null +++ b/localstack-core/localstack/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() From 2ee1128826d886de89b2cc78aeb3f084aa11f290 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Tue, 30 Jul 2024 12:12:05 +0100 Subject: [PATCH 3/5] chore: add convenience properties for accessing source paths on the host --- .../localstack/dev/run/configurators.py | 17 +++-------------- localstack-core/localstack/dev/run/paths.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/localstack-core/localstack/dev/run/configurators.py b/localstack-core/localstack/dev/run/configurators.py index 42182321dc5ca..ae624285289cc 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,12 +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" - / "localstack_core.egg-info" - / "entry_points.txt" - ) + host_path = self.host_paths.aws_community_package_dir if host_path.exists(): cfg.volumes.append( VolumeBind( 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""" From 71f71ed14e194274031af5117b26e6a79b495898 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Tue, 30 Jul 2024 17:10:50 +0100 Subject: [PATCH 4/5] Implement handling of community/ext entrypoints files --- .../localstack/dev/run/configurators.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/localstack-core/localstack/dev/run/configurators.py b/localstack-core/localstack/dev/run/configurators.py index ae624285289cc..08cba9ae0b4fa 100644 --- a/localstack-core/localstack/dev/run/configurators.py +++ b/localstack-core/localstack/dev/run/configurators.py @@ -233,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" ): From 3b8db0b9462cb4ff6a5c3f1dbf7bc56252861690 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Tue, 30 Jul 2024 21:10:13 +0100 Subject: [PATCH 5/5] chore: move debugger plugin to localstack.dev package --- localstack-core/localstack/{ => dev}/debugger/__init__.py | 0 localstack-core/localstack/{ => dev}/debugger/plugins.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename localstack-core/localstack/{ => dev}/debugger/__init__.py (100%) rename localstack-core/localstack/{ => dev}/debugger/plugins.py (100%) diff --git a/localstack-core/localstack/debugger/__init__.py b/localstack-core/localstack/dev/debugger/__init__.py similarity index 100% rename from localstack-core/localstack/debugger/__init__.py rename to localstack-core/localstack/dev/debugger/__init__.py diff --git a/localstack-core/localstack/debugger/plugins.py b/localstack-core/localstack/dev/debugger/plugins.py similarity index 100% rename from localstack-core/localstack/debugger/plugins.py rename to localstack-core/localstack/dev/debugger/plugins.py