Skip to content

Commit

Permalink
Update fastcs version
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelldls committed Dec 3, 2024
1 parent 86ea923 commit 3ca6b62
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 64 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ classifiers = [
description = "FastCS support for the ThorLabs MFF (Motorized Filter Flipper)"
dependencies = [
"FastCS",
"typer",
] # Add project dependencies here, e.g. ["click", "numpy"]
dynamic = ["version"]
license.file = "LICENSE"
Expand All @@ -33,7 +32,7 @@ dev = [
]

[project.scripts]
thorlabs-mff-fastcs = "thorlabs_mff_fastcs.__main__:app"
thorlabs-mff-fastcs = "thorlabs_mff_fastcs.__main__:main"

[project.urls]
GitHub = "https://github.com/DiamondLightSource/thorlabs-mff-fastcs"
Expand Down
65 changes: 5 additions & 60 deletions src/thorlabs_mff_fastcs/__main__.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,18 @@
from pathlib import Path

import typer
from fastcs.connections.serial_connection import SerialConnectionSettings
from fastcs import launch

from thorlabs_mff_fastcs.controllers import (
ThorlabsMFF,
ThorlabsMFFSettings,
)

from . import __version__

__all__ = ["main"]


app = typer.Typer()


def version_callback(value: bool):
if value:
typer.echo(__version__)
raise typer.Exit()


@app.callback()
def main(
version: bool | None = typer.Option(
None,
"--version",
callback=version_callback,
is_eager=True,
help="Print the version and exit",
),
):
pass


@app.command()
def ioc(
pv_prefix: str = typer.Argument(..., help="Name of the IOC/service to attach to"),
port: str = typer.Argument(..., help="Serial port to open such as /dev/ttyUSB0"),
baud: int = typer.Option(115200, help="Baud rate"),
output_path: Path = typer.Option( # noqa: B008
Path.cwd(), # noqa: B008
help="folder of local service definition",
exists=True,
file_okay=False,
dir_okay=True,
writable=False,
readable=True,
resolve_path=True,
),
):
"""
Start up the service
"""
from fastcs.backends.epics.backend import EpicsBackend, EpicsGUIOptions

backend = EpicsBackend(get_controller(port, baud), pv_prefix)
backend.create_gui(EpicsGUIOptions(output_path / "index.bob"))
backend.run()


def get_controller(port: str, baud: int) -> ThorlabsMFF:
serial_settings = SerialConnectionSettings(port=port, baud=baud)
settings = ThorlabsMFFSettings(serial_settings)
tcont = ThorlabsMFF(settings)
return tcont
def main() -> None:
"""Argument parser for the CLI."""
launch(ThorlabsMFF)


# test with: python -m thorlabs_mff_fastcs
if __name__ == "__main__":
app()
main()
2 changes: 1 addition & 1 deletion src/thorlabs_mff_fastcs/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any

from fastcs.attributes import AttrR, AttrW
from fastcs.connections.serial_connection import (
from fastcs.connections import (
SerialConnection,
SerialConnectionSettings,
)
Expand Down
5 changes: 4 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import subprocess
import sys

import pytest

from thorlabs_mff_fastcs import __version__


@pytest.skip("FastCS will add version command")
def test_cli_version():
cmd = [sys.executable, "-m", "thorlabs_mff_fastcs", "--version"]
cmd = [sys.executable, "-m", "thorlabs_mff_fastcs", "version"]
assert subprocess.check_output(cmd).decode().strip() == __version__

0 comments on commit 3ca6b62

Please sign in to comment.