Skip to content

Commit

Permalink
drop mixed use of classproperty/classmethod that has removed support …
Browse files Browse the repository at this point in the history
…by Py313 - use classmethod explicitly
  • Loading branch information
fmigneault committed Dec 18, 2024
1 parent 63aee8f commit 3ee07a8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
2 changes: 0 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions tests/test_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
)
]
Expand All @@ -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},
)
Expand All @@ -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],
)
Expand Down
7 changes: 3 additions & 4 deletions weaver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions weaver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand All @@ -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. "
Expand All @@ -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 "
Expand Down
7 changes: 2 additions & 5 deletions weaver/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()]
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion weaver/wps_restapi/swagger_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7788,7 +7788,7 @@ class GoneJobResponseSchema(ExtendedMappingSchema):


class JobProvAcceptHeader(AcceptHeader):
validator = OneOf(ProvenanceFormat.media_types)
validator = OneOf(ProvenanceFormat.media_types())


class JobProvRequestHeaders(RequestHeaders):
Expand Down

0 comments on commit 3ee07a8

Please sign in to comment.