Skip to content
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

⬆️ Upgrade openapi generator #202

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
15869d0
begin converting to new generator
bisgaard-itis Oct 23, 2024
6df235f
remove invalid import
bisgaard-itis Oct 23, 2024
e6663e6
fix minor bug in tests
bisgaard-itis Oct 24, 2024
456a98b
fix download file method
bisgaard-itis Oct 24, 2024
e7756b1
remove skip if dev version decorator
bisgaard-itis Oct 24, 2024
373089b
update models in wrapper
bisgaard-itis Oct 24, 2024
4bb8a1c
patch JobInputs model
bisgaard-itis Oct 24, 2024
f55455b
make JobOutputs backwards compatible
bisgaard-itis Oct 24, 2024
4351ea5
improve wrapping of JobOutputs
bisgaard-itis Oct 24, 2024
8837472
improve JobInputs constructor
bisgaard-itis Oct 24, 2024
dae27fe
resolve configuration issue
bisgaard-itis Oct 24, 2024
35b66fd
include configuration directly in api
bisgaard-itis Oct 24, 2024
bc3bfe1
update to latest openapi.json
bisgaard-itis Oct 24, 2024
a5985bd
cleanup model location
bisgaard-itis Oct 24, 2024
4039885
start adding metadata test
bisgaard-itis Oct 27, 2024
728c497
expose MetadataValue
bisgaard-itis Oct 27, 2024
7a6ca5f
only missing check that objects coincide
bisgaard-itis Oct 27, 2024
98b53e5
improve wrapper models
bisgaard-itis Oct 28, 2024
f703002
improve jobinputs model
bisgaard-itis Oct 29, 2024
040d1f9
handle metadata and job inputs/outputs in studies api
bisgaard-itis Oct 29, 2024
5d0b7b5
fix several unittests
bisgaard-itis Oct 29, 2024
4257335
improve design of unittests
bisgaard-itis Oct 29, 2024
c38eac2
minor refactoring
bisgaard-itis Oct 29, 2024
8cd2ff3
start creating test for create solver jobs
bisgaard-itis Oct 29, 2024
295c827
add create job test
bisgaard-itis Oct 29, 2024
1ef0fd5
extract models from openapi specs
bisgaard-itis Nov 1, 2024
5b47cc2
add test for joboutputs
bisgaard-itis Nov 1, 2024
da0965f
minor cleanup
bisgaard-itis Nov 1, 2024
3fd8207
remove obsolete tests
bisgaard-itis Nov 1, 2024
99a4a65
fix create job function
bisgaard-itis Nov 1, 2024
9ba877c
use monkeypatch to avoid rouge env vars
bisgaard-itis Nov 1, 2024
a11cab2
redo uneeded change
bisgaard-itis Nov 3, 2024
36f5c1c
improve some signatures in the wrapped client
bisgaard-itis Nov 3, 2024
3e1e831
automate response model creation when mocking
bisgaard-itis Nov 4, 2024
3fc1767
add study api unit tests
bisgaard-itis Nov 4, 2024
bc42b5e
minor corrections
bisgaard-itis Nov 4, 2024
31e62ee
delete old comment @pcrespov
bisgaard-itis Nov 4, 2024
2ceb1ad
fix faker.uuid4 type issue
bisgaard-itis Nov 4, 2024
e76b901
fix
bisgaard-itis Nov 4, 2024
41f0df1
update openapi.json with new model examples
bisgaard-itis Nov 4, 2024
99341ad
make Make recipe more readable @pcrespov
bisgaard-itis Nov 4, 2024
db56108
merge master into 201-experiment-with-upgrading-openapi-generator
bisgaard-itis Nov 5, 2024
f0f31f6
python 3.8 compatible
bisgaard-itis Nov 6, 2024
e0d5f2d
merge master into 201-experiment-with-upgrading-openapi-generator
bisgaard-itis Nov 6, 2024
b9bcdc7
remove Annotated import from typing
bisgaard-itis Nov 6, 2024
ff7c0d5
fix type hinting dict to Dict for py 3.8
bisgaard-itis Nov 6, 2024
6323aaf
more py3.8 compatibility changes
bisgaard-itis Nov 6, 2024
084fa56
more py3.8 compatibility changes
bisgaard-itis Nov 6, 2024
db2d5d2
more py3.8 compatibility changes
bisgaard-itis Nov 6, 2024
866fa8a
more py3.8 compatibility changes
bisgaard-itis Nov 6, 2024
122e912
update openapi.json
bisgaard-itis Nov 8, 2024
002b157
minor fix after openapi.json update
bisgaard-itis Nov 8, 2024
5d37230
test fix for https://github.com/ITISFoundation/osparc-simcore/issues/…
bisgaard-itis Nov 8, 2024
baf7bc1
Merge branch '201-experiment-with-upgrading-openapi-generator' of git…
bisgaard-itis Nov 8, 2024
308dd7f
merge master into 201-experiment-with-upgrading-openapi-generator
bisgaard-itis Nov 18, 2024
4041620
add make target for installing local client for running e2e tests
bisgaard-itis Nov 18, 2024
5fd1600
Merge branch 'master' into 201-experiment-with-upgrading-openapi-gene…
bisgaard-itis Nov 25, 2024
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
2,133 changes: 1,289 additions & 844 deletions api/openapi.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions clients/python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ _check_venv_active:

