Przeglądaj źródła

Merge pull request #2577 from Avaiga/refactor/allow-passing-extra-package-to-check-dependencies

Refactor - Allow passing extra package name to check dependency
Đỗ Trường Giang 2 tygodni temu
rodzic
commit
236f8c64b0

+ 19 - 12
taipy/core/common/_check_dependencies.py → taipy/common/_check_dependencies.py

@@ -8,26 +8,33 @@
 # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 # specific language governing permissions and limitations under the License.
+
 from importlib import util
+from typing import Optional
 
 
-def _check_dependency_is_installed(module_name: str, package_name: str) -> None:
+def _check_dependency_is_installed(
+    module_name: str, package_name: str, extra_taipy_package_name: str, taipy_sublibrary: Optional[str] = None
+) -> None:
     """
-        Check if a package is installed.
+    Check if an extra package for taipy is installed.
+
+    Args:
+        module_name: Name of the taipy module importing the package.
+        package_name: Name of the package.
+        extra_taipy_package_name: Name of the extra taipy package.
+        taipy_sublibrary: Optional name of the taipy sublibrary.
 
-        Args:
-            module_name: Name of the taipy module importing the package.
-            package_name: Name of the package.
-    .
+    Raises:
+        RuntimeError: If the package is not installed.
     """
-    extras = {
-        "boto3": "s3",
-        "pymongo": "mongo",
-    }
+    if taipy_sublibrary is None:
+        taipy_sublibrary = "taipy"
+
     if not util.find_spec(package_name):
         raise RuntimeError(
-            f"Cannot use {module_name} as {package_name} package is not installed. Please install it  "
-            f"using `pip install taipy[{extras.get(package_name)}]`."
+            f"Cannot use {module_name} as {package_name} package is not installed. Please install it "
+            f"using `pip install {taipy_sublibrary}[{extra_taipy_package_name}]`."
         )
 
 

+ 1 - 1
taipy/common/_cli/_create_cli_factory.py

@@ -15,7 +15,7 @@ from typing import Type
 
 from taipy.common._cli._base_cli._abstract_cli import _AbstractCLI
 
-from ...core.common._check_dependencies import EnterpriseEditionUtils
+from .._check_dependencies import EnterpriseEditionUtils
 from ._create_cli import _CreateCLI
 
 

+ 1 - 1
taipy/core/_cli/_core_cli_factory.py

@@ -15,7 +15,7 @@ from typing import Type
 
 from taipy.common._cli._base_cli._abstract_cli import _AbstractCLI
 
-from ..common._check_dependencies import EnterpriseEditionUtils
+from ...common._check_dependencies import EnterpriseEditionUtils
 from ._core_cli import _CoreCLI
 
 

+ 1 - 1
taipy/core/_entity/_reload.py

@@ -12,8 +12,8 @@
 import functools
 from typing import Dict, Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager import _Manager
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ..notification import EventOperation, Notifier, _make_event
 

+ 2 - 1
taipy/core/_orchestrator/_orchestrator_factory.py

@@ -8,12 +8,13 @@
 # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 # specific language governing permissions and limitations under the License.
+
 import typing
 from typing import Optional, Type
 
 from taipy.common.config import Config
 
-from ..common._check_dependencies import EnterpriseEditionUtils
+from ...common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ..exceptions.exceptions import ModeNotAvailable, OrchestratorNotBuilt
 from ._abstract_orchestrator import _AbstractOrchestrator

+ 1 - 1
taipy/core/_version/_cli/_version_cli_factory.py

@@ -15,7 +15,7 @@ from typing import Type
 
 from taipy.common._cli._base_cli._abstract_cli import _AbstractCLI
 
-from ...common._check_dependencies import EnterpriseEditionUtils
+from ....common._check_dependencies import EnterpriseEditionUtils
 from ._version_cli import _VersionCLI
 
 

+ 1 - 1
taipy/core/_version/_version_manager_factory.py

@@ -12,9 +12,9 @@
 from functools import lru_cache
 from typing import Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager_factory import _ManagerFactory
 from ..common import _utils
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ._version_fs_repository import _VersionFSRepository
 from ._version_manager import _VersionManager
 

+ 1 - 1
taipy/core/cycle/_cycle_manager_factory.py

@@ -12,8 +12,8 @@
 from functools import lru_cache
 from typing import Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager_factory import _ManagerFactory
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ..cycle._cycle_manager import _CycleManager
 from ._cycle_fs_repository import _CycleFSRepository

