Skip to content

Functions api ✨ 🗃️ #7539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 110 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
1b1e8fe
Add functions api. New commit to clean up db migration
wvangeit Apr 16, 2025
080e4fb
Add db migration script for functions api
wvangeit Apr 16, 2025
db68658
Add functions api. New commit to clean up db migration
wvangeit May 6, 2025
0170982
Add db migration script for functions api
wvangeit Apr 16, 2025
acdcfd4
Add solver functions
wvangeit Apr 16, 2025
8fbd814
Add default inputs to functions
wvangeit Apr 16, 2025
b5cf30a
Add default inputs to functions
wvangeit Apr 16, 2025
4e1ac9a
Add function collections
wvangeit Apr 29, 2025
9fabebf
Working project function job collection
wvangeit Apr 29, 2025
3c9f819
Add db migration for job collections
wvangeit Apr 29, 2025
77e0a00
Adapt for changes in solver job api
wvangeit Apr 29, 2025
b8722cc
Db merge heads functions draft and master rebase
wvangeit Apr 29, 2025
efdd470
Add tests for functions api server
wvangeit Apr 30, 2025
be9ac7c
Add function rpc tests
wvangeit Apr 30, 2025
6a7ba23
Move function rpc test dir
wvangeit Apr 30, 2025
23b36e9
Remove Nullable fields
wvangeit May 7, 2025
f956360
Merge alembic heads after rebase
wvangeit May 7, 2025
94c44c8
Fix tests after rebase
wvangeit May 7, 2025
61c3bbf
Add pagenation to function listing
wvangeit May 7, 2025
9f3d968
Fix function routes
wvangeit May 7, 2025
8619a2c
Fix function pagination api tests
wvangeit May 7, 2025
8042578
Fix pagination of functions again
wvangeit May 7, 2025
dc39523
Restore some files from master
wvangeit May 8, 2025
4022abb
Merge branch 'functions_draft_tests' into functions_draft
wvangeit May 8, 2025
d246bb4
Fix pylint
wvangeit May 8, 2025
616bf69
Changes based on Mads comments wrt functions api
wvangeit May 8, 2025
3da5899
Mention explicit exceptions in functions rpc
wvangeit May 8, 2025
ced82aa
Fix linting
wvangeit May 8, 2025
7e74a60
Add assert checks in functions rpc interface
wvangeit May 8, 2025
c1660c6
Fix gh action tests
wvangeit May 8, 2025
d4ef130
Add types jsonschema to api-server test requirements
wvangeit May 8, 2025
4e10cc7
Fix functions rpc assert and delete functions.py old schema
wvangeit May 8, 2025
188b0da
Add functions api. New commit to clean up db migration
wvangeit May 8, 2025
2feedee
Add db migration script for functions api
wvangeit Apr 16, 2025
f9f4a67
Add solver functions
wvangeit Apr 16, 2025
a5b5a76
Add default inputs to functions
wvangeit Apr 16, 2025
1f24485
Add default inputs to functions
wvangeit Apr 16, 2025
b38daa2
Add function collections
wvangeit Apr 29, 2025
ef3ce7b
Working project function job collection
wvangeit Apr 29, 2025
3f5ea5c
Add db migration for job collections
wvangeit Apr 29, 2025
5031f89
Adapt for changes in solver job api
wvangeit Apr 29, 2025
6957801
Db merge heads functions draft and master rebase
wvangeit Apr 29, 2025
baa5bfb
Add tests for functions api server
wvangeit Apr 30, 2025
c4aad00
Add function rpc tests
wvangeit Apr 30, 2025
b5421f2
Move function rpc test dir
wvangeit Apr 30, 2025
b061250
Remove Nullable fields
wvangeit May 7, 2025
e2d1da0
Merge alembic heads after rebase
wvangeit May 7, 2025
df546b3
Fix tests after rebase
wvangeit May 7, 2025
90dc711
Add pagenation to function listing
wvangeit May 7, 2025
d8393d4
Fix function routes
wvangeit May 7, 2025
e71932a
Fix function pagination api tests
wvangeit May 7, 2025
af697f2
Fix pagination of functions again
wvangeit May 7, 2025
bede7bd
Restore some files from master
wvangeit May 8, 2025
f772f04
Fix pylint
wvangeit May 8, 2025
fae8553
Changes based on Mads comments wrt functions api
wvangeit May 8, 2025
a8fbdf1
Mention explicit exceptions in functions rpc
wvangeit May 8, 2025
b683bc5
Fix linting
wvangeit May 8, 2025
e0d186b
Add assert checks in functions rpc interface
wvangeit May 8, 2025
9b2ff02
Fix gh action tests
wvangeit May 8, 2025
61dcec3
Add types jsonschema to api-server test requirements
wvangeit May 8, 2025
9b1e0a7
Fix functions rpc assert and delete functions.py old schema
wvangeit May 8, 2025
53f7029
Merge branch 'functions_draft' of github.com:wvangeit/osparc-simcore …
wvangeit May 8, 2025
f1041e1
Changes suggested by Sylvain wrt to functions api+new function schema
wvangeit May 9, 2025
1c22143
Refactor function db files based on SA's suggestion
wvangeit May 9, 2025
c548293
Fix db names in function repo
wvangeit May 9, 2025
489dd92
Rename function tables primary keys
wvangeit May 9, 2025
f1e9a63
Remove pk constraints from a functions table
wvangeit May 9, 2025
df84db9
Add migration script for renaming funcapi tables
wvangeit May 9, 2025
0c4980a
Merge branch 'master' into functions_draft
wvangeit May 9, 2025
810a1fa
Delete db migrates for funcapi to cleanup
wvangeit May 9, 2025
8bfaa2a
Add db migration script for functions_api
wvangeit May 9, 2025
98fa066
Run isort on function files
wvangeit May 9, 2025
d0d9f9b
Introducing Registered functions/function jobs/collections
wvangeit May 12, 2025
11555c1
Move function models back in function model file
wvangeit May 12, 2025
58b57e2
Move function collections model
wvangeit May 12, 2025
0b1e491
Fix function unit tests
wvangeit May 12, 2025
555a5a9
First batch of changes requested by GHK for functions API
wvangeit May 12, 2025
b056d29
Update openapi specs
wvangeit May 12, 2025
569d47b
Fix function tests
wvangeit May 12, 2025
f7bbfe6
Move rpc tests of functions to higher level
wvangeit May 13, 2025
b91196c
Move the rpc test some levels up
wvangeit May 13, 2025
65abd18
Merge branch 'master' into functions_draft
wvangeit May 13, 2025
a55ad90
Use prefix for function api routes
wvangeit May 13, 2025
fc4ec0d
Merge branch 'master' into functions_draft
wvangeit May 13, 2025
33f2757
Fix small lint failure
wvangeit May 13, 2025
a6d2097
Merge branch 'functions_draft' of github.com:wvangeit/osparc-simcore …
wvangeit May 13, 2025
313aade
Move function rpc tests to webserver 04
wvangeit May 13, 2025
48ebf8a
Merge branch 'master' into functions_draft
wvangeit May 13, 2025
0207711
Fix import in function controller
wvangeit May 13, 2025
983ae3d
Merge branch 'functions_draft' of github.com:wvangeit/osparc-simcore …
wvangeit May 13, 2025
5953ba9
Add creation/modification of functions in table
wvangeit May 14, 2025
9c7927c
Add creation/modification time to function table
wvangeit May 14, 2025
36498e9
Add function endpoints to update title and description
wvangeit May 14, 2025
2b54c17
Add new openapi specs for functions
wvangeit May 14, 2025
4f3c8ff
Merge branch 'master' into functions_draft
wvangeit May 14, 2025
8402ba0
Refactor api test to include deeper layers
wvangeit May 13, 2025
6c3d6e9
Move api tests of functions to deeper level
wvangeit May 14, 2025
bb80d20
Small lint fixes for functions
wvangeit May 14, 2025
0ff7180
Merge branch 'master' into functions_draft
wvangeit May 14, 2025
a472249
Lint fix
wvangeit May 14, 2025
1942489
Refactor function tests based on pr comments
wvangeit May 14, 2025
b61d3c8
Merge branch 'master' into functions_draft
wvangeit May 14, 2025
68d8fe5
Split function route files and solve other comments
wvangeit May 14, 2025
5916524
Pylint fixes
wvangeit May 15, 2025
7e4d917
Temp delete func db migration files
wvangeit May 15, 2025
834395f
Add function db migration script
wvangeit May 15, 2025
ad08a53
Fix comments from functions PR
wvangeit May 15, 2025
267c7a5
Rm functions db migration to create a new one
wvangeit May 15, 2025
e032e1e
Add a new function db migration script
wvangeit May 15, 2025
605fd28
Fix latest functions PR comments
wvangeit May 15, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Annotated, Any, Literal, TypeAlias