.PHONY: install-dev
install-dev: _check_venv_active .install-dev-reqs python-client ## installs osparc_client and osparc in edit mode
uv pip install -e artifacts/client
uv pip install -e .
# for some reason this command refuses to run with uv. Looks related to https://github.com/astral-sh/uv/issues/1661
pip install --editable artifacts/client --editable .
uv pip list

.PHONY: install-unit-test
Expand All @@ -129,6 +129,10 @@ install-e2e-test: _check_venv_active guard-OSPARC_VERSION ## install packages fo
$(eval version := $(shell bash $(CLIENTS_PYTHON_DIR)/test/e2e/ci/bash/osparc_version.bash $(OSPARC_VERSION)))
uv pip install -r $(CLIENTS_PYTHON_DIR)/requirements/e2e-test.txt osparc-client==$(version) osparc==$(version)

.PHONY: install-e2e-test-local
install-e2e-test-local: _check_venv_active python-client ## install packages for e2e testing with local (repo) client [e2e]
pip install -r $(CLIENTS_PYTHON_DIR)/requirements/e2e-test.txt --editable artifacts/client --editable .

.PHONY: install-doc
install-doc: _check_venv_active .install-dev-reqs ## install packages for generating documentation
uv pip install -r $(CLIENTS_PYTHON_DIR)/requirements/doc.txt
Expand Down
1 change: 0 additions & 1 deletion clients/python/requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-r ../../../requirements.txt
-r unit-test.txt
-r e2e-test.txt
pylint
3 changes: 3 additions & 0 deletions clients/python/requirements/unit-test.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
-r ../../../requirements.txt
black
faker
openapi-spec-validator #installed as backend for prance
parse
pipdeptree
pipreqs
prance
pytest
pytest-asyncio
pytest-mock
Expand Down
1 change: 1 addition & 0 deletions clients/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"tenacity",
"tqdm>=4.48.0",
f"osparc_client=={VERSION}",
"urllib3",
"aiofiles",
]

Expand Down
6 changes: 2 additions & 4 deletions clients/python/src/osparc/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from typing import Optional

from osparc_client.api_client import ApiClient as _ApiClient
from osparc_client import Configuration
from ._configuration import Configuration
from pydantic import ValidationError

from ._settings import ConfigurationEnvVars


