From 1a49158afab3706c2f62c6b85b58cd201cc37ba3 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Tue, 14 Jan 2025 07:00:19 +0100 Subject: [PATCH] refact: move repository to data_repository --- plesna/dataplatform.py | 6 +++--- .../{repository => data_repository}/__init__.py | 0 .../data_repository.py} | 2 +- .../fs_data_repository.py} | 8 ++++---- tests/dataplatform/test_dataplateform.py | 16 ++++++++-------- ..._repository.py => test_fs_data_repository.py} | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) rename plesna/storage/{repository => data_repository}/__init__.py (100%) rename plesna/storage/{repository/repository.py => data_repository/data_repository.py} (97%) rename plesna/storage/{repository/fs_repository.py => data_repository/fs_data_repository.py} (96%) rename tests/storage/{test_fs_repository.py => test_fs_data_repository.py} (92%) diff --git a/plesna/dataplatform.py b/plesna/dataplatform.py index 0f47384..7daa365 100644 --- a/plesna/dataplatform.py +++ b/plesna/dataplatform.py @@ -5,7 +5,7 @@ from plesna.graph.graph_set import GraphSet from plesna.models.flux import Flux, FluxMetaData from plesna.models.graphs import Node from plesna.models.libs.flux_graph import flux_to_edgeonset -from plesna.storage.repository.repository import Repository +from plesna.storage.data_repository.data_repository import DataRepository class DataPlateformError(Exception): @@ -18,7 +18,7 @@ class DataPlateform: self._fluxes = {} self._repositories = {} - def add_repository(self, repository: Repository) -> str: + def add_repository(self, repository: DataRepository) -> str: if repository.id in self._repositories: raise DataPlateformError("The repository {repository.id} already exists") @@ -29,7 +29,7 @@ class DataPlateform: def repositories(self) -> list[str]: return list(self._repositories) - def repository(self, id: str) -> Repository: + def repository(self, id: str) -> DataRepository: return self._repositories[id] def add_flux(self, name: str, flux: Flux) -> str: diff --git a/plesna/storage/repository/__init__.py b/plesna/storage/data_repository/__init__.py similarity index 100% rename from plesna/storage/repository/__init__.py rename to plesna/storage/data_repository/__init__.py diff --git a/plesna/storage/repository/repository.py b/plesna/storage/data_repository/data_repository.py similarity index 97% rename from plesna/storage/repository/repository.py rename to plesna/storage/data_repository/data_repository.py index ba3b10c..7a060aa 100644 --- a/plesna/storage/repository/repository.py +++ b/plesna/storage/data_repository/data_repository.py @@ -3,7 +3,7 @@ import abc from plesna.models.storage import Partition, Schema, Table -class Repository: +class DataRepository: def __init__(self, id: str, name: str): self._id = id self._name = name diff --git a/plesna/storage/repository/fs_repository.py b/plesna/storage/data_repository/fs_data_repository.py similarity index 96% rename from plesna/storage/repository/fs_repository.py rename to plesna/storage/data_repository/fs_data_repository.py index f64d624..e0cc09d 100644 --- a/plesna/storage/repository/fs_repository.py +++ b/plesna/storage/data_repository/fs_data_repository.py @@ -3,8 +3,8 @@ from pathlib import Path from pydantic import BaseModel, computed_field from plesna.libs.string_tools import extract_values_from_pattern -from plesna.models.storage import Partition, Schema, Table -from plesna.storage.repository.repository import Repository +from plesna.models.storage import Schema, Table +from plesna.storage.data_repository.data_repository import DataRepository class FSTable(BaseModel): @@ -58,8 +58,8 @@ class FSRepositoryError(ValueError): pass -class FSRepository(Repository): - """Repository based on files tree structure +class FSDataRepository(DataRepository): + """Data Repository based on files tree structure - first level: schemas - second level: tables diff --git a/tests/dataplatform/test_dataplateform.py b/tests/dataplatform/test_dataplateform.py index e2b0ce3..f92a443 100644 --- a/tests/dataplatform/test_dataplateform.py +++ b/tests/dataplatform/test_dataplateform.py @@ -6,13 +6,13 @@ import pytest from plesna.dataplatform import DataPlateform from plesna.models.graphs import Edge, EdgeOnSet, Node from plesna.models.flux import Flux, Transformation -from plesna.storage.repository.fs_repository import FSRepository +from plesna.storage.data_repository.fs_data_repository import FSDataRepository FIXTURE_DIR = Path(__file__).parent.parent / Path("raw_datas") @pytest.fixture -def repository(tmp_path) -> FSRepository: +def repository(tmp_path) -> FSDataRepository: example_src = FIXTURE_DIR assert example_src.exists() @@ -24,11 +24,11 @@ def repository(tmp_path) -> FSRepository: silver_path = Path(tmp_path) / "silver" silver_path.mkdir() - return FSRepository("test", "test", tmp_path) + return FSDataRepository("test", "test", tmp_path) def test_add_repository( - repository: FSRepository, + repository: FSDataRepository, ): dp = DataPlateform() dp.add_repository(repository) @@ -39,7 +39,7 @@ def test_add_repository( @pytest.fixture -def copy_flux(repository: FSRepository) -> Flux: +def copy_flux(repository: FSDataRepository) -> Flux: raw_username = [repository.table("test-raw-username")] bronze_username = [repository.table("test-bronze-username")] @@ -62,7 +62,7 @@ def copy_flux(repository: FSRepository) -> Flux: @pytest.fixture -def foo_flux(repository: FSRepository) -> Flux: +def foo_flux(repository: FSDataRepository) -> Flux: src = [ repository.table("test-raw-username"), repository.table("test-raw-recovery"), @@ -84,7 +84,7 @@ def foo_flux(repository: FSRepository) -> Flux: return flux -def test_add_flux(repository: FSRepository, copy_flux: Flux): +def test_add_flux(repository: FSDataRepository, copy_flux: Flux): dataplatform = DataPlateform() dataplatform.add_repository(repository) @@ -99,7 +99,7 @@ def test_add_flux(repository: FSRepository, copy_flux: Flux): @pytest.fixture def dataplatform( - repository: FSRepository, + repository: FSDataRepository, foo_flux: Flux, copy_flux: Flux, ) -> DataPlateform: diff --git a/tests/storage/test_fs_repository.py b/tests/storage/test_fs_data_repository.py similarity index 92% rename from tests/storage/test_fs_repository.py rename to tests/storage/test_fs_data_repository.py index 434e30e..7d58ca9 100644 --- a/tests/storage/test_fs_repository.py +++ b/tests/storage/test_fs_data_repository.py @@ -3,7 +3,7 @@ from pathlib import Path import pytest -from plesna.storage.repository.fs_repository import FSRepository +from plesna.storage.data_repository.fs_data_repository import FSDataRepository FIXTURE_DIR = Path(__file__).parent.parent / Path("./raw_datas/") @@ -20,7 +20,7 @@ def location(tmp_path): def test_init(location): - repo = FSRepository("example", "example", location) + repo = FSDataRepository("example", "example", location) assert repo.ls() == [ "schema", ] @@ -44,8 +44,8 @@ def test_init(location): @pytest.fixture -def repository(location) -> FSRepository: - return FSRepository("repo_id", "example", location) +def repository(location) -> FSDataRepository: + return FSDataRepository("repo_id", "example", location) def test_list_schemas(repository):