Ver Fonte

refactor: move common attribute of file-based data node to _FileDataNodeMixin

trgiangdo há 1 ano atrás
pai
commit
ccf8ca477f

+ 14 - 0
taipy/core/data/_abstract_file.py

@@ -45,6 +45,9 @@ class _FileDataNodeMixin(object):
         if not self._path:
             self._path = self._build_path(self.storage_type())
 
+        properties[self._IS_GENERATED_KEY] = self._is_generated
+        properties[self._PATH_KEY] = self._path
+
     def _write_default_data(self, default_value: Any):
         if default_value is not None and not os.path.exists(self._path):
             self._write(default_value)
@@ -67,6 +70,17 @@ class _FileDataNodeMixin(object):
     def is_generated(self) -> bool:
         return self._is_generated
 
+    @property  # type: ignore
+    @_self_reload(DataNode._MANAGER_NAME)
+    def path(self) -> Any:
+        return self._path
+
+    @path.setter
+    def path(self, value):
+        self._path = value
+        self.properties[self._PATH_KEY] = value
+        self.properties[self._IS_GENERATED_KEY] = False
+
     @classmethod
     def storage_type(cls) -> str:
         raise NotImplementedError

+ 0 - 14
taipy/core/data/csv.py

@@ -18,7 +18,6 @@ import pandas as pd
 
 from taipy.config.common.scope import Scope
 
-from .._entity._reload import _self_reload
 from .._version._version_manager_factory import _VersionManagerFactory
 from ..job.job_id import JobId
 from ._abstract_file import _FileDataNodeMixin
@@ -99,8 +98,6 @@ class CSVDataNode(DataNode, _FileDataNodeMixin, _TabularDataNodeMixin):
         default_value = properties.pop(self._DEFAULT_DATA_KEY, None)
         _FileDataNodeMixin.__init__(self, properties)
         _TabularDataNodeMixin.__init__(self, **properties)
-        properties[self._IS_GENERATED_KEY] = self._is_generated
-        properties[self._PATH_KEY] = self._path
 
         DataNode.__init__(
             self,
@@ -137,17 +134,6 @@ class CSVDataNode(DataNode, _FileDataNodeMixin, _TabularDataNodeMixin):
     def storage_type(cls) -> str:
         return cls.__STORAGE_TYPE
 
-    @property  # type: ignore
-    @_self_reload(DataNode._MANAGER_NAME)
-    def path(self):
-        return self._path
-
-    @path.setter
-    def path(self, value):
-        self._path = value
-        self.properties[self._PATH_KEY] = value
-        self.properties[self._IS_GENERATED_KEY] = False
-
     def _read(self):
         if self.properties[self._EXPOSED_TYPE_PROPERTY] == self._EXPOSED_TYPE_PANDAS:
             return self._read_as_pandas_dataframe()

+ 0 - 14
taipy/core/data/excel.py

@@ -18,7 +18,6 @@ from openpyxl import load_workbook
 
 from taipy.config.common.scope import Scope
 
-from .._entity._reload import _self_reload
 from .._version._version_manager_factory import _VersionManagerFactory
 from ..exceptions.exceptions import ExposedTypeLengthMismatch, NonExistingExcelSheet, SheetNameLengthMismatch
 from ..job.job_id import JobId
@@ -101,8 +100,6 @@ class ExcelDataNode(DataNode, _FileDataNodeMixin, _TabularDataNodeMixin):
         default_value = properties.pop(self._DEFAULT_DATA_KEY, None)
         _FileDataNodeMixin.__init__(self, properties)
         _TabularDataNodeMixin.__init__(self, **properties)
-        properties[self._IS_GENERATED_KEY] = self._is_generated
-        properties[self._PATH_KEY] = self._path
 
         DataNode.__init__(
             self,
@@ -135,17 +132,6 @@ class ExcelDataNode(DataNode, _FileDataNodeMixin, _TabularDataNodeMixin):
             }
         )
 
-    @property  # type: ignore
-    @_self_reload(DataNode._MANAGER_NAME)
-    def path(self):
-        return self._path
-
-    @path.setter
-    def path(self, value):
-        self._path = value
-        self.properties[self._PATH_KEY] = value
-        self.properties[self._IS_GENERATED_KEY] = False
-
     @classmethod
     def storage_type(cls) -> str:
         return cls.__STORAGE_TYPE

+ 0 - 16
taipy/core/data/json.py