Expand All @@ -16,7 +15,6 @@ def __init__(
header_name=None,
header_value=None,
cookie=None,
pool_threads=1,
):
if configuration is None:
try:
Expand All @@ -36,4 +34,4 @@ def __init__(
"osparc.Configuration object explicitly"
) from exc

super().__init__(configuration, header_name, header_value, cookie, pool_threads)
super().__init__(configuration, header_name, header_value, cookie)
4 changes: 2 additions & 2 deletions clients/python/src/osparc/_api_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import logging
import math
from pathlib import Path
from typing import Any, Iterator, List, Optional, Tuple, Union, Set, Final
from typing import Any, Iterator, List, Optional, Tuple, Union, Final, Set
from tempfile import NamedTemporaryFile

import httpx
from httpx import Response
Expand All @@ -27,7 +28,6 @@
)
from urllib.parse import urljoin
import aiofiles
from tempfile import NamedTemporaryFile
import shutil
from ._utils import (
DEFAULT_TIMEOUT_SECONDS,
Expand Down
72 changes: 68 additions & 4 deletions clients/python/src/osparc/_api_solvers_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

import httpx
from osparc_client.api.solvers_api import SolversApi as _SolversApi
from .models import JobInputs, OnePageSolverPort, SolverPort
from .models import (
JobInputs,
OnePageSolverPort,
SolverPort,
Job,
JobOutputs,
JobMetadata,
JobMetadataUpdate,
)
from osparc_client import JobInputs as _JobInputs
from osparc_client import JobMetadataUpdate as _JobMetadataUpdate

from ._api_client import ApiClient
from ._settings import ParentProjectInfo
Expand All @@ -13,8 +23,11 @@
_DEFAULT_PAGINATION_OFFSET,
PaginationIterable,
)

import warnings
from tempfile import NamedTemporaryFile
from pathlib import Path
from pydantic import validate_call
from pydantic import StrictStr


class SolversApi(_SolversApi):
Expand Down Expand Up @@ -88,8 +101,59 @@ def jobs(self, solver_key: str, version: str, **kwargs) -> PaginationIterable:
)
return self.iter_jobs(solver_key, version, **kwargs)

@validate_call
def create_job(
self, solver_key: str, version: str, job_inputs: JobInputs, **kwargs
):
) -> Job:
_job_inputs = _JobInputs.from_json(job_inputs.model_dump_json())
assert _job_inputs is not None
kwargs = {**kwargs, **ParentProjectInfo().model_dump(exclude_none=True)}
return super().create_job(solver_key, version, job_inputs, **kwargs)
return super().create_job(solver_key, version, _job_inputs, **kwargs)

def get_job_output_logfile(
self,
solver_key: str,
version: str,
job_id: StrictStr,
**kwargs,
):
data = super().get_job_output_logfile(
solver_key=solver_key, version=version, job_id=job_id, **kwargs
)
with NamedTemporaryFile(delete=False) as tmp_file:
log_file = Path(tmp_file.name)
log_file.write_bytes(data)
return log_file

def get_job_outputs(
self,
solver_key: str,
version: str,
job_id: StrictStr,
**kwargs,
) -> JobOutputs:
_osparc_client_outputs = super().get_job_outputs(
solver_key=solver_key, version=version, job_id=job_id, **kwargs
)
return JobOutputs.model_validate_json(_osparc_client_outputs.to_json())

def get_job_custom_metadata(self, *args, **kwargs) -> JobMetadata:
metadata = super().get_job_custom_metadata(*args, **kwargs)
return JobMetadata.model_validate_json(metadata.to_json())

@validate_call
def replace_job_custom_metadata(
self,
solver_key: str,
version: str,
job_id: str,
job_metadata_update: JobMetadataUpdate,
) -> JobMetadata:
_job_metadata_update = _JobMetadataUpdate.from_json(
job_metadata_update.model_dump_json()
)
assert _job_metadata_update is not None
_job_custom_metadata = super().replace_job_custom_metadata(
solver_key, version, job_id, _job_metadata_update
)
return JobMetadata.model_validate_json(_job_custom_metadata.to_json())
44 changes: 42 additions & 2 deletions clients/python/src/osparc/_api_studies_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@
from typing import Optional

