Skip to content

Commit

Permalink
v0.2.2 (#11)
Browse files Browse the repository at this point in the history
* update parameter to accept all primitive types

* fix defaults for availability model (#10)

* update version number to dev

* update version to 0.2.2
  • Loading branch information
jwfraustro authored Dec 19, 2023
1 parent 3af8127 commit 2753176
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "vo-models"
version = "0.2.1"
version = "0.2.2"
authors = [
{name = "Joshua Fraustro", email="[email protected]"},
{name = "MAST Archive Developers", email="[email protected]"}
Expand Down
26 changes: 8 additions & 18 deletions vo_models/uws/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""UWS Job Schema using Pydantic-XML models"""
from typing import Dict, Generic, Optional, TypeVar

from pydantic import field_validator
from pydantic_xml import BaseXmlModel, attr, element

from vo_models.uws.types import ErrorType, ExecutionPhase, UWSVersion
Expand All @@ -21,10 +20,6 @@
class Parameter(BaseXmlModel, tag="parameter", ns="uws", nsmap=NSMAP):
"""A UWS Job parameter
The list of input parameters to the job - if the job description language does not naturally have
parameters, then this list should contain one element which is the content of the original POST that created the
job.
Attributes:
byReference (bool): If this attribute is true then the content of the parameter represents a URL to retrieve the
actual parameter value.
Expand All @@ -39,22 +34,21 @@ class Parameter(BaseXmlModel, tag="parameter", ns="uws", nsmap=NSMAP):
value (str): the value of the parameter.
"""

value: Optional[str] = None
value: Optional[str | int | float | bool | bytes] = None # only primitive types are allowed

by_reference: Optional[bool] = attr(name="byReference", default=False)
id: str = attr()
is_post: Optional[bool] = attr(name="isPost", default=False)

@field_validator("value", mode="before")
def validate_value(cls, value): # pylint: disable=no-self-argument
"""Coerces value to a string"""
# TODO: Find better way to handle arbitrary types
if value is not None:
return str(value)


class Parameters(BaseXmlModel, tag="parameters", ns="uws", nsmap=NSMAP):
"""An abstract holder of UWS parameters."""
"""
An abstract holder of UWS parameters.
The list of input parameters to the job - if the job description language does not naturally have
parameters, then this list should contain one element which is the content of the original POST that created the
job.
"""

def __init__(__pydantic_self__, **data) -> None: # pylint: disable=no-self-argument
# during init -- especially if reading from xml -- we may not get the parameters in the order
Expand Down Expand Up @@ -170,10 +164,6 @@ class Jobs(BaseXmlModel, tag="jobs", ns="uws", nsmap=NSMAP):
version: Optional[UWSVersion] = attr(default=UWSVersion.V1_1)


# pylint: disable=invalid-name
ParametersType = TypeVar("ParametersType", bound=Parameters)


class JobSummary(BaseXmlModel, Generic[ParametersType], tag="job", ns="uws", nsmap=NSMAP):
"""The complete representation of the state of a job
Expand Down
10 changes: 5 additions & 5 deletions vo_models/vosi/availability/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}


class Availability(BaseXmlModel, tag="availability", nsmap=NSMAP):
class Availability(BaseXmlModel, tag="availability", nsmap=NSMAP, skip_empty=True):
"""VOSI Availability complex type.
Elements:
Expand All @@ -26,7 +26,7 @@ class Availability(BaseXmlModel, tag="availability", nsmap=NSMAP):
"""

available: bool = element(tag="available")
up_since: Optional[UTCTimestamp] = element(tag="upSince")
down_at: Optional[UTCTimestamp] = element(tag="downAt")
back_at: Optional[UTCTimestamp] = element(tag="backAt")
note: Optional[list[str]] = element(tag="note")
up_since: Optional[UTCTimestamp] = element(tag="upSince", default=None)
down_at: Optional[UTCTimestamp] = element(tag="downAt", default=None)
back_at: Optional[UTCTimestamp] = element(tag="backAt", default=None)
note: Optional[list[str]] = element(tag="note", default=None)

0 comments on commit 2753176

Please sign in to comment.