Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move the named_pipe_helper.py under the folder adaptor_runtime_client #87

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ source = [
"src/openjd/adaptor_runtime/_named_pipe/*.py",
epmog marked this conversation as resolved.
Show resolved Hide resolved
"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'" = [
Expand Down
2 changes: 1 addition & 1 deletion src/openjd/adaptor_runtime/_background/backend_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)

if OSName.is_windows():
from openjd.adaptor_runtime._named_pipe.named_pipe_helper import NamedPipeHelper
from ...adaptor_runtime_client.named_pipe.named_pipe_helper import NamedPipeHelper
import pywintypes

_logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...adaptor_runtime_client.named_pipe.named_pipe_helper import (
NamedPipeHelper,
PipeDisconnectedException,
)
Expand Down
10 changes: 6 additions & 4 deletions src/openjd/adaptor_runtime/_named_pipe/named_pipe_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@

from typing import List

from openjd.adaptor_runtime._background.server_config import DEFAULT_NAMED_PIPE_TIMEOUT_MILLISECONDS
from ...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 ...adaptor_runtime_client.named_pipe.named_pipe_helper import (
NamedPipeHelper,
NamedPipeTimeoutError,
)

if TYPE_CHECKING:
from openjd.adaptor_runtime._named_pipe import ResourceRequestHandler
from openjd.adaptor_runtime._osname import OSName
from .._named_pipe import ResourceRequestHandler
from .._osname import OSName

import win32pipe
import win32file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...adaptor_runtime_client.named_pipe.named_pipe_helper import NamedPipeHelper
from .._named_pipe.named_pipe_server import NamedPipeServer


Expand Down
1 change: 1 addition & 0 deletions src/openjd/adaptor_runtime_client/named_pipe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os


from openjd.adaptor_runtime._background.server_config import (
from .named_pipe_config import (
NAMED_PIPE_BUFFER_SIZE,
DEFAULT_MAX_NAMED_PIPE_INSTANCES,
)
Expand Down
5 changes: 1 addition & 4 deletions src/openjd/adaptor_runtime_client/win_client_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

from .base_client_interface import BaseClientInterface

# 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 .named_pipe.named_pipe_helper import NamedPipeHelper

_DEFAULT_TIMEOUT_IN_SECONDS = 15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down