Skip to content
Open
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
21 changes: 10 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ name: Pytest Unit Tests
on: [push]

jobs:
build_and_test:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: Checkout code
- name: Test makefile
run: make init .env
- name: Check .env file
run: cat .env
- name: Create paths
run: make paths
- name: Initialize, Build, and Test with Docker
run: make test
shell: bash
- uses: actions/setup-python@v5
name: Setup Python
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -e . pytest httpx
- name: Run tests
run: pytest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.pdm-python
.vscode/
33 changes: 33 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# List available commands
default:
@just --list --justfile {{justfile()}}

# initialize the project
init:
@which pdm || echo "pdm not found, you'll need to install it: https://github.com/pdm-project/pdm"
@pdm install -G:all
@test -e .env || cp example.env .env
@which pre-commit && pre-commit install && pre-commit autoupdate || true

# Build the project
build: init dcb

# Run the pre-commit checks
checks:
@pre-commit run --all-files || { echo "Checking fixes\n" ; pre-commit run --all-files; }
check: checks

# Run automated tests
test:
@pytest
tests: test
pytest: test

# Build docker image
dcb:
@docker compose build

# Start the node in docker
up:
@test -e .env || cp example.env .env
@docker compose up
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ghcr.io/ad-sdl/wei
FROM ghcr.io/ad-sdl/madsci:v0.8.0

LABEL org.opencontainers.image.source=https://github.com/AD-SDL/kla_module
LABEL org.opencontainers.image.description="Drivers and REST API's for the KLA devices"
LABEL org.opencontainers.image.description="Drivers and MADSci REST node for KLA devices"
LABEL org.opencontainers.image.licenses=MIT

#########################################
Expand All @@ -13,12 +13,9 @@ RUN mkdir -p kla_module
COPY ./src kla_module/src
COPY ./README.md kla_module/README.md
COPY ./pyproject.toml kla_module/pyproject.toml
COPY ./tests kla_module/tests

# RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y

RUN --mount=type=cache,target=/root/.cache \
pip install -e ./kla_module
uv pip install --python ${MADSCI_VENV}/bin/python -e ./kla_module

CMD ["python", "kla_module/src/kla_rest_node.py"]

Expand Down
30 changes: 0 additions & 30 deletions Makefile

This file was deleted.

48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# kla_module
A repository for KLA REST Node

A [MADSci](https://github.com/AD-SDL/MADSci) node module for controlling a KLA Nanomechanics instrument through its HTTP control server.

## Actions

| Action | Arguments | Description |
| --------------- | --------------------------------------------- | --------------------------------------------------------------- |
| `load_protocol` | `protocol_files: list[str]`, `message: str?` | Load protocol files and move the stage to the sample load position |
| `run_protocol` | `protocol_files: list[str]`, `message: str?` | Run a batch of protocol (`.NMPROJ`) files |
| `check_status` | none | Query whether a sample run is in progress |

`protocol_files` are paths on the KLA control PC, e.g. `C:\Users\Public\Documents\Nanomechanics\Profiles\Default\Make Indents.NMPROJ`.

## Configuration

Settings come from CLI flags, environment variables (prefixed `NODE_`), or a `.env` file:

| Setting | Env var | Default |
| ----------------- | ---------------------- | ----------------------- |
| `kla_url` | `NODE_KLA_URL` | `http://127.0.0.1:8080` |
| `request_timeout` | `NODE_REQUEST_TIMEOUT` | `30.0` |
| `node_name` | `NODE_NAME` | `kla_node` |
| `node_url` | `NODE_URL` | `http://127.0.0.1:2000` |

## Running

With Docker:

```bash
cp example.env .env # then edit KLA_URL / NODE_URL
docker compose up --build
```

Locally:

```bash
pdm install -G:all
python src/kla_rest_node.py --kla_url http://<kla-pc>:8080 --node_url http://0.0.0.0:3015
```

## Development

```bash
just init # install deps and pre-commit hooks
just test # run unit tests (no hardware needed)
just checks # run pre-commit
```
17 changes: 8 additions & 9 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ name: kla_module
services:
kla_module:
container_name: kla_module
image: ${IMAGE}
image: ghcr.io/ad-sdl/kla_module
network_mode: host
build:
context: .
dockerfile: Dockerfile
tags:
- ${IMAGE}:latest
- ${IMAGE}:dev
command: python -m kla_rest_node --port 3015 --kla_url ${KLA_URL}
- ghcr.io/ad-sdl/kla_module:latest
- ghcr.io/ad-sdl/kla_module:dev
env_file: .env
volumes:
- ./src:/home/app/kla_module/src
- ./tests:/home/app/kla_module/tests
ports:
- 3015:3015
environment:
- USER_ID=${USER_ID:-1000}
- GROUP_ID=${GROUP_ID:-1000}
command: python -m kla_rest_node --kla_url ${KLA_URL:-http://127.0.0.1:8080}
15 changes: 7 additions & 8 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Note: all paths are relative to the docker compose file
KLA_URL="http://127.0.0.1:8080"
PROJECT_PATH=
WEI_DATA_DIR=~/.wei
WORKCELL_FILENAME=test_workcell.yaml
WORKCELLS_DIR=${PROJECT_PATH}/tests/workcell_defs
IMAGE=ghcr.io/ad-sdl/kla_module
REDIS_DIR=~/.wei/redis
# Copy to .env and adjust for your setup
# URL of the KLA control server running on the instrument PC
KLA_URL=http://127.0.0.1:8080
# MADSci node identity and the URL this node serves on
NODE_NAME=kla
NODE_MODULE_NAME=kla_module
NODE_URL=http://127.0.0.1:3015
29 changes: 18 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "kla_module"
version = "0.2.0"
description = "Software for automatting a KLA robot"
version = "1.0.0"
description = "Software for automating a KLA robot"
authors = [
{name = "Ryan D. Lewis", email="ryan.lewis@anl.gov"},
{name = "Rafael Vescovi", email="ravescovi@anl.gov"},
Expand All @@ -11,15 +11,13 @@ authors = [
{name = "Tobias Ginsburg", email = "tginsburg@anl.gov"},
]
dependencies = [
"ad_sdl.wei>=0.5.3",
"fastapi>=0.103.2",
"uvicorn>=0.21.1",
"pytest",
"madsci.node_module~=0.8.0",
"madsci.client~=0.8.0",
"madsci.common~=0.8.0",
"requests",

]

requires-python = ">=3.8.1"
requires-python = ">=3.10"
readme = "README.md"
license = {text = "MIT"}

Expand All @@ -33,6 +31,14 @@ homepage = "https://github.com/AD-SDL/kla_module"
requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"

[dependency-groups]
dev = [
"pre-commit>=4.2.0",
"ruff>=0.11.7",
"pytest",
"httpx",
]

#####################
# Development Tools #
#####################
Expand Down Expand Up @@ -70,8 +76,8 @@ exclude = [
line-length = 88
indent-width = 4

# Assume Python 3.8
target-version = "py38"
# Assume Python 3.10
target-version = "py310"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
Expand Down Expand Up @@ -123,10 +129,11 @@ line-ending = "auto"
[tool.pytest.ini_options]
# https://docs.pytest.org/en/stable/customize.html
addopts = "-x"
testpaths = ["tests"]
pythonpath = ["src"]
junit_family="xunit1"
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::pottery.exceptions.InefficientAccessWarning",
]
markers = [
"hardware: marks test as requiring hardware (deselect with '-m \"not hardware\"')",
Expand Down
1 change: 1 addition & 0 deletions src/kla_driver/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Driver for the KLA Nanomechanics control server."""
Loading
Loading