From 4bdaa3c6d9ea8133739a316903242880f780b697 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Fri, 4 Mar 2022 12:21:37 -0500 Subject: [PATCH] Initial commit --- .dockerignore | 18 +++++++++++ .gitignore | 11 +++++++ Dockerfile | 18 +++++++++++ LICENSE | 21 +++++++++++++ README.md | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ app.py | 26 +++++++++++++++ requirements.txt | 1 + setup.py | 26 +++++++++++++++ 8 files changed, 203 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100755 app.py create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..63df785 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +.git/ +.github/ +.dockerignore +Dockerfile + +*~ +*.DS_Store +*.egg-info/ +__pycache__/ + +.docker + +.idea/ +.vscode/ + +examples/ + +venv/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ffd9fdb --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*~ +*.DS_Store +*.egg-info/ +__pycache__/ + +.docker + +.idea/ +.vscode/ + +venv/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3c76768 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# 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.2-slim-buster + +LABEL org.opencontainers.image.authors="FNNDSC " \ + org.opencontainers.image.title="ChRIS Plugin Title" \ + org.opencontainers.image.description="A ChRIS ds plugin that..." + +WORKDIR /usr/local/src/app + +COPY requirements.txt . +RUN pip install -r requirements.txt + +COPY . . +RUN pip install . + +CMD ["commandname", "--help"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..205de68 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 FNNDSC / BCH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..68508f0 --- /dev/null +++ b/README.md @@ -0,0 +1,82 @@ +# _ChRIS_ ds Plugin Template + + + + +This is a minimal template repository for _ChRIS_ _ds_ plugin applications. +For a more comprehensive boilerplate, use + +https://github.com/fnndsc/cookiecutter-chrisapp + +## How to Use This Template + +1. Click "Use this template" +2. Clone the newly created repository +3. Replace placeholder text + +```shell +function replace () { + find . -type f -not -path '*/\.*/*' -not -path '*/\venv/*' -exec sed -i -e "s/$1/$2/g" '{}' \; +} + +replace commandname my_command_name +replace pl-appname pl-my-plugin-name +replace fnndsc my_username +``` + +### Template Examples + +Here are some good, complete examples of _ChRIS_ plugins created from this template. + +- https://github.com/FNNDSC/pl-nums2mask +- https://github.com/FNNDSC/pl-nii2mnc-u8 + +Advanced users can `cp -rv .github/workflows` into their own repositories to enable +automatic builds. + +## Abstract + +PROGRAMNAME is a [_ChRIS_](https://chrisproject.org/) +_ds_ plugin which takes in ... as input files and +creates ... as output files. + +## Usage + +```shell +singularity exec docker://fnndsc/pl-appname commandname [--args values...] input/ output/ +``` + +## Examples + +```shell +mkdir incoming/ outgoing/ +mv some.dat other.dat incoming/ +singularity exec docker://fnndsc/pl-appname:latest commandname [--args] incoming/ outgoing/ +``` + +## Development + +### Building + +```shell +docker build -t localhost/fnndsc/pl-appname . +``` + +### Get JSON Representation + +```shell +docker run --rm localhost/fnndsc/pl-appname chris_plugin_info > MyProgram.json +``` + +### Local Test Run + +```shell +docker run --rm -it --userns=host -u $(id -u):$(id -g) \ + -v $PWD/app.py:/usr/local/lib/python3.10/site-packages/app.py:ro \ + -v $PWD/in:/incoming:ro -v $PWD/out:/outgoing:rw -w /outgoing \ + localhost/fnndsc/pl-appname commandname /incoming /outgoing +``` diff --git a/app.py b/app.py new file mode 100755 index 0000000..25b25b0 --- /dev/null +++ b/app.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +from pathlib import Path +from argparse import ArgumentParser, Namespace +from chris_plugin import chris_plugin + +parser = ArgumentParser(description='cli description') +parser.add_argument('-e', '--example', default='jelly', + help='argument which does not do anything') + + +# documentation: https://fnndsc.github.io/chris_plugin/ +@chris_plugin( + parser=parser, + title='My ChRIS plugin', + 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 +) +def main(options: Namespace, inputdir: Path, outputdir: Path): + print(f'Option: {options.example}') + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..233c7de --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +chris_plugin~=0.0.12 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f4da0fb --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +from setuptools import setup + +setup( + name = 'chris-plugin-template', + version = '1.0.0', + description = 'A ChRIS DS plugin template', + author = 'FNNDSC', + author_email = 'dev@babyMRI.org', + url = 'https://github.com/FNNDSC/python-chrisapp-template', + py_modules = ['app'], + install_requires = ['chris_plugin'], + license = 'MIT', + python_requires = '>=3.8.2', + entry_points = { + 'console_scripts': [ + 'commandname = app:main' + ] + }, + classifiers = [ + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3.10', + 'Topic :: Scientific/Engineering', + 'Topic :: Scientific/Engineering :: Bio-Informatics', + 'Topic :: Scientific/Engineering :: Medical Science Apps.' + ] +)