Skip to content
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
71 changes: 71 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Docker Image Build and Publish

on:
push: # * Run for every push
branches: [ "*" ]
tags: [ '*' ]
schedule: # Run on Tuesday's at 12:00
- cron: '0 12 * * 2'
workflow_dispatch: # Run manually

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build_and_publish:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}

# Build and push Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
20 changes: 20 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Pre-Commit Checks

on:
push: # Run for every push
branches: ["*"]
tags: ["*"]
workflow_dispatch: # Run manually

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout code
- uses: actions/setup-python@v4
name: Setup Python
with:
python-version: 3.9
- uses: pre-commit/action@v3.0.1
name: Run Pre-Commit Checks
28 changes: 28 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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
@OSTYPE="" . .venv/bin/activate
@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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: nbstripout
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.9
rev: v0.11.5
hooks:
# Run the linter.
- id: ruff
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM ghcr.io/ad-sdl/madsci

LABEL org.opencontainers.image.source=https://github.com/AD-SDL/hudson_platecrane_module
LABEL org.opencontainers.image.description="Drivers and REST API's for the Hudson Platecrane and Sciclops robots"
LABEL org.opencontainers.image.licenses=MIT

#########################################
# Module specific logic goes below here #
#########################################

RUN apt update && apt install -y libusb-1.0-0-dev && rm -rf /var/lib/apt/lists/*

RUN mkdir -p sciclops_module

COPY ./src sciclops_module/src
COPY ./README.md sciclops_module/README.md
COPY ./pyproject.toml sciclops_module/pyproject.toml

RUN --mount=type=cache,target=/root/.cache \
pip install -e ./sciclops_module

RUN usermod -aG dialout madsci

CMD ["python", "-,", "sciclops_rest_node"]
#########################################
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# sciclops_module
A MADSci node module for interfacing with the Hudson Robotics Sciclops Platecrane

A MADSci Node module for interfacing with the Hudson Robotics Sciclops Platecrane.

## Installation and Usage

### Python

```bash
# Create a virtual environment named .venv
python -m venv .venv
# Activate the virtual environment on Linux or macOS
source .venv/bin/activate
# Alternatively, activate the virtual environment on Windows
# .venv\Scripts\activate
# Install the module and dependencies in the venv
pip install .
# Run the environment
python -m sciclops_rest_node --host 127.0.0.1 --port 2000
```

### Docker

- We provide a `Dockerfile` and example docker compose file (`compose.yaml`) to run this node dockerized.
- There is also a pre-built image available as `ghcr.io/ad-sdl/sciclops_module`.
- You can control the container user's id and group id by setting the `USER_ID` and `GROUP_ID`
16 changes: 16 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: sciclops_node
services:
sciclops:
container_name: sciclops
image: ghcr.io/ad-sdl/sciclops_module
build:
context: .
dockerfile: Dockerfile
tags:
- ghcr.io/ad-sdl/sciclops_module:latest
- ghcr.io/ad-sdl/sciclops_module:dev
command: python -m sciclops_rest_node
privileged: true
network_mode: host
volumes:
- ./definitions:/home/madsci/definitions
144 changes: 144 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
[project]
name = "hudson_platecrane_module"
version = "1.5.0"
description = "Driver for the Platecrane and Sciclops"
authors = [
{name = "Ryan D. Lewis", email="ryan.lewis@anl.gov"},
{name = "Rafael Vescovi", email="ravescovi@anl.gov"},
{name = "Doga Ozgulbas", email="dozgulbas@anl.gov"},
{name = "Abe Stroka", email="astroka@anl.gov"},
{name = "Kyle Hippe", email = "khippe@anl.gov"},
{name = "Tobias Ginsburg", email = "tginsburg@anl.gov"},
]
dependencies = [
"fastapi>=0.103",
"uvicorn>=0.14.0",
"pyusb",
"libusb",
"pyserial",
"madsci.node_module>=0.1.9",
"pydantic>=2.7",
"pytest"
]
requires-python = ">=3.9.1"
readme = "README.md"
license = {text = "MIT"}

[project.urls]
homepage = "https://github.com/AD-SDL/sciclops_module"

######################
# Build Info + Tools #
######################
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

#####################
# Development Tools #
#####################

[tool.ruff]
# https://docs.astral.sh/ruff/configuration/

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"docs",
]

# Same as Black.
line-length = 88
indent-width = 4

# Assume Python 3.8
target-version = "py38"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
# "UP",
# flake8-bugbear
"B",
# flake8-simplify
# "SIM",
# isort
"I",
# Warning
"W",
# pydocstyle
"D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107",
# ruff
# "RUF"
]
ignore = [
"E501" # Line too long
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

[tool.pytest.ini_options]
# https://docs.pytest.org/en/stable/customize.html
addopts = "-x"
junit_family="xunit1"
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::pottery.exceptions.InefficientAccessWarning",
]
markers = [
"hardware: marks test as requiring hardware (deselect with '-m \"not hardware\"')",
]

[tool.mypy]
# https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml
show_error_codes = true
check_untyped_defs = true
follow_imports = "normal"
strict_optional = true
plugins = ["pydantic.mypy"]
strict = true
disallow_untyped_defs = true
implicit_reexport = true
Loading