diff --git a/CHANGES.rst b/CHANGES.rst index c3813ab2f..a7dae625a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -37,8 +37,6 @@ Changes: Fixes: ------ - Fix missing documentation about certain ``WeaverClient`` operations. -- Fix metaclass of ``weaver.base.Constants`` not properly handling derived classes using methods decorated - by mixed use of ``classmethod`` and ``classproperty`` to provide "*dynamically computed*" class attributes. - Fix ``weaver.cli.OperationResult`` not setting its ``text`` property when a valid non-`JSON` response is obtained. - Fix the `API` frontpage `HTML` rendering to returning enabled features and corresponding ``doc``/``url``/``api`` endpoints for quick referencing the capabilities activated for a `Weaver` instance. diff --git a/tests/test_provenance.py b/tests/test_provenance.py index c4d2e1714..7c86b403a 100644 --- a/tests/test_provenance.py +++ b/tests/test_provenance.py @@ -32,7 +32,7 @@ def test_provenance_path_type_resolution(provenance, prov_run_id, expect_path, e @pytest.mark.prov def test_provenance_formats(): - result = ProvenanceFormat.formats + result = ProvenanceFormat.formats() expect = [ ProvenanceFormat.PROV_JSON, ProvenanceFormat.PROV_JSONLD, @@ -47,7 +47,7 @@ def test_provenance_formats(): @pytest.mark.prov def test_provenance_media_types(): - result = ProvenanceFormat.media_types + result = ProvenanceFormat.media_types() expect = [ ContentType.APP_JSON, ContentType.APP_JSONLD, @@ -131,7 +131,7 @@ def test_provenance_as_media_type(provenance, expect): (_prov, _prov_fmt, None, None, False) for _prov, _prov_fmt in itertools.product( - set(ProvenancePathType.types) - {ProvenancePathType.as_type(ProvenancePathType.PROV)}, + set(ProvenancePathType.types()) - {ProvenancePathType.as_type(ProvenancePathType.PROV)}, ProvenanceFormat.values(), ) ] @@ -142,7 +142,7 @@ def test_provenance_as_media_type(provenance, expect): (_prov, _prov_fmt, _out_fmt, None, True) for _prov, _prov_fmt, _out_fmt in itertools.product( - set(ProvenancePathType.types) - {ProvenancePathType.as_type(ProvenancePathType.PROV)}, + set(ProvenancePathType.types()) - {ProvenancePathType.as_type(ProvenancePathType.PROV)}, ProvenanceFormat.values(), set(OutputFormat.values()) - {OutputFormat.TEXT, OutputFormat.TXT}, ) @@ -154,7 +154,7 @@ def test_provenance_as_media_type(provenance, expect): (_prov, _prov_fmt, _out_fmt, None, False) for _prov, _prov_fmt, _out_fmt in itertools.product( - set(ProvenancePathType.types) - {ProvenancePathType.as_type(ProvenancePathType.PROV)}, + set(ProvenancePathType.types()) - {ProvenancePathType.as_type(ProvenancePathType.PROV)}, ProvenanceFormat.values(), [OutputFormat.TEXT, OutputFormat.TXT], ) diff --git a/weaver/base.py b/weaver/base.py index 0dcb0ee11..01f048e01 100644 --- a/weaver/base.py +++ b/weaver/base.py @@ -113,7 +113,6 @@ class classproperty(property): # pylint: disable=C0103,invalid-name .. seealso:: https://stackoverflow.com/a/5191224 """ - def __init__(self, fget=None, # type: Optional[Callable[[object], PropertyDataTypeT]] fset=None, # type: Optional[Callable[[object, PropertyDataTypeT], None]] @@ -123,9 +122,9 @@ def __init__(self, super(classproperty, self).__init__(fget=fget, fset=fset, fdel=fdel, doc=doc) self.__doc__ = inspect.cleandoc(doc) - def __get__(self, cls, owner): # noqa - # type: (Type[object], Any) -> PropertyDataTypeT - return classmethod(self.fget).__get__(None, owner or cls)() + def __get__(self, instance, owner=None): + # type: (Any, Optional[Type[object]]) -> PropertyDataTypeT + return self.fget.__get__(None, owner)(instance or owner) class _EnumMeta(enum.EnumMeta): diff --git a/weaver/cli.py b/weaver/cli.py index eac625343..dbfcec97f 100644 --- a/weaver/cli.py +++ b/weaver/cli.py @@ -2687,7 +2687,7 @@ def add_provenance_params(parser): # type: (argparse.ArgumentParser) -> None parser.add_argument( "-pT", "--prov", "--prov-type", dest="prov", - choices=ProvenancePathType.types, + choices=ProvenancePathType.types(), help=( "Desired PROV metadata contents. " "The main PROV metadata supports multiple representations. " @@ -2696,7 +2696,7 @@ def add_provenance_params(parser): ) parser.add_argument( "-pF", "--prov-format", dest="prov_format", - choices=ProvenanceFormat.formats, + choices=ProvenanceFormat.formats(), help=( "Desired PROV metadata schema representation. " "Applicable formats depend on the PROV metadata type being requested. " @@ -2707,7 +2707,7 @@ def add_provenance_params(parser): ) parser.add_argument( "-pR", "--run", "--prov-run", dest="prov_run_id", - choices=ProvenancePathType.types, + choices=ProvenancePathType.types(), help=( "Specific run (i.e.: a nested Workflow step) for which to retrieve Provenance metadata. " "Applicable IDs will typically correspond to the underlying Job ID that would have been " diff --git a/weaver/provenance.py b/weaver/provenance.py index 1676a816e..648674331 100644 --- a/weaver/provenance.py +++ b/weaver/provenance.py @@ -10,7 +10,7 @@ from prov import constants as prov_const from weaver.__meta__ import __version__ as weaver_version -from weaver.base import Constants, classproperty +from weaver.base import Constants from weaver.formats import ContentType, OutputFormat from weaver.utils import get_weaver_url @@ -40,7 +40,6 @@ class ProvenancePathType(Constants): PROV_RUNS = "/prov/runs" @classmethod - @classproperty def types(cls): # type: () -> List[str] return [cls.as_type(prov) for prov in cls.values()] @@ -64,7 +63,7 @@ def get( # pylint: disable=W0221,W0237 # arguments differ/renamed fo if prov_found is not None and run_id is None: return prov_found if isinstance(prov, str): - if not prov_found and prov.strip("/") not in ProvenancePathType.types: # pylint: disable=E1135 + if not prov_found and prov.strip("/") not in ProvenancePathType.types(): return default prov = f"/{prov}" if not prov.startswith("/") else prov prov = f"/prov{prov}" if not prov.startswith("/prov") else prov @@ -110,13 +109,11 @@ def get( # pylint: disable=W0221,W0237 # arguments diffe return prov @classmethod - @classproperty def media_types(cls): # type: () -> List[ContentType] return list(cls._media_types) @classmethod - @classproperty def formats(cls): # type: () -> List["ProvenanceFormat"] return cls.values() diff --git a/weaver/wps_restapi/swagger_definitions.py b/weaver/wps_restapi/swagger_definitions.py index 084d8041d..0076e3cc1 100644 --- a/weaver/wps_restapi/swagger_definitions.py +++ b/weaver/wps_restapi/swagger_definitions.py @@ -7788,7 +7788,7 @@ class GoneJobResponseSchema(ExtendedMappingSchema): class JobProvAcceptHeader(AcceptHeader): - validator = OneOf(ProvenanceFormat.media_types) + validator = OneOf(ProvenanceFormat.media_types()) class JobProvRequestHeaders(RequestHeaders):