diff --git a/python/BUILD.md b/python/BUILD.md index d61aadb..66de0f5 100644 --- a/python/BUILD.md +++ b/python/BUILD.md @@ -14,7 +14,7 @@ Run the following commands to generate a distributable source package: ``` python -m pip install --upgrade build -python -m build --dist +python -m build --sdist ``` ### Why not .whl? diff --git a/python/saleae/automation/manager.py b/python/saleae/automation/manager.py index 1389a8d..9b02a64 100644 --- a/python/saleae/automation/manager.py +++ b/python/saleae/automation/manager.py @@ -314,9 +314,10 @@ def cleanup(): @classmethod def launch(cls, - application_path: Optional[Union[Path, str]] = None, + application_path: Optional[Union[Path, str]] = None, connect_timeout_seconds: Optional[float] = None, - grpc_channel_arguments: Optional[List[Tuple[str, Any]]] = None) -> 'Manager': + grpc_channel_arguments: Optional[List[Tuple[str, Any]]] = None, + port: Optional[int] = None) -> 'Manager': """ Launch the Logic2 application and shut it down when the returned Manager is closed. @@ -324,6 +325,7 @@ def launch(cls, a locally installed copy of Logic2 will be searched for. :param connect_timeout_seconds: See __init__ :param grpc_channel_arguments: See __init__ + :param port: Port to use for the gRPC server. If not specified, 10430 will be used. """ @@ -357,7 +359,10 @@ def fail(reason: str): if not os.path.exists(logic2_bin): fail(f'application path "{application_path}" does not exist') - process = subprocess.Popen([logic2_bin, '--automation', '--automationPort', str(_DEFAULT_GRPC_PORT)], + if port is None: + port = _DEFAULT_GRPC_PORT + + process = subprocess.Popen([logic2_bin, '--automation', '--automationPort', str(port)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) @@ -383,7 +388,7 @@ def fail(reason: str): return cls( address=_DEFAULT_GRPC_ADDRESS, - port=_DEFAULT_GRPC_PORT, + port=port, logic2_process=process, connect_timeout_seconds=connect_timeout_seconds, grpc_channel_arguments=grpc_channel_arguments) diff --git a/python/tests/conftest.py b/python/tests/conftest.py index be1fc48..5cfd351 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -7,6 +7,7 @@ def pytest_addoption(parser): parser.addoption('--use-existing', action='store_true') parser.addoption('--app-path', action='store') + parser.addoption('--port', action='store', type=int) @pytest.fixture def asset_path() -> str: @@ -16,13 +17,15 @@ def asset_path() -> str: @pytest.fixture(scope='session') def manager(request): app_path = request.config.getoption('--app-path') + + port = request.config.getoption('--port') if app_path is not None: - with saleae.automation.Manager.launch(app_path) as mgr: + with saleae.automation.Manager.launch(app_path, port=port) as mgr: yield mgr pass elif request.config.getoption('--use-existing'): - with saleae.automation.Manager.connect(port=10430) as mgr: + with saleae.automation.Manager.connect(port=port) as mgr: yield mgr else: - with saleae.automation.Manager.launch() as mgr: + with saleae.automation.Manager.launch(port=port) as mgr: yield mgr diff --git a/python/tests/load_save_test.py b/python/tests/load_save_test.py index a2a9abe..36dae38 100644 --- a/python/tests/load_save_test.py +++ b/python/tests/load_save_test.py @@ -1,5 +1,4 @@ import os.path -from tkinter import E import saleae.automation