+ 1 - 1
taipy/core/data/_data_manager_factory.py

@@ -12,8 +12,8 @@
 from functools import lru_cache
 from typing import Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager_factory import _ManagerFactory
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ._data_fs_repository import _DataFSRepository
 from ._data_manager import _DataManager

+ 2 - 3
taipy/core/data/aws_s3.py

@@ -13,7 +13,7 @@ from datetime import datetime, timedelta
 from importlib import util
 from typing import Any, Dict, List, Optional, Set
 
-from ..common._check_dependencies import _check_dependency_is_installed
+from ...common._check_dependencies import _check_dependency_is_installed
 
 if util.find_spec("boto3"):
     import boto3
@@ -69,7 +69,6 @@ class S3ObjectDataNode(DataNode):
     __AWS_S3_GET_OBJECT_PARAMETERS = "aws_s3_get_object_parameters"
     __AWS_S3_PUT_OBJECT_PARAMETERS = "aws_s3_put_object_parameters"
 
-
     _REQUIRED_PROPERTIES: List[str] = [
         __AWS_ACCESS_KEY_ID,
         __AWS_SECRET_ACCESS_KEY,
@@ -93,7 +92,7 @@ class S3ObjectDataNode(DataNode):
         editor_expiration_date: Optional[datetime] = None,
         properties: Optional[Dict] = None,
     ) -> None:
-        _check_dependency_is_installed("S3 Data Node", "boto3")
+        _check_dependency_is_installed("S3 Data Node", "boto3", "s3")
         if properties is None:
             properties = {}
         required = self._REQUIRED_PROPERTIES

+ 2 - 3
taipy/core/data/mongo.py

@@ -14,8 +14,8 @@ from importlib import util
 from inspect import isclass
 from typing import Any, Dict, List, Optional, Set, Tuple, Union
 
+from ...common._check_dependencies import _check_dependency_is_installed
 from .._version._version_manager_factory import _VersionManagerFactory
-from ..common._check_dependencies import _check_dependency_is_installed
 from ..common.scope import Scope
 
 if util.find_spec("pymongo"):
@@ -84,7 +84,7 @@ class MongoCollectionDataNode(DataNode):
         editor_expiration_date: Optional[datetime] = None,
         properties: Dict = None,
     ) -> None:
-        _check_dependency_is_installed("Mongo Data Node", "pymongo")
+        _check_dependency_is_installed("Mongo Data Node", "pymongo", "mongo")
         if properties is None:
             properties = {}
         required = self._REQUIRED_PROPERTIES
@@ -269,4 +269,3 @@ class MongoCollectionDataNode(DataNode):
             The document dictionary.
         """
         return document_object.__dict__
-

+ 1 - 1
taipy/core/job/_job_manager_factory.py

@@ -12,8 +12,8 @@
 from functools import lru_cache
 from typing import Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager_factory import _ManagerFactory
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ._job_fs_repository import _JobFSRepository
 from ._job_manager import _JobManager

+ 1 - 1
taipy/core/scenario/_scenario_manager_factory.py

@@ -12,8 +12,8 @@
 from functools import lru_cache
 from typing import Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager_factory import _ManagerFactory
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ._scenario_fs_repository import _ScenarioFSRepository
 from ._scenario_manager import _ScenarioManager

+ 1 - 1
taipy/core/sequence/_sequence_manager_factory.py

@@ -12,8 +12,8 @@
 from functools import lru_cache
 from typing import Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager_factory import _ManagerFactory
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ._sequence_manager import _SequenceManager
 

+ 1 - 1
taipy/core/submission/_submission_manager_factory.py

@@ -12,8 +12,8 @@
 from functools import lru_cache
 from typing import Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager_factory import _ManagerFactory
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ._submission_fs_repository import _SubmissionFSRepository
 from ._submission_manager import _SubmissionManager

+ 2 - 1
taipy/core/task/_task_manager_factory.py

@@ -8,11 +8,12 @@
 # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 # specific language governing permissions and limitations under the License.
+
 from functools import lru_cache
 from typing import Type
 
+from ...common._check_dependencies import EnterpriseEditionUtils
 from .._manager._manager_factory import _ManagerFactory
-from ..common._check_dependencies import EnterpriseEditionUtils
 from ..common._utils import _load_fct
 from ._task_fs_repository import _TaskFSRepository
 from ._task_manager import _TaskManager