import httpx
from .models import JobInputs, JobLogsMap, PageStudy
from pydantic import StrictStr

from .models import (
JobInputs,
JobLogsMap,
PageStudy,
JobOutputs,
JobMetadata,
JobMetadataUpdate,
)
from osparc_client.api.studies_api import StudiesApi as _StudiesApi
from osparc_client import JobInputs as _JobInputs
from osparc_client import JobMetadataUpdate as _JobMetadataUpdate
from tqdm.asyncio import tqdm_asyncio

from ._api_client import ApiClient
Expand Down Expand Up @@ -58,8 +69,18 @@ def __init__(self, api_client: ApiClient):
)

def create_study_job(self, study_id: str, job_inputs: JobInputs, **kwargs):
_job_inputs = _JobInputs.from_json(job_inputs.model_dump_json())
bisgaard-itis marked this conversation as resolved.
Show resolved Hide resolved
assert _job_inputs is not None
kwargs = {**kwargs, **ParentProjectInfo().model_dump(exclude_none=True)}
return super().create_study_job(study_id, job_inputs, **kwargs)
return super().create_study_job(study_id, _job_inputs, **kwargs)

def get_study_job_outputs(
self, study_id: StrictStr, job_id: StrictStr, **kwargs
) -> JobOutputs:
_job_outputs = super().get_study_job_outputs(
study_id=study_id, job_id=job_id, **kwargs
)
return JobOutputs.model_validate_json(_job_outputs.to_json())

def clone_study(self, study_id: str, **kwargs):
kwargs = {**kwargs, **ParentProjectInfo().model_dump(exclude_none=True)}
Expand Down Expand Up @@ -140,3 +161,22 @@ async def _download(unique_node_name: str, download_link: str) -> None:
)

return folder

def get_study_job_custom_metadata(self, study_id: str, job_id: str) -> JobMetadata:
_job_metadata = super().get_study_job_custom_metadata(study_id, job_id)
return JobMetadata.model_validate_json(_job_metadata.to_json())

def replace_study_job_custom_metadata(
self,
study_id: StrictStr,
job_id: StrictStr,
job_metadata_update: JobMetadataUpdate,
) -> JobMetadata:
_job_metadata_update = _JobMetadataUpdate.from_json(
job_metadata_update.model_dump_json()
)
assert _job_metadata_update is not None
_job_metadata = super().replace_study_job_custom_metadata(
study_id, job_id, _job_metadata_update
)
return JobMetadata.model_validate_json(_job_metadata.to_json())
45 changes: 45 additions & 0 deletions clients/python/src/osparc/_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from osparc_client import Configuration as _Configuration
from typing import Set
from urllib3 import Retry


class Configuration(_Configuration):
def __init__(
self,
host="https://api.osparc.io",
api_key=None,
api_key_prefix=None,
username=None,
password=None,
*,
retry_max_count: int = 4,
retry_methods: Set[str] = {
"DELETE",
"GET",
"HEAD",
"OPTIONS",
"PUT",
"TRACE",
"POST",
"PATCH",
"CONNECT",
},
retry_status_codes: Set[int] = {429, 503, 504},
retry_backoff_factor=4.0,
):
retries = Retry(
total=retry_max_count,
backoff_factor=retry_backoff_factor,
status_forcelist=retry_status_codes,
allowed_methods=retry_methods,
respect_retry_after_header=True,
raise_on_status=True,
)
super().__init__(
host=host,
api_key=api_key,
api_key_prefix=api_key_prefix,
username=username,
password=password,
retries=retries,
)
45 changes: 45 additions & 0 deletions clients/python/src/osparc/_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from osparc_client import JobInputs as _JobInputs
from osparc_client import JobOutputs as _JobOutputs
from osparc_client import JobMetadata as _JobMetadata
from osparc_client import JobMetadataUpdate as _JobMetadataUpdate
from .models import File
from typing import Dict, Union, List, Optional
from pydantic import BaseModel, StrictStr, Field