@@ -60,9 +60,6 @@ class JSONDataNode(DataNode, _FileDataNodeMixin):
     """
 
     __STORAGE_TYPE = "json"
-    _DEFAULT_DATA_KEY = "default_data"
-    _DEFAULT_PATH_KEY = "default_path"
-    _PATH_KEY = "path"
     __ENCODING_KEY = "encoding"
     _ENCODER_KEY = "encoder"
     _DECODER_KEY = "decoder"
@@ -94,8 +91,6 @@ class JSONDataNode(DataNode, _FileDataNodeMixin):
 
         default_value = properties.pop(self._DEFAULT_DATA_KEY, None)
         _FileDataNodeMixin.__init__(self, properties)
-        properties[self._IS_GENERATED_KEY] = self._is_generated
-        properties[self._PATH_KEY] = self._path
 
         DataNode.__init__(
             self,
@@ -135,17 +130,6 @@ class JSONDataNode(DataNode, _FileDataNodeMixin):
     def storage_type(cls) -> str:
         return cls.__STORAGE_TYPE
 
-    @property  # type: ignore
-    @_self_reload(DataNode._MANAGER_NAME)
-    def path(self):
-        return self._path
-
-    @path.setter
-    def path(self, value):
-        self._path = value
-        self.properties[self._PATH_KEY] = value
-        self.properties[self._IS_GENERATED_KEY] = False
-
     @property  # type: ignore
     @_self_reload(DataNode._MANAGER_NAME)
     def encoder(self):

+ 0 - 14
taipy/core/data/parquet.py

@@ -18,7 +18,6 @@ import pandas as pd
 
 from taipy.config.common.scope import Scope
 
-from .._entity._reload import _self_reload
 from .._version._version_manager_factory import _VersionManagerFactory
 from ..exceptions.exceptions import UnknownCompressionAlgorithm, UnknownParquetEngine
 from ..job.job_id import JobId
@@ -136,8 +135,6 @@ class ParquetDataNode(DataNode, _FileDataNodeMixin, _TabularDataNodeMixin):
         default_value = properties.pop(self._DEFAULT_DATA_KEY, None)
         _FileDataNodeMixin.__init__(self, properties)
         _TabularDataNodeMixin.__init__(self, **properties)
-        properties[self._IS_GENERATED_KEY] = self._is_generated
-        properties[self._PATH_KEY] = self._path
 
         DataNode.__init__(
             self,
@@ -178,17 +175,6 @@ class ParquetDataNode(DataNode, _FileDataNodeMixin, _TabularDataNodeMixin):
     def storage_type(cls) -> str:
         return cls.__STORAGE_TYPE
 
-    @property  # type: ignore
-    @_self_reload(DataNode._MANAGER_NAME)
-    def path(self):
-        return self._path
-
-    @path.setter
-    def path(self, value):
-        self._path = value
-        self.properties[self._PATH_KEY] = value
-        self.properties[self._IS_GENERATED_KEY] = False
-
     def _read(self):
         return self.read_with_kwargs()
 

+ 1 - 15
taipy/core/data/pickle.py

@@ -11,11 +11,10 @@
 
 import pickle
 from datetime import datetime, timedelta
-from typing import Any, List, Optional, Set
+from typing import List, Optional, Set
 
 from taipy.config.common.scope import Scope
 
-from .._entity._reload import _self_reload
 from .._version._version_manager_factory import _VersionManagerFactory
 from ._abstract_file import _FileDataNodeMixin
 from .data_node import DataNode
@@ -81,8 +80,6 @@ class PickleDataNode(DataNode, _FileDataNodeMixin):
 
         default_value = properties.pop(self._DEFAULT_DATA_KEY, None)
         _FileDataNodeMixin.__init__(self, properties)
-        properties[self._IS_GENERATED_KEY] = self._is_generated
-        properties[self._PATH_KEY] = self._path
 
         DataNode.__init__(
             self,
@@ -116,17 +113,6 @@ class PickleDataNode(DataNode, _FileDataNodeMixin):
     def storage_type(cls) -> str:
         return cls.__STORAGE_TYPE
 
-    @property  # type: ignore
-    @_self_reload(DataNode._MANAGER_NAME)
-    def path(self) -> Any:
-        return self._path
-
-    @path.setter
-    def path(self, value):
-        self._path = value
-        self.properties[self._PATH_KEY] = value
-        self.properties[self._IS_GENERATED_KEY] = False
-
     def _read(self):
         with open(self._path, "rb") as pf:
             return pickle.load(pf)