diff --git a/swh/provenance/__init__.py b/swh/provenance/__init__.py --- a/swh/provenance/__init__.py +++ b/swh/provenance/__init__.py @@ -73,18 +73,11 @@ if cls == "local": from swh.core.db import BaseDb - from .postgresql.provenancedb_base import ProvenanceDBBase + from .postgresql.provenancedb import ProvenanceDB conn = BaseDb.connect(**kwargs["db"]).conn raise_on_commit = kwargs.get("raise_on_commit", False) - if "with-path" in ProvenanceDBBase(conn, raise_on_commit).flavor: - from .postgresql.provenancedb_with_path import ProvenanceWithPathDB - - return ProvenanceWithPathDB(conn, raise_on_commit) - else: - from .postgresql.provenancedb_without_path import ProvenanceWithoutPathDB - - return ProvenanceWithoutPathDB(conn, raise_on_commit) + return ProvenanceDB(conn, raise_on_commit) elif cls == "remote": from .api.client import RemoteProvenanceStorage diff --git a/swh/provenance/postgresql/provenancedb_base.py b/swh/provenance/postgresql/provenancedb.py rename from swh/provenance/postgresql/provenancedb_base.py rename to swh/provenance/postgresql/provenancedb.py --- a/swh/provenance/postgresql/provenancedb_base.py +++ b/swh/provenance/postgresql/provenancedb.py @@ -24,7 +24,7 @@ ) -class ProvenanceDBBase: +class ProvenanceDB: def __init__( self, conn: psycopg2.extensions.connection, raise_on_commit: bool = False ): @@ -359,4 +359,7 @@ return result def _relation_uses_location_table(self, relation: RelationType) -> bool: - ... + if self.with_path(): + src = relation.value.split("_")[0] + return src in ("content", "directory") + return False diff --git a/swh/provenance/postgresql/provenancedb_with_path.py b/swh/provenance/postgresql/provenancedb_with_path.py deleted file mode 100644 --- a/swh/provenance/postgresql/provenancedb_with_path.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (C) 2021 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU General Public License version 3, or any later version -# See top-level LICENSE file for more information - -from ..interface import RelationType -from .provenancedb_base import ProvenanceDBBase - - -class ProvenanceWithPathDB(ProvenanceDBBase): - def _relation_uses_location_table(self, relation: RelationType) -> bool: - src, *_ = relation.value.split("_") - return src in ("content", "directory") diff --git a/swh/provenance/postgresql/provenancedb_without_path.py b/swh/provenance/postgresql/provenancedb_without_path.py deleted file mode 100644 --- a/swh/provenance/postgresql/provenancedb_without_path.py +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (C) 2021 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU General Public License version 3, or any later version -# See top-level LICENSE file for more information - -from ..provenance import RelationType -from .provenancedb_base import ProvenanceDBBase - - -class ProvenanceWithoutPathDB(ProvenanceDBBase): - def _relation_uses_location_table(self, relation: RelationType) -> bool: - return False diff --git a/swh/provenance/tests/test_provenance_db.py b/swh/provenance/tests/test_provenance_db.py --- a/swh/provenance/tests/test_provenance_db.py +++ b/swh/provenance/tests/test_provenance_db.py @@ -4,16 +4,13 @@ # See top-level LICENSE file for more information from datetime import datetime, timedelta, timezone -from typing import Type from swh.model.model import OriginVisitStatus from swh.model.tests.swh_model_data import TEST_OBJECTS -from swh.provenance.interface import ProvenanceInterface, ProvenanceStorageInterface +from swh.provenance.interface import ProvenanceInterface from swh.provenance.model import OriginEntry from swh.provenance.origin import origin_add -from swh.provenance.postgresql.provenancedb_base import ProvenanceDBBase -from swh.provenance.postgresql.provenancedb_with_path import ProvenanceWithPathDB -from swh.provenance.postgresql.provenancedb_without_path import ProvenanceWithoutPathDB +from swh.provenance.postgresql.provenancedb import ProvenanceDB from swh.provenance.storage.archive import ArchiveStorage from swh.storage.postgresql.storage import Storage @@ -41,16 +38,10 @@ def test_provenance_flavor(provenance: ProvenanceInterface) -> None: - if isinstance(provenance.storage, ProvenanceDBBase): + if isinstance(provenance.storage, ProvenanceDB): assert provenance.storage.flavor in ( "with-path", "without-path", "with-path-denormalized", "without-path-denormalized", ) - backend_class: Type[ProvenanceStorageInterface] - if "with-path" in provenance.storage.flavor: - backend_class = ProvenanceWithPathDB - else: - backend_class = ProvenanceWithoutPathDB - assert isinstance(provenance.storage, backend_class)