Skip to content

Commit 6f69bdb

Browse files
authored
Initial commit
0 parents  commit 6f69bdb

13 files changed

Lines changed: 824 additions & 0 deletions

File tree

.github/rename.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Check if the correct number of arguments is provided
4+
if [ "$#" -ne 2 ]; then
5+
echo "Usage: $0 <search_string> <replace_string>"
6+
exit 1
7+
fi
8+
9+
search_string=$1
10+
replace_string=$2
11+
12+
# Replace string in filenames
13+
git ls-files | grep "$search_string" | while read -r file; do
14+
new_file=$(echo "$file" | sed "s/$search_string/$replace_string/g")
15+
mkdir -p $(dirname $new_file)
16+
git mv "$file" "$new_file"
17+
done
18+
19+
# Replace string in file contents
20+
git ls-files | xargs -I {} sed -i "s/$search_string/$replace_string/g" {}
21+
22+
echo "Replacement completed"

.github/workflows/pre-commit.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Pre-Commit Checks
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
pre-commit:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
name: Checkout code
12+
- uses: actions/setup-python@v3
13+
name: Setup Python
14+
- uses: pre-commit/action@v3.0.0
15+
name: Run Pre-Commit Checks

.github/workflows/rename.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Rename Module Repo
2+
3+
# Only run when the new module is created
4+
on: [create, workflow_dispatch]
5+
6+
jobs:
7+
rename:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
with:
12+
# by default, it uses a depth of 1
13+
# this fetches all history so that we can read each commit
14+
fetch-depth: 0
15+
ref: ${{ github.head_ref }}
16+
17+
- run: |
18+
replacement_string="$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | tr '-' '_' | tr '[:upper:]' '[:lower:]')"
19+
replacement_string="${replacement_string%_module}"
20+
.github/rename.sh python_template "$replacement_string"
21+
22+
- uses: stefanzweifel/git-auto-commit-action@v4
23+
with:
24+
commit_message: "Renamed module"
25+
push_options: --force
26+
file_pattern: . :!.github # Don't modify the workflow

.gitignore

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110+
.pdm.toml
111+
.pdm-python
112+
.pdm-build/
113+
114+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115+
__pypackages__/
116+
117+
# Celery stuff
118+
celerybeat-schedule
119+
celerybeat.pid
120+
121+
# SageMath parsed files
122+
*.sage.py
123+
124+
# Environments
125+
.env
126+
.venv
127+
env/
128+
venv/
129+
ENV/
130+
env.bak/
131+
venv.bak/
132+
133+
# Spyder project settings
134+
.spyderproject
135+
.spyproject
136+
137+
# Rope project settings
138+
.ropeproject
139+
140+
# mkdocs documentation
141+
/site
142+
143+
# mypy
144+
.mypy_cache/
145+
.dmypy.json
146+
dmypy.json
147+
148+
# Pyre type checker
149+
.pyre/
150+
151+
# pytype static type analyzer
152+
.pytype/
153+
154+
# Cython debug symbols
155+
cython_debug/
156+
157+
# PyCharm
158+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160+
# and can be added to the global gitignore or merged into this file. For a more nuclear
161+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162+
#.idea/

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-yaml
6+
- id: check-json
7+
- id: check-toml
8+
- id: check-ast
9+
- id: check-merge-conflict
10+
- id: check-added-large-files
11+
- id: mixed-line-ending
12+
- id: end-of-file-fixer
13+
- id: trailing-whitespace
14+
- repo: https://github.com/kynan/nbstripout
15+
rev: 0.7.1
16+
hooks:
17+
- id: nbstripout
18+
- repo: https://github.com/astral-sh/ruff-pre-commit
19+
# Ruff version.
20+
rev: v0.6.9
21+
hooks:
22+
# Run the linter.
23+
- id: ruff
24+
args: [--fix]
25+
# Run the formatter.
26+
- id: ruff-format

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM ghcr.io/ad-sdl/wei
2+
3+
# TODO: update labels, if neccessary
4+
LABEL org.opencontainers.image.source=https://github.com/AD-SDL/python_template_module
5+
LABEL org.opencontainers.image.description="A template python module that demonstrates basic WEI module functionality."
6+
LABEL org.opencontainers.image.licenses=MIT
7+
8+
#########################################
9+
# Module specific logic goes below here #
10+
#########################################
11+
12+
RUN mkdir -p python_template_module
13+
14+
COPY ./src python_template_module/src
15+
COPY ./README.md python_template_module/README.md
16+
COPY ./pyproject.toml python_template_module/pyproject.toml
17+
18+
RUN --mount=type=cache,target=/root/.cache \
19+
pip install ./python_template_module
20+
21+
# TODO: Add any device-specific container configuration/setup here
22+
23+
CMD ["python", "python_template_module.py"]
24+
25+
#########################################

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Self Driving Laboratories @ Argonne
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# python_template_module
2+
3+
A template module, implemented in python, for integrating a device into a WEI workcell.
4+
5+
## Using This Template
6+
7+
[Creating a Repository From a Template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)
8+
9+
10+
## Renaming
11+
12+
To automatically replace `python_template` with the name of your instrument, run the "Rename Module Repo" GitHub Actions Workflow in your repository: [Manually Running a Workflow](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow)
13+
14+
N.B. this assumes your repository is named using the `<instrument_name>_module` format.
15+
16+
Alternatively, you can run `.github/rename.sh python_template <new_name>` locally and commit the results.
17+
18+
## TODO's
19+
20+
Throughout this module template, there are a number of comments marked `TODO`. You can use search/find and replace to help ensure you're taking full advantage of the module template and don't have any residual template artifacts hanging around.
21+
22+
## Guide to Writing Your Own Module
23+
24+
For more details on how to write your own module (either using this template or from scratch), see [How-To: Modules (WEI Docs)](https://rpl-wei.readthedocs.io/en/latest/pages/how-to/module.html)

compose.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: python_template_module
2+
services:
3+
python_template_module:
4+
container_name: python_template_module
5+
image: ghcr.io/ad-sdl/python_template_module
6+
build:
7+
context: .
8+
tags:
9+
- ghcr.io/ad-sdl/python_template_module:latest
10+
- ghcr.io/ad-sdl/python_template_module:dev
11+
volumes:
12+
- ./src:/home/app/python_template_module/src
13+
- ./tests:/home/app/python_template_module/tests
14+
command: python -m python_template_module --port 2000
15+
ports:
16+
- 2000:2000
17+
#####################
18+
# WEI Core Services #
19+
#####################
20+
python_template_wei_server:
21+
image: ghcr.io/ad-sdl/wei
22+
container_name: python_template_wei_server
23+
ports:
24+
- 8000:8000
25+
environment:
26+
- PYTHONUNBUFFERED=1 # Fix weird bug with empty logging
27+
- USER_ID=${USER_ID:-1000}
28+
- GROUP_ID=${GROUP_ID:-1000}
29+
volumes:
30+
- ./workcells:/workcells
31+
command: python3 -m wei.server --workcell /workcells/test.workcell.yaml
32+
depends_on:
33+
- python_template_wei_redis
34+
python_template_wei_redis:
35+
image: redis
36+
container_name: python_template_wei_redis
37+
ports:
38+
- 6379:6379
39+
command: redis-server --save 60 1 --loglevel warning

0 commit comments

Comments
 (0)