Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/FAIRmat-NFDI/cookiecutter-nomad-plugin",
"commit": "d306850507a46af96b5ab71129582655ce534c86",
"commit": "f942403ed913de05af91db50209d494ccea148a3",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -17,11 +17,12 @@
"include_parser": true,
"include_app": false,
"include_example_uploads": true,
"include_action": true,
"_copy_without_render": [
"*.html"
],
"_template": "https://github.com/FAIRmat-NFDI/cookiecutter-nomad-plugin",
"_commit": "d306850507a46af96b5ab71129582655ce534c86"
"_commit": "f942403ed913de05af91db50209d494ccea148a3"
}
},
"directory": null
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.rulers": [
90
88
],
"editor.renderWhitespace": "all",
"editor.tabSize": 4,
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
recursive-include * nomad_plugin.yaml
graft src/nomad_plugin_parser_example/example_uploads
27 changes: 24 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,31 @@ maintainers = [
]
license = { file = "LICENSE" }
dependencies = [
"nomad-lab>=1.3.0",
"python-magic-bin; sys_platform == 'win32'",
"nomad-lab>=1.4.0",
"pydantic",
"temporalio",
]

[project.urls]
Repository = "https://github.com/ZBT-Tools/nomad_plugin_parser_example"

[project.optional-dependencies]
dev = ["ruff", "pytest", "structlog"]
dev = [
"ruff",
"pytest",
"structlog",
"mkdocs",
"mkdocs-material==8.1.1",
"pymdown-extensions",
"mkdocs-click",
"pytest-asyncio",
]

[tool.uv]
extra-index-url = [
"https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple",
]

[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
Expand Down Expand Up @@ -82,13 +97,18 @@ select = [

ignore = [
"F403", # 'from module import *' used; unable to detect undefined names
"PLC0415", # `import` should be at the top-level of a file
"E501", # line too long
]

fixable = ["ALL"]

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["PLC0415"] # import-outside-top-level

# this is entirely optional, you can remove this if you wish to
[tool.ruff.format]
# use single quotes for strings.
Expand All @@ -115,6 +135,7 @@ schema_package_entry_point = "nomad_plugin_parser_example.schema_packages:schema


example_upload_entry_point = "nomad_plugin_parser_example.example_uploads:example_upload_entry_point"
action_entry_point = "nomad_plugin_parser_example.actions:simple_action_entry_point"
[tool.cruft]
# Avoid updating workflow files, this leads to permissions issues
skip = [".github/*"]
4 changes: 0 additions & 4 deletions requirements_docs.txt

This file was deleted.

3 changes: 3 additions & 0 deletions src/nomad_plugin_parser_example/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from nomad_plugin_parser_example.actions.simple_action import simple_action_entry_point

__all__ = ['simple_action_entry_point']
30 changes: 30 additions & 0 deletions src/nomad_plugin_parser_example/actions/simple_action/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from nomad.actions import TaskQueue
from pydantic import Field
from temporalio import workflow

with workflow.unsafe.imports_passed_through():
from nomad.config.models.plugins import ActionEntryPoint


class SimpleActionEntryPoint(ActionEntryPoint):
task_queue: str = Field(
default=TaskQueue.CPU, description='Determines the task queue for this action'
)

def load(self):
from nomad.actions import Action

from nomad_plugin_parser_example.actions.simple_action.activities import greet
from nomad_plugin_parser_example.actions.simple_action.workflows import SimpleWorkflow

return Action(
task_queue=self.task_queue,
workflow=SimpleWorkflow,
activities=[greet],
)


simple_action_entry_point = SimpleActionEntryPoint(
name='SimpleAction',
description='A simple action that returns a greeting.',
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from temporalio import activity

from nomad_plugin_parser_example.actions.simple_action.models import SimpleWorkflowInput


@activity.defn
async def greet(data: SimpleWorkflowInput) -> str:
return f'hello {data.name} - created by user {data.user_id} for upload {data.upload_id}'
15 changes: 15 additions & 0 deletions src/nomad_plugin_parser_example/actions/simple_action/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pydantic import BaseModel, Field


class SimpleWorkflowInput(BaseModel):
"""Input model for the simple workflow"""

upload_id: str = Field(
...,
description='Unique identifier for the upload associated with the workflow.',
)
user_id: str = Field(
..., description='Unique identifier for the user who initiated the workflow.'
)

name: str = Field(..., description='The name to greet.')
24 changes: 24 additions & 0 deletions src/nomad_plugin_parser_example/actions/simple_action/workflows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from datetime import timedelta

from temporalio import workflow
from temporalio.common import RetryPolicy

with workflow.unsafe.imports_passed_through():
from nomad_plugin_parser_example.actions.simple_action.activities import greet
from nomad_plugin_parser_example.actions.simple_action.models import SimpleWorkflowInput


@workflow.defn
class SimpleWorkflow:
@workflow.run
async def run(self, data: SimpleWorkflowInput) -> str:
retry_policy = RetryPolicy(
maximum_attempts=3,
)
result = await workflow.execute_activity(
greet,
data,
start_to_close_timeout=timedelta(seconds=60),
retry_policy=retry_policy,
)
return result
32 changes: 32 additions & 0 deletions tests/actions/test_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import Worker

from nomad_plugin_parser_example.actions.simple_action.activities import greet
from nomad_plugin_parser_example.actions.simple_action.models import SimpleWorkflowInput
from nomad_plugin_parser_example.actions.simple_action.workflows import SimpleWorkflow


@pytest.mark.asyncio
async def test_simple_workflow():
task_queue = 'test-simple-workflow'
async with await WorkflowEnvironment.start_local() as env:
async with Worker(
env.client,
task_queue=task_queue,
workflows=[SimpleWorkflow],
activities=[greet],
):
result = await env.client.execute_workflow(
SimpleWorkflow.run,
SimpleWorkflowInput(
upload_id='upload_id',
user_id='user_id',
name='World',
),
id='test-workflow',
task_queue=task_queue,
)
assert (
result == 'hello World - created by user user_id for upload upload_id'
)