Skip to content

Commit

Permalink
Merge pull request #25 from saleae/feature/custom-port-for-launch
Browse files Browse the repository at this point in the history
Custom port for launch
  • Loading branch information
huffman authored Jul 14, 2023
2 parents 8003d9f + a6185d9 commit b646825
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion python/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
13 changes: 9 additions & 4 deletions python/saleae/automation/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,18 @@ 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.
:param application_path: The path to the Logic2 binary to run. If not specified,
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.
"""

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
1 change: 0 additions & 1 deletion python/tests/load_save_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os.path
from tkinter import E

import saleae.automation

Expand Down

0 comments on commit b646825

Please sign in to comment.