Skip to content

Commit 63ebca5

Browse files
gotap integration, data/parameters cleanup
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 60533b7 commit 63ebca5

File tree

7 files changed

+46
-47
lines changed

7 files changed

+46
-47
lines changed

.github/workflows/docker-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
id: meta
4848
uses: docker/metadata-action@v4
4949
with:
50-
images: ghcr.io/vforwater/tbr_template_python
50+
images: ghcr.io/tool-spec/tbr_template_python
5151

5252
- name: Build and push
5353
uses: docker/build-push-action@v3

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ venv.bak/
120120
# mkdocs documentation
121121
/site
122122

123+
# gotap-generated bindings (built during Docker build)
124+
src/parameters.py
125+
out/
126+
123127
# mypy
124128
.mypy_cache/
125129
.dmypy.json

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ keywords:
3434
- docker
3535
- tool-spec
3636
license: CC-BY-4.0
37-
version: '0.6.1'
37+
version: '0.7.0'
3838
date-released: '2026-02-13'

Dockerfile

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1+
# Build gotap from source, then discard Go
2+
FROM golang:1.25-alpine AS gotap-builder
3+
RUN apk add --no-cache git
4+
ARG GOTAP_VERSION=main
5+
RUN git clone --depth 1 --branch ${GOTAP_VERSION} https://github.com/tool-spec/gotap.git /gotap && \
6+
cd /gotap && go build -o gotap .
7+
18
# Pull any base image that includes python3
29
FROM python:3.12
3-
4-
# install the toolbox runner tools
5-
RUN pip install "json2args[data]>=0.6.2"
6-
7-
# if you do not need data-preloading as your tool does that on its own
8-
# you can use this instread of the line above to use a json2args version
9-
# with less dependencies
10-
# RUN pip install json2args>=0.6.2
11-
12-
# Build spec binary from source
13-
RUN apt-get update && apt-get install -y golang-go git && \
14-
git clone https://github.com/hydrocode-de/gotap.git /tmp/gotap && \
15-
cd /tmp/gotap && go build -o /usr/local/bin/spec ./main.go && \
16-
rm -rf /tmp/gotap && \
17-
apt-get remove -y golang-go git && apt-get autoremove -y && apt-get clean
10+
COPY --from=gotap-builder /gotap/gotap /usr/local/bin/gotap
11+
RUN chmod +x /usr/local/bin/gotap
1812

1913
# Do anything you need to install tool dependencies here
2014
RUN echo "Replace this line with a tool"
@@ -26,8 +20,12 @@ RUN mkdir /out
2620
RUN mkdir /src
2721
COPY ./src /src
2822

23+
# Generate parameter bindings from tool.yml at build time (replaces json2args)
24+
WORKDIR /src
25+
RUN gotap generate --spec-file=tool.yml --target=python --output=parameters.py
26+
2927
# copy the citation file - looks funny to make COPY not fail if the file is not there
3028
COPY ./CITATION.cf[f] /src/CITATION.cff
3129

3230
WORKDIR /src
33-
CMD ["spec", "run", "foobar", "--input-file", "/in/input.json"]
31+
CMD ["gotap", "run", "foobar", "--input-file", "/in/input.json"]

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ services:
44
context: .
55
dockerfile: Dockerfile
66
volumes:
7-
- ./src:/src
87
- ./in:/in
98
- ./out:/out
109
environment:
11-
- TOOL_RUN=foobar
12-
command: python run.py
10+
- TOOL_RUN=foobar

in/input.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"foobar": {
3-
"parameters": {
4-
"foo_int": 42,
5-
"foo_float": 13.37,
6-
"foo_string": "Never eat yellow snow",
7-
"foo_enum": "bar",
8-
"foo_array": [34, 55, 23, 43, 23]
9-
},
10-
"data": {
11-
"foo_matrix": "/in/foo_matrix.dat",
12-
"foo_csv": "/in/foo_csv.csv"
13-
}
2+
"foobar": {
3+
"parameters": {
4+
"foo_int": 42,
5+
"foo_float": 13.37,
6+
"foo_string": "Never eat yellow snow",
7+
"foo_enum": "bar",
8+
"foo_array": [34, 55, 23, 43, 23]
9+
},
10+
"data": {
11+
"foo_matrix": "/in/foo_matrix.dat",
12+
"foo_csv": "/in/foo_csv.csv"
1413
}
14+
}
1515
}

src/run.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import logging
12
import os
23
from datetime import datetime as dt
34

4-
from json2args import get_parameter
5-
from json2args.data import get_data
6-
from json2args.logger import logger
5+
from parameters import get_parameters, get_data
76

8-
# parse parameters
9-
kwargs = get_parameter()
10-
data = get_data(as_dict=True)
7+
logging.basicConfig(level=logging.INFO)
8+
logger = logging.getLogger(__name__)
9+
10+
# parse parameters (generated by gotap at container build time)
11+
params = get_parameters()
12+
data = get_data()
1113

1214
# check if a toolname was set in env
1315
toolname = os.environ.get('TOOL_RUN', 'foobar').lower()
@@ -16,14 +18,11 @@
1618
if toolname == 'foobar':
1719
# RUN the tool here and create the output in /out
1820
logger.info('This toolbox does not include any tool. Did you run the template?\n')
19-
20-
# write parameters to STDOUT.log
21-
logger.info(kwargs)
22-
23-
for name, ds in data.items():
24-
logger.info(f"\n### {name}")
25-
logger.info(ds)
26-
21+
22+
logger.info(vars(params))
23+
24+
for name, path in data.items():
25+
logger.info(f"\n### {name}: %s", path)
2726

2827
# In any other case, it was not clear which tool to run
2928
else:

0 commit comments

Comments
 (0)