class JobInputs(BaseModel):
values: Dict[str, Union[File, List[object], bool, float, int, str, None]]

def __init__(
self, values: Dict[str, Union[File, List[object], bool, float, int, str, None]]
):
super().__init__(values=values)


assert set(_JobInputs.model_fields.keys()) == set(JobInputs.model_fields.keys())


class JobOutputs(BaseModel):
job_id: StrictStr = Field(description="Job that produced this output")
results: Dict[str, Union[File, List[object], bool, float, int, str, None]]


assert set(_JobOutputs.model_fields.keys()) == set(JobOutputs.model_fields.keys())


class JobMetadata(BaseModel):
job_id: StrictStr
metadata: Dict[str, Union[bool, float, int, str, None]]
url: Optional[str]


assert set(_JobMetadata.model_fields.keys()) == set(JobMetadata.model_fields.keys())


class JobMetadataUpdate(BaseModel):
metadata: Dict[str, Union[bool, float, int, str, None]]


assert set(_JobMetadataUpdate.model_fields.keys()) == set(
JobMetadataUpdate.model_fields.keys()
)
2 changes: 1 addition & 1 deletion clients/python/src/osparc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# NOTE: this is an interface. Keep it clean!


from osparc_client.configuration import Configuration as Configuration
from ._configuration import Configuration as Configuration
from ._api_client import ApiClient as ApiClient


Expand Down
15 changes: 6 additions & 9 deletions clients/python/src/osparc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
from osparc_client.models.body_complete_multipart_upload_v0_files_file_id_complete_post import (
BodyCompleteMultipartUploadV0FilesFileIdCompletePost as BodyCompleteMultipartUploadV0FilesFileIdCompletePost,
)
from osparc_client.models.body_upload_file_v0_files_content_put import (
BodyUploadFileV0FilesContentPut as BodyUploadFileV0FilesContentPut,
)
from osparc_client.models.client_file import ClientFile as ClientFile
from osparc_client.models.client_file_upload_data import (
ClientFileUploadData as ClientFileUploadData,
Expand All @@ -31,13 +28,8 @@
HTTPValidationError as HTTPValidationError,
)
from osparc_client.models.job import Job as Job
from osparc_client.models.job_inputs import JobInputs as JobInputs
from osparc_client.models.job_logs_map import JobLogsMap as JobLogsMap
from osparc_client.models.job_metadata import JobMetadata as JobMetadata
from osparc_client.models.job_metadata_update import (
JobMetadataUpdate as JobMetadataUpdate,
)
from osparc_client.models.job_outputs import JobOutputs as JobOutputs
from osparc_client.models.values_value import ValuesValue as ValuesValue
from osparc_client.models.job_status import JobStatus as JobStatus
from osparc_client.models.links import Links as Links
from osparc_client.models.log_link import LogLink as LogLink
Expand All @@ -48,6 +40,7 @@
from osparc_client.models.one_page_study_port import (
OnePageStudyPort as OnePageStudyPort,
)
from osparc_client import MetadataValue as MetadataValue
from osparc_client.models.page_file import PageFile as PageFile
from osparc_client.models.page_job import PageJob as PageJob
from osparc_client.models.page_study import PageStudy as PageStudy
Expand Down Expand Up @@ -75,6 +68,10 @@
)
from osparc_client.models.wallet_status import WalletStatus as WalletStatus

from ._models import JobInputs as JobInputs
from ._models import JobOutputs as JobOutputs
from ._models import JobMetadata as JobMetadata
from ._models import JobMetadataUpdate as JobMetadataUpdate

# renames
TaskStates = _RunningState
Loading
Loading