Skip to content

Commit

Permalink
🎊
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Aug 26, 2022
1 parent 455b243 commit 97d7692
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
docker.io/${{ steps.determine.outputs.dock_image }}
ghcr.io/${{ steps.determine.outputs.dock_image }}
# if non-x86_84 architectures are supported, add them here
platforms: linux/amd64 #,linux/arm64,linux/ppc64le
platforms: linux/amd64,linux/arm64,linux/ppc64le
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
Expand Down
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Python version can be changed, e.g.
# FROM python:3.8
# FROM docker.io/fnndsc/conda:python3.10.2-cuda11.6.0
FROM docker.io/python:3.10.6-slim-bullseye
FROM docker.io/fnndsc/mni-conda-base:civet2.1.1-python3.10.6

LABEL org.opencontainers.image.authors="FNNDSC <[email protected]>" \
org.opencontainers.image.title="create_tetra" \
Expand Down
91 changes: 4 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# create_tetra
# pl-create_tetra

[![Version](https://img.shields.io/docker/v/fnndsc/pl-create_tetra?sort=semver)](https://hub.docker.com/r/fnndsc/pl-create_tetra)
[![MIT License](https://img.shields.io/github/license/fnndsc/pl-create_tetra)](https://github.com/FNNDSC/pl-create_tetra/blob/main/LICENSE)
[![ci](https://github.com/FNNDSC/pl-create_tetra/actions/workflows/ci.yml/badge.svg)](https://github.com/FNNDSC/pl-create_tetra/actions/workflows/ci.yml)

`pl-create_tetra` is a [_ChRIS_](https://chrisproject.org/)
_ds_ plugin which takes in ... as input files and
creates ... as output files.

## Abstract

...
*fs*-type plugin wrapper around `create_tetra`.

## Installation

Expand All @@ -25,85 +20,7 @@ To get started with local command-line usage, use [Apptainer](https://apptainer.
(a.k.a. Singularity) to run `pl-create_tetra` as a container:

```shell
singularity exec docker://fnndsc/pl-create_tetra create_tetra_wrapper [--args values...] input/ output/
```

To print its available options, run:

```shell
singularity exec docker://fnndsc/pl-create_tetra create_tetra_wrapper --help
```

## Examples

`create_tetra_wrapper` requires two positional arguments: a directory containing
input data, and a directory where to create output data.
First, create the input directory and move input data into it.

```shell
mkdir incoming/ outgoing/
mv some.dat other.dat incoming/
singularity exec docker://fnndsc/pl-create_tetra:latest create_tetra_wrapper [--args] incoming/ outgoing/
```

## Development

Instructions for developers.

### Building

Build a local container image:

```shell
docker build -t localhost/fnndsc/pl-create_tetra .
```

### Running

Mount the source code `create_tetra_wrapper.py` into a container to try out changes without rebuild.

```shell
docker run --rm -it --userns=host -u $(id -u):$(id -g) \
-v $PWD/create_tetra_wrapper.py:/usr/local/lib/python3.10/site-packages/create_tetra_wrapper.py:ro \
-v $PWD/in:/incoming:ro -v $PWD/out:/outgoing:rw -w /outgoing \
localhost/fnndsc/pl-create_tetra create_tetra_wrapper /incoming /outgoing
```

### Testing

Run unit tests using `pytest`.
It's recommended to rebuild the image to ensure that sources are up-to-date.
Use the option `--build-arg extras_require=dev` to install extra dependencies for testing.

```shell
docker build -t localhost/fnndsc/pl-create_tetra:dev --build-arg extras_require=dev .
docker run --rm -it localhost/fnndsc/pl-create_tetra:dev pytest
```

## Release

Steps for release can be automated by [Github Actions](.github/workflows/ci.yml).
This section is about how to do those steps manually.

### Increase Version Number

Increase the version number in `setup.py` and commit this file.

### Push Container Image

Build and push an image tagged by the version. For example, for version `1.2.3`:

```
docker build -t docker.io/fnndsc/pl-create_tetra:1.2.3 .
docker push docker.io/fnndsc/pl-create_tetra:1.2.3
```

### Get JSON Representation

Run [`chris_plugin_info`](https://github.com/FNNDSC/chris_plugin#usage)
to produce a JSON description of this plugin, which can be uploaded to a _ChRIS Store_.

```shell
docker run --rm localhost/fnndsc/pl-create_tetra:dev chris_plugin_info > chris_plugin_info.json
apptainer exec docker://fnndsc/pl-create_tetra create_tetra_wrapper out/
```

Its default behavior is to create a unit sphere `sphere_81920.obj` in the specified directory.
45 changes: 33 additions & 12 deletions create_tetra_wrapper.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env python

import sys
from pathlib import Path
from argparse import ArgumentParser, Namespace, ArgumentDefaultsHelpFormatter
from importlib.metadata import Distribution
import subprocess as sp
import shlex
import functools

from chris_plugin import chris_plugin

Expand All @@ -24,26 +27,44 @@

parser = ArgumentParser(description='A ChRIS fs plugin wrapper for create_tetra',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('-n', '--name', default='foo',
help='argument which sets example output file name')
parser.add_argument('-c', '--center', default='0,0,0', type=str,
help='center of sphere')
parser.add_argument('-r', '--radius', default='1,1,1', type=str,
help='radius of sphere')
parser.add_argument('-t', '--triangles', default=81920, type=int,
help='number of triangles')
parser.add_argument('-o', '--output', default='sphere_81920.obj',
help='output file name')
parser.add_argument('-V', '--version', action='version',
version=f'%(prog)s {__version__}')


# documentation: https://fnndsc.github.io/chris_plugin/chris_plugin.html#chris_plugin
@chris_plugin(
parser=parser,
title='create_tetra',
category='', # ref. https://chrisstore.co/plugins
min_memory_limit='100Mi', # supported units: Mi, Gi
min_cpu_limit='1000m', # millicores, e.g. "1000m" = 1 CPU core
min_gpu_limit=0 # set min_gpu_limit=1 to enable GPU
category='Modeling',
min_memory_limit='100Mi',
min_cpu_limit='1000m',
min_gpu_limit=0
)
def main(options: Namespace, inputdir: Path, outputdir: Path):
print(DISPLAY_TITLE)
def main(options: Namespace, outputdir: Path):
print(DISPLAY_TITLE, file=sys.stderr)

create_tetra = ('create_tetra',)
filename = (outputdir / options.output,)
center = parse_triplet(options.center)
radius = parse_triplet(options.radius)
n_triangles = (str(options.triangles),)

cmd = functools.reduce(lambda l, r: l + r, (create_tetra, filename, center, radius, n_triangles))
print('$> ' + shlex.join(map(str, cmd)), file=sys.stderr)

sp.run(cmd, check=True)


output_file = outputdir / f'{options.name}.txt'
output_file.write_text('did nothing successfully!')
def parse_triplet(s: str) -> tuple[str, str, str]:
x, y, z = s.split(',')
return x, y, z


if __name__ == '__main__':
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from setuptools import setup
import shutil

if not shutil.which('create_tetra'):
raise Exception('create_tetra command not found')

setup(
name='create_tetra',
Expand Down
23 changes: 0 additions & 23 deletions tests/test_example.py

This file was deleted.

19 changes: 19 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pytest_mock import MockerFixture
from pathlib import Path
import subprocess
from create_tetra_wrapper import parser, main


def test_main(mocker: MockerFixture, tmp_path: Path):
"""
Running main w/o options should create a unit sphere.
"""
outputdir = tmp_path / 'outgoing'
output_file = outputdir / 'sphere_81920.obj'

options = parser.parse_args([])
spy = mocker.spy(subprocess, 'run')
main(options, outputdir)
assert output_file.exists()
spy.assert_called_once()
assert spy.call_args[0][0][0] == 'create_tetra'

0 comments on commit 97d7692

Please sign in to comment.