From b41d2068ad74ddc19c0f4fab0205acca6bf08f9c Mon Sep 17 00:00:00 2001 From: Hongli Chen Date: Mon, 18 Mar 2024 12:49:10 -0700 Subject: [PATCH] fix: Move the `named_pipe_helper.py` under the folder `adaptor_runtime_client` Signed-off-by: Hongli Chen --- pyproject.toml | 3 ++- .../adaptor_runtime/_background/backend_runner.py | 2 +- .../adaptor_runtime/_background/frontend_runner.py | 2 +- .../_named_pipe/named_pipe_request_handler.py | 2 +- .../adaptor_runtime/_named_pipe/named_pipe_server.py | 6 ++++-- .../application_ipc/_win_adaptor_server.py | 2 +- .../adaptor_runtime_client/named_pipe/__init__.py | 1 + .../named_pipe/named_pipe_config.py} | 0 .../named_pipe}/named_pipe_helper.py | 2 +- .../adaptor_runtime_client/win_client_interface.py | 2 +- .../integ/_named_pipe/test_named_pipe_helper.py | 2 +- .../application_ipc/test_integration_adaptor_ipc.py | 2 +- .../unit/named_pipe/test_named_pipe_helper.py | 10 ++++++---- 13 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 src/openjd/adaptor_runtime_client/named_pipe/__init__.py rename src/openjd/{adaptor_runtime/_background/server_config.py => adaptor_runtime_client/named_pipe/named_pipe_config.py} (100%) rename src/openjd/{adaptor_runtime/_named_pipe => adaptor_runtime_client/named_pipe}/named_pipe_helper.py (99%) diff --git a/pyproject.toml b/pyproject.toml index 3d66b43..9baa13d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -139,7 +139,8 @@ source = [ "src/openjd/adaptor_runtime/_named_pipe/*.py", "src/openjd/adaptor_runtime/application_ipc/_win_adaptor_server.py", "src/openjd/adaptor_runtime/application_ipc/_named_pipe_request_handler.py", - "src/openjd/adaptor_runtime_client/win_client_interface.py" + "src/openjd/adaptor_runtime_client/win_client_interface.py", + "src/openjd/adaptor_runtime_client/named_pipe/*.py" ] # Source files to exclude from coverage on Windows "sys_platform == 'win32'" = [ diff --git a/src/openjd/adaptor_runtime/_background/backend_runner.py b/src/openjd/adaptor_runtime/_background/backend_runner.py index bf09554..674cb3d 100644 --- a/src/openjd/adaptor_runtime/_background/backend_runner.py +++ b/src/openjd/adaptor_runtime/_background/backend_runner.py @@ -19,7 +19,7 @@ if OSName.is_posix(): from .http_server import BackgroundHTTPServer if OSName.is_windows(): - from .._named_pipe.named_pipe_helper import NamedPipeHelper + from openjd.adaptor_runtime_client.named_pipe.named_pipe_helper import NamedPipeHelper from .backend_named_pipe_server import WinBackgroundNamedPipeServer from .log_buffers import LogBuffer from .model import ConnectionSettings diff --git a/src/openjd/adaptor_runtime/_background/frontend_runner.py b/src/openjd/adaptor_runtime/_background/frontend_runner.py index 4304858..158bfd0 100644 --- a/src/openjd/adaptor_runtime/_background/frontend_runner.py +++ b/src/openjd/adaptor_runtime/_background/frontend_runner.py @@ -31,7 +31,7 @@ ) if OSName.is_windows(): - from openjd.adaptor_runtime._named_pipe.named_pipe_helper import NamedPipeHelper + from openjd.adaptor_runtime_client.named_pipe.named_pipe_helper import NamedPipeHelper import pywintypes _logger = logging.getLogger(__name__) diff --git a/src/openjd/adaptor_runtime/_named_pipe/named_pipe_request_handler.py b/src/openjd/adaptor_runtime/_named_pipe/named_pipe_request_handler.py index 59be4c8..c22399d 100644 --- a/src/openjd/adaptor_runtime/_named_pipe/named_pipe_request_handler.py +++ b/src/openjd/adaptor_runtime/_named_pipe/named_pipe_request_handler.py @@ -6,7 +6,7 @@ if TYPE_CHECKING: # pragma: no cover because pytest will think we should test for this. from openjd.adaptor_runtime._named_pipe import NamedPipeServer -from openjd.adaptor_runtime._named_pipe.named_pipe_helper import ( +from openjd.adaptor_runtime_client.named_pipe.named_pipe_helper import ( NamedPipeHelper, PipeDisconnectedException, ) diff --git a/src/openjd/adaptor_runtime/_named_pipe/named_pipe_server.py b/src/openjd/adaptor_runtime/_named_pipe/named_pipe_server.py index a23174c..4a93079 100644 --- a/src/openjd/adaptor_runtime/_named_pipe/named_pipe_server.py +++ b/src/openjd/adaptor_runtime/_named_pipe/named_pipe_server.py @@ -8,10 +8,12 @@ from typing import List -from openjd.adaptor_runtime._background.server_config import DEFAULT_NAMED_PIPE_TIMEOUT_MILLISECONDS +from openjd.adaptor_runtime_client.named_pipe.named_pipe_config import ( + DEFAULT_NAMED_PIPE_TIMEOUT_MILLISECONDS, +) from typing import TYPE_CHECKING -from openjd.adaptor_runtime._named_pipe.named_pipe_helper import ( +from openjd.adaptor_runtime_client.named_pipe.named_pipe_helper import ( NamedPipeHelper, NamedPipeTimeoutError, ) diff --git a/src/openjd/adaptor_runtime/application_ipc/_win_adaptor_server.py b/src/openjd/adaptor_runtime/application_ipc/_win_adaptor_server.py index d467e75..4aaebdc 100644 --- a/src/openjd/adaptor_runtime/application_ipc/_win_adaptor_server.py +++ b/src/openjd/adaptor_runtime/application_ipc/_win_adaptor_server.py @@ -7,7 +7,7 @@ from ._named_pipe_request_handler import WinAdaptorServerResourceRequestHandler from .._named_pipe import ResourceRequestHandler -from .._named_pipe.named_pipe_helper import NamedPipeHelper +from openjd.adaptor_runtime_client.named_pipe.named_pipe_helper import NamedPipeHelper from .._named_pipe.named_pipe_server import NamedPipeServer diff --git a/src/openjd/adaptor_runtime_client/named_pipe/__init__.py b/src/openjd/adaptor_runtime_client/named_pipe/__init__.py new file mode 100644 index 0000000..8d929cc --- /dev/null +++ b/src/openjd/adaptor_runtime_client/named_pipe/__init__.py @@ -0,0 +1 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/src/openjd/adaptor_runtime/_background/server_config.py b/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_config.py similarity index 100% rename from src/openjd/adaptor_runtime/_background/server_config.py rename to src/openjd/adaptor_runtime_client/named_pipe/named_pipe_config.py diff --git a/src/openjd/adaptor_runtime/_named_pipe/named_pipe_helper.py b/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_helper.py similarity index 99% rename from src/openjd/adaptor_runtime/_named_pipe/named_pipe_helper.py rename to src/openjd/adaptor_runtime_client/named_pipe/named_pipe_helper.py index 41bbfc1..8795077 100644 --- a/src/openjd/adaptor_runtime/_named_pipe/named_pipe_helper.py +++ b/src/openjd/adaptor_runtime_client/named_pipe/named_pipe_helper.py @@ -19,7 +19,7 @@ import os -from openjd.adaptor_runtime._background.server_config import ( +from openjd.adaptor_runtime_client.named_pipe.named_pipe_config import ( NAMED_PIPE_BUFFER_SIZE, DEFAULT_MAX_NAMED_PIPE_INSTANCES, ) diff --git a/src/openjd/adaptor_runtime_client/win_client_interface.py b/src/openjd/adaptor_runtime_client/win_client_interface.py index eb129c5..9b37572 100644 --- a/src/openjd/adaptor_runtime_client/win_client_interface.py +++ b/src/openjd/adaptor_runtime_client/win_client_interface.py @@ -12,7 +12,7 @@ # TODO: We need to remove this relative import, since it won't work with how # we inject this module into DCCs. Likely by copying the function # NamedPipeHelper.send_named_pipe_request into this adaptor_runtime_client namespace. -from ..adaptor_runtime._named_pipe.named_pipe_helper import NamedPipeHelper +from openjd.adaptor_runtime_client.named_pipe.named_pipe_helper import NamedPipeHelper _DEFAULT_TIMEOUT_IN_SECONDS = 15 diff --git a/test/openjd/adaptor_runtime/integ/_named_pipe/test_named_pipe_helper.py b/test/openjd/adaptor_runtime/integ/_named_pipe/test_named_pipe_helper.py index 3454707..84dcba9 100644 --- a/test/openjd/adaptor_runtime/integ/_named_pipe/test_named_pipe_helper.py +++ b/test/openjd/adaptor_runtime/integ/_named_pipe/test_named_pipe_helper.py @@ -13,7 +13,7 @@ import win32pipe import win32security import win32api - from openjd.adaptor_runtime._named_pipe.named_pipe_helper import NamedPipeHelper + from openjd.adaptor_runtime_client.named_pipe.named_pipe_helper import NamedPipeHelper else: # Cannot put this on the top of this file or mypy will complain pytest.mark.skip(reason="NamedPipe is only implemented in Windows.") diff --git a/test/openjd/adaptor_runtime/integ/application_ipc/test_integration_adaptor_ipc.py b/test/openjd/adaptor_runtime/integ/application_ipc/test_integration_adaptor_ipc.py index 6a46479..f021dea 100644 --- a/test/openjd/adaptor_runtime/integ/application_ipc/test_integration_adaptor_ipc.py +++ b/test/openjd/adaptor_runtime/integ/application_ipc/test_integration_adaptor_ipc.py @@ -16,7 +16,7 @@ from openjd.adaptor_runtime.application_ipc import AdaptorServer as _AdaptorServer if OSName.is_windows(): - from openjd.adaptor_runtime._named_pipe.named_pipe_helper import NamedPipeHelper + from openjd.adaptor_runtime_client.named_pipe.named_pipe_helper import NamedPipeHelper @pytest.fixture diff --git a/test/openjd/adaptor_runtime/unit/named_pipe/test_named_pipe_helper.py b/test/openjd/adaptor_runtime/unit/named_pipe/test_named_pipe_helper.py index a0b9a6f..d2afae0 100644 --- a/test/openjd/adaptor_runtime/unit/named_pipe/test_named_pipe_helper.py +++ b/test/openjd/adaptor_runtime/unit/named_pipe/test_named_pipe_helper.py @@ -10,7 +10,9 @@ win32pipe = pytest.importorskip("win32pipe") win32file = pytest.importorskip("win32file") winerror = pytest.importorskip("winerror") -named_pipe_helper = pytest.importorskip("openjd.adaptor_runtime._named_pipe.named_pipe_helper") +named_pipe_helper = pytest.importorskip( + "openjd.adaptor_runtime_client.named_pipe.named_pipe_helper" +) class MockReadFile: @@ -70,7 +72,7 @@ def test_read_from_pipe_timeout_raises_exception(self, mock_win32file): @patch("os.getpid", return_value=1) @patch( - "openjd.adaptor_runtime._named_pipe.named_pipe_helper.NamedPipeHelper.check_named_pipe_exists", + "openjd.adaptor_runtime_client.named_pipe.named_pipe_helper.NamedPipeHelper.check_named_pipe_exists", return_value=False, ) def test_generate_pipe_name(self, mock_check_named_pipe_exists, mock_getpid): @@ -79,7 +81,7 @@ def test_generate_pipe_name(self, mock_check_named_pipe_exists, mock_getpid): @patch("os.getpid", return_value=1) @patch( - "openjd.adaptor_runtime._named_pipe.named_pipe_helper.NamedPipeHelper.check_named_pipe_exists", + "openjd.adaptor_runtime_client.named_pipe.named_pipe_helper.NamedPipeHelper.check_named_pipe_exists", side_effect=[True, False], ) def test_generate_pipe_name2(self, mock_check_named_pipe_exists, mock_getpid): @@ -89,7 +91,7 @@ def test_generate_pipe_name2(self, mock_check_named_pipe_exists, mock_getpid): @patch("os.getpid", return_value=1) @patch( - "openjd.adaptor_runtime._named_pipe.named_pipe_helper.NamedPipeHelper.check_named_pipe_exists", + "openjd.adaptor_runtime_client.named_pipe.named_pipe_helper.NamedPipeHelper.check_named_pipe_exists", return_value=True, ) def test_failed_to_generate_pipe_name(self, mock_check_named_pipe_exists, mock_getpid):