from models_library import projects
from pydantic import BaseModel, Field

FunctionID: TypeAlias = projects.ProjectID


class FunctionSchema(BaseModel):
schema_dict: dict[str, Any] | None # JSON Schema


class FunctionInputSchema(FunctionSchema): ...


class FunctionOutputSchema(FunctionSchema): ...


class Function(BaseModel):
uid: FunctionID | None = None
title: str | None = None
description: str | None = None
input_schema: FunctionInputSchema | None = None
output_schema: FunctionOutputSchema | None = None

# @classmethod
# def compose_resource_name(cls, function_key) -> api_resources.RelativeResourceName:
# return api_resources.compose_resource_name("functions", function_key)


class StudyFunction(Function):
function_type: Literal["study"] = "study"
study_url: str


class PythonCodeFunction(Function):
function_type: Literal["python_code"] = "python_code"
code_url: str


FunctionUnion: TypeAlias = Annotated[
StudyFunction | PythonCodeFunction,
Field(discriminator="function_type"),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
from enum import Enum
from typing import Annotated, Any, Literal, TypeAlias
from uuid import UUID

from models_library import projects
from pydantic import BaseModel, Field

from ..projects import ProjectID

FunctionID: TypeAlias = projects.ProjectID
FunctionJobID: TypeAlias = projects.ProjectID
FileID: TypeAlias = UUID

InputTypes: TypeAlias = FileID | float | int | bool | str | list | None


class FunctionSchema(BaseModel):
schema_dict: dict[str, Any] | None # JSON Schema


class FunctionInputSchema(FunctionSchema): ...


class FunctionOutputSchema(FunctionSchema): ...


class FunctionClass(str, Enum):
project = "project"
python_code = "python_code"


FunctionClassSpecificData: TypeAlias = dict[str, Any]
FunctionJobClassSpecificData: TypeAlias = FunctionClassSpecificData


# TODO, use InputTypes here, but api is throwing weird errors and asking for dict for elements # noqa: FIX002
FunctionInputs: TypeAlias = dict[str, Any] | None

FunctionInputsList: TypeAlias = list[FunctionInputs]

FunctionOutputs: TypeAlias = dict[str, Any] | None


class FunctionBase(BaseModel):
uid: FunctionID | None = None
title: str | None = None
description: str | None = None
function_class: FunctionClass
input_schema: FunctionInputSchema | None = None
output_schema: FunctionOutputSchema | None = None


class FunctionDB(BaseModel):
uuid: FunctionJobID | None = None
title: str | None = None
description: str | None = None
function_class: FunctionClass
input_schema: FunctionInputSchema | None = None
output_schema: FunctionOutputSchema | None = None
class_specific_data: FunctionClassSpecificData


class FunctionJobDB(BaseModel):
uuid: FunctionJobID | None = None
function_uuid: FunctionID
title: str | None = None
inputs: FunctionInputs | None = None
outputs: FunctionOutputs | None = None
class_specific_data: FunctionJobClassSpecificData
function_class: FunctionClass


class ProjectFunction(FunctionBase):
function_class: Literal[FunctionClass.project] = FunctionClass.project
project_id: ProjectID


class PythonCodeFunction(FunctionBase):
function_class: Literal[FunctionClass.python_code] = FunctionClass.python_code
code_url: str


Function: TypeAlias = Annotated[
ProjectFunction | PythonCodeFunction,
Field(discriminator="function_class"),
]

FunctionJobCollectionID: TypeAlias = projects.ProjectID


class FunctionJobBase(BaseModel):
uid: FunctionJobID | None = None
title: str | None = None
description: str | None = None
function_uid: FunctionID
inputs: FunctionInputs | None = None
outputs: FunctionOutputs | None = None
function_class: FunctionClass


class ProjectFunctionJob(FunctionJobBase):
function_class: Literal[FunctionClass.project] = FunctionClass.project
project_job_id: ProjectID


class PythonCodeFunctionJob(FunctionJobBase):
function_class: Literal[FunctionClass.python_code] = FunctionClass.python_code
code_url: str


FunctionJob: TypeAlias = Annotated[
ProjectFunctionJob | PythonCodeFunctionJob,
Field(discriminator="function_class"),
]


class FunctionJobStatus(BaseModel):
status: str


class FunctionJobCollection(BaseModel):
"""Model for a collection of function jobs"""

id: FunctionJobCollectionID
title: str | None
description: str | None
job_ids: list[FunctionJobID]
status: str


class FunctionJobCollectionStatus(BaseModel):
status: list[str]
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""Add function tables

Revision ID: 93dbd49553ae
Revises: cf8f743fd0b7
Create Date: 2025-04-16 09:32:48.976846+00:00

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "93dbd49553ae"
down_revision = "cf8f743fd0b7"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"function_job_collections",
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("name", sa.String(), nullable=True),
sa.PrimaryKeyConstraint("uuid", name="function_job_collections_pk"),
)
op.create_index(
op.f("ix_function_job_collections_uuid"),
"function_job_collections",
["uuid"],
unique=False,
)
op.create_table(
"functions",
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("title", sa.String(), nullable=True),
sa.Column("function_class", sa.String(), nullable=True),
sa.Column("description", sa.String(), nullable=True),
sa.Column("input_schema", sa.JSON(), nullable=True),
sa.Column("output_schema", sa.JSON(), nullable=True),
sa.Column("system_tags", sa.JSON(), nullable=True),
sa.Column("user_tags", sa.JSON(), nullable=True),
sa.Column("class_specific_data", sa.JSON(), nullable=True),
sa.PrimaryKeyConstraint("uuid", name="functions_pk"),
)
op.create_index(op.f("ix_functions_uuid"), "functions", ["uuid"], unique=False)
op.create_table(
"function_jobs",
sa.Column("uuid", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("title", sa.String(), nullable=True),
sa.Column("function_uuid", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("function_class", sa.String(), nullable=True),
sa.Column("status", sa.String(), nullable=True),
sa.Column("inputs", sa.JSON(), nullable=True),
sa.Column("outputs", sa.JSON(), nullable=True),
sa.Column("class_specific_data", sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(
["function_uuid"],
["functions.uuid"],
name="fk_functions_to_function_jobs_to_function_uuid",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint("uuid", name="function_jobs_pk"),
)
op.create_index(
op.f("ix_function_jobs_function_uuid"),
"function_jobs",
["function_uuid"],
unique=False,
)
op.create_index(
op.f("ix_function_jobs_uuid"), "function_jobs", ["uuid"], unique=False
)
op.create_table(
"function_job_collections_to_function_jobs",
sa.Column(
"function_job_collection_uuid", postgresql.UUID(as_uuid=True), nullable=True
),
sa.Column("function_job_uuid", postgresql.UUID(as_uuid=True), nullable=True),
sa.ForeignKeyConstraint(
["function_job_collection_uuid"],
["function_job_collections.uuid"],
name="fk_func_job_coll_to_func_jobs_to_func_job_coll_uuid",
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["function_job_uuid"],
["function_jobs.uuid"],
name="fk_func_job_coll_to_func_jobs_to_func_job_uuid",
onupdate="CASCADE",
ondelete="CASCADE",
),
)
op.drop_index("idx_projects_last_change_date_desc", table_name="projects")
op.create_index(
"idx_projects_last_change_date_desc",
"projects",
["last_change_date"],
unique=False,
postgresql_using="btree",
postgresql_ops={"last_change_date": "DESC"},
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
"idx_projects_last_change_date_desc",
table_name="projects",
postgresql_using="btree",
postgresql_ops={"last_change_date": "DESC"},
)
op.create_index(
"idx_projects_last_change_date_desc",
"projects",
[sa.text("last_change_date DESC")],
unique=False,
)
op.drop_table("function_job_collections_to_function_jobs")
op.drop_index(op.f("ix_function_jobs_uuid"), table_name="function_jobs")
op.drop_index(op.f("ix_function_jobs_function_uuid"), table_name="function_jobs")
op.drop_table("function_jobs")
op.drop_index(op.f("ix_functions_uuid"), table_name="functions")
op.drop_table("functions")
op.drop_index(
op.f("ix_function_job_collections_uuid"), table_name="function_job_collections"
)
op.drop_table("function_job_collections")
# ### end Alembic commands ###
Loading
Loading