Skip to content

Commit

Permalink
Ease of use (#65)
Browse files Browse the repository at this point in the history
* split schema from main plugin script

* initial rename script

* rename directories first

* correct entrypoint in Dockerfile

* add input check to rename script

* fix for github workflow

* rename configs to inputs
  • Loading branch information
dustinblack authored Dec 5, 2023
1 parent 9b35e85 commit 635417b
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
contents: write
pull-requests: write
with:
plugin_path: "arcaflow_plugin_template_python/arcaflow_plugin_template_python.py"
plugin_path: "arcaflow_plugin_template_python/template_python_plugin.py"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RUN python -m pip install -r requirements.txt

WORKDIR /app/${package}

ENTRYPOINT ["python", "arcaflow_plugin_template_python.py"]
ENTRYPOINT ["python", "template_python_plugin.py"]
CMD []

LABEL org.opencontainers.image.source="https://github.com/arcalot/arcaflow-plugin-template-python"
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Python Plugin Template Project
# Python Plugin Template

## Image Building

You can change this plugin's image version tag in
`.github/workflows/carpenter.yaml` by editing the
`IMAGE_TAG` variable, and pushing that change to the
branch designated in that workflow.
This plugin serves as a template from which new plugins can be built.

# Autogenerated Input/Output Documentation by Arcaflow-Docsgen Below

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,12 @@

import sys
import typing
from dataclasses import dataclass
from arcaflow_plugin_sdk import plugin, validation


@dataclass
class InputParams:
"""
This is the data structure for the input parameters of the step defined
below.
"""

name: typing.Annotated[str, validation.min(1)]


@dataclass
class SuccessOutput:
"""
This is the output data structure for the success case.
"""

message: str


@dataclass
class ErrorOutput:
"""
This is the output data structure in the error case.
"""

error: str
from arcaflow_plugin_sdk import plugin
from template_python_schema import (
InputParams,
SuccessOutput,
ErrorOutput,
)


@plugin.step(
Expand Down
33 changes: 33 additions & 0 deletions arcaflow_plugin_template_python/template_python_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import typing
from dataclasses import dataclass
from arcaflow_plugin_sdk import validation


@dataclass
class InputParams:
"""
This is the data structure for the input parameters of the step defined
below.
"""

name: typing.Annotated[str, validation.min(1)]


@dataclass
class SuccessOutput:
"""
This is the output data structure for the success case.
"""

message: str


@dataclass
class ErrorOutput:
"""
This is the output data structure in the error case.
"""

error: str
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ services:
image: quay.io/arcalot/arcaflow-plugin-template-python
build: .
volumes:
- source: ./example.yaml
- source: ./inputs/example.yaml
target: /config/example.yaml
type: bind
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Arcalot"]
license = "Apache-2.0+GPL-2.0-only"

packages = [
{ include="arcaflow_plugin_template_python.py", from="./arcaflow_plugin_template_python" },
{ include="template_python_plugin.py", from="./arcaflow_plugin_template_python" },
]

[tool.poetry.dependencies]
Expand Down
31 changes: 31 additions & 0 deletions set-plugin-name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

die () {
echo >&2 "$@"
exit 1
}

[ "$#" -eq 1 ] || die "1 argument required, $# provided"
echo $1 | grep -E -q '^.*-.*' && die "Please use underscores (_) instead of hyphens (-)"

for file in $(find . -type d -name '*template_python*'); do
git mv "$file" "${file/template_python/$1}"
done

for file in $(find . -type f -name '*template_python*'); do
git mv "$file" "${file/template_python/$1}"
done

for name in template_python Template; do
for file in $(grep -rl $name * .github); do
sed -i "s/$name/$1/g" $file
done
done

hyphenated_name=$(echo $1 | sed s/_/-/g)

for file in $(grep -rl template-python *); do
sed -i "s/template-python/$hyphenated_name/g" $file
done

echo "Template renaming complete. Please remove this file and commit your changes."
16 changes: 7 additions & 9 deletions tests/test_arcaflow_plugin_template_python.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
#!/usr/bin/env python3
import unittest
import arcaflow_plugin_template_python
import template_python_plugin
from arcaflow_plugin_sdk import plugin


class HelloWorldTest(unittest.TestCase):
@staticmethod
def test_serialization():
plugin.test_object_serialization(
arcaflow_plugin_template_python.InputParams("John Doe")
)
plugin.test_object_serialization(template_python_plugin.InputParams("John Doe"))

plugin.test_object_serialization(
arcaflow_plugin_template_python.SuccessOutput("Hello, world!")
template_python_plugin.SuccessOutput("Hello, world!")
)

plugin.test_object_serialization(
arcaflow_plugin_template_python.ErrorOutput(error="This is an error")
template_python_plugin.ErrorOutput(error="This is an error")
)

def test_functional(self):
input = arcaflow_plugin_template_python.InputParams(name="Example Joe")
input = template_python_plugin.InputParams(name="Example Joe")

output_id, output_data = arcaflow_plugin_template_python.hello_world(
output_id, output_data = template_python_plugin.hello_world(
params=input, run_id="plugin_ci"
)

# The example plugin always returns an error:
self.assertEqual("success", output_id)
self.assertEqual(
output_data,
arcaflow_plugin_template_python.SuccessOutput("Hello, Example Joe!"),
template_python_plugin.SuccessOutput("Hello, Example Joe!"),
)


Expand Down

0 comments on commit 635417b

Please sign in to comment.