Skip to content
Snippets Groups Projects
Commit e0b4b946 authored by Thibault Allançon's avatar Thibault Allançon
Browse files

model: remove deprecated and unused PID methods

Use the new SWHID naming convention instead of SWH PID.
parent a2737185
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,6 @@ import hashlib ...@@ -10,7 +10,6 @@ import hashlib
from typing import Any, Dict, Union from typing import Any, Dict, Union
import attr import attr
from deprecated import deprecated
from .collections import ImmutableDict from .collections import ImmutableDict
from .exceptions import ValidationError from .exceptions import ValidationError
...@@ -30,13 +29,6 @@ SWHID_TYPES = ["ori", "snp", "rel", "rev", "dir", "cnt"] ...@@ -30,13 +29,6 @@ SWHID_TYPES = ["ori", "snp", "rel", "rev", "dir", "cnt"]
SWHID_SEP = ":" SWHID_SEP = ":"
SWHID_CTXT_SEP = ";" SWHID_CTXT_SEP = ";"
# deprecated variables
PID_NAMESPACE = SWHID_NAMESPACE
PID_VERSION = SWHID_VERSION
PID_TYPES = SWHID_TYPES
PID_SEP = SWHID_SEP
PID_CTXT_SEP = SWHID_CTXT_SEP
@lru_cache() @lru_cache()
def identifier_to_bytes(identifier): def identifier_to_bytes(identifier):
...@@ -736,20 +728,6 @@ class SWHID: ...@@ -736,20 +728,6 @@ class SWHID:
return swhid return swhid
@deprecated("Use swh.model.identifiers.SWHID instead")
class PersistentId(SWHID):
"""
Named tuple holding the relevant info associated to a SoftWare Heritage
persistent IDentifier.
.. deprecated:: 0.3.8
Use :class:`swh.model.identifiers.SWHID` instead
"""
pass
def swhid( def swhid(
object_type: str, object_type: str,
object_id: Union[str, Dict[str, Any]], object_id: Union[str, Dict[str, Any]],
...@@ -784,17 +762,6 @@ def swhid( ...@@ -784,17 +762,6 @@ def swhid(
return str(swhid) return str(swhid)
@deprecated("Use swh.model.identifiers.swhid instead")
def persistent_identifier(*args, **kwargs) -> str:
"""Compute :ref:`persistent-identifiers`
.. deprecated:: 0.3.8
Use :func:`swh.model.identifiers.swhid` instead
"""
return swhid(*args, **kwargs)
def parse_swhid(swhid: str) -> SWHID: def parse_swhid(swhid: str) -> SWHID:
"""Parse :ref:`persistent-identifiers`. """Parse :ref:`persistent-identifiers`.
...@@ -848,13 +815,3 @@ def parse_swhid(swhid: str) -> SWHID: ...@@ -848,13 +815,3 @@ def parse_swhid(swhid: str) -> SWHID:
_id, _id,
_metadata, # type: ignore # mypy can't properly unify types _metadata, # type: ignore # mypy can't properly unify types
) )
@deprecated("Use swh.model.identifiers.parse_swhid instead")
def parse_persistent_identifier(persistent_id: str) -> PersistentId:
"""Parse :ref:`persistent-identifiers`.
.. deprecated:: 0.3.8
Use :func:`swh.model.identifiers.parse_swhid` instead
"""
return PersistentId(**parse_swhid(persistent_id).to_dict())
...@@ -856,7 +856,7 @@ class RawExtrinsicMetadata(BaseModel): ...@@ -856,7 +856,7 @@ class RawExtrinsicMetadata(BaseModel):
"Got SWHID as id for origin metadata (expected an URL)." "Got SWHID as id for origin metadata (expected an URL)."
) )
else: else:
self._check_pid(self.type.value, value) self._check_swhid(self.type.value, value)
@discovery_date.validator @discovery_date.validator
def check_discovery_date(self, attribute, value): def check_discovery_date(self, attribute, value):
...@@ -925,7 +925,7 @@ class RawExtrinsicMetadata(BaseModel): ...@@ -925,7 +925,7 @@ class RawExtrinsicMetadata(BaseModel):
f"Unexpected 'snapshot' context for {self.type.value} object: {value}" f"Unexpected 'snapshot' context for {self.type.value} object: {value}"
) )
self._check_pid("snapshot", value) self._check_swhid("snapshot", value)
@release.validator @release.validator
def check_release(self, attribute, value): def check_release(self, attribute, value):
...@@ -941,7 +941,7 @@ class RawExtrinsicMetadata(BaseModel): ...@@ -941,7 +941,7 @@ class RawExtrinsicMetadata(BaseModel):
f"Unexpected 'release' context for {self.type.value} object: {value}" f"Unexpected 'release' context for {self.type.value} object: {value}"
) )
self._check_pid("release", value) self._check_swhid("release", value)
@revision.validator @revision.validator
def check_revision(self, attribute, value): def check_revision(self, attribute, value):
...@@ -953,7 +953,7 @@ class RawExtrinsicMetadata(BaseModel): ...@@ -953,7 +953,7 @@ class RawExtrinsicMetadata(BaseModel):
f"Unexpected 'revision' context for {self.type.value} object: {value}" f"Unexpected 'revision' context for {self.type.value} object: {value}"
) )
self._check_pid("revision", value) self._check_swhid("revision", value)
@path.validator @path.validator
def check_path(self, attribute, value): def check_path(self, attribute, value):
...@@ -975,20 +975,20 @@ class RawExtrinsicMetadata(BaseModel): ...@@ -975,20 +975,20 @@ class RawExtrinsicMetadata(BaseModel):
f"Unexpected 'directory' context for {self.type.value} object: {value}" f"Unexpected 'directory' context for {self.type.value} object: {value}"
) )
self._check_pid("directory", value) self._check_swhid("directory", value)
def _check_pid(self, expected_object_type, pid): def _check_swhid(self, expected_object_type, swhid):
if isinstance(pid, str): if isinstance(swhid, str):
raise ValueError(f"Expected SWHID, got a string: {pid}") raise ValueError(f"Expected SWHID, got a string: {swhid}")
if pid.object_type != expected_object_type: if swhid.object_type != expected_object_type:
raise ValueError( raise ValueError(
f"Expected SWHID type '{expected_object_type}', " f"Expected SWHID type '{expected_object_type}', "
f"got '{pid.object_type}' in {pid}" f"got '{swhid.object_type}' in {swhid}"
) )
if pid.metadata: if swhid.metadata:
raise ValueError(f"Expected core SWHID, but got: {pid}") raise ValueError(f"Expected core SWHID, but got: {swhid}")
def to_dict(self): def to_dict(self):
d = super().to_dict() d = super().to_dict()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment