diff --git a/pyproject.toml b/pyproject.toml index 6b89a8e3a..bb1e176a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,14 +52,13 @@ gcsfs = { version = ">= 2023.4.0", optional = true } s3fs = { version = ">= 2023.4.0", optional = true } adlfs = { version = ">= 2023.4.0", optional = true } kfp = { version = ">= 1.8.19, < 2", optional = true } -kubernetes = { version = ">= 18.20.0", optional = true } pandas = { version = ">= 1.3.5", optional = true } [tool.poetry.extras] aws = ["fsspec", "s3fs"] azure = ["fsspec", "adlfs"] gcp = ["fsspec", "gcsfs"] -pipelines = ["kfp", "kubernetes"] +kfp = ["kfp"] [tool.poetry.group.test.dependencies] pre-commit = "^3.1.1" diff --git a/src/fondant/compiler.py b/src/fondant/compiler.py index 51179b284..52924a056 100644 --- a/src/fondant/compiler.py +++ b/src/fondant/compiler.py @@ -226,7 +226,7 @@ def _resolve_imports(self): self.kfp = kfp except ImportError: msg = """You need to install kfp to use the Kubeflow compiler,\n - you can install it with `pip install --extras pipelines`""" + you can install it with `pip install fondant[kfp]`""" raise ImportError( msg, ) diff --git a/src/fondant/import_utils.py b/src/fondant/import_utils.py deleted file mode 100644 index 8619b4aa1..000000000 --- a/src/fondant/import_utils.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Import utils.""" -import importlib.metadata -import importlib.util -import logging -import sys -from pathlib import Path - -logger = logging.getLogger(__name__) - -KFP_IMPORT_ERROR = """ -`{0}` requires the kubeflow pipelines (kfp) library but it was not found in your environment. -Please install fondant using pip install fondant [pipelines]. -""" - - -def is_package_available(package_name: str, import_error_msg: str) -> bool: - """ - Function that checks if a given package is available - Args: - package_name (str): the name of the package - import_error_msg (str): the error message to return if the package is not found - Returns: - bool: check if package is available. - """ - package_available = importlib.util.find_spec(package_name) is not None - - try: - package_version = importlib.metadata.version(package_name) - logger.debug(f"Successfully imported {package_name} version {package_version}") - except importlib.metadata.PackageNotFoundError: - package_available = False - - if package_available: - return package_available - - raise ModuleNotFoundError(import_error_msg.format(Path(sys.argv[0]).stem)) - - -def is_kfp_available(): - """Check if 'kfp' is available.""" - return is_package_available("kfp", KFP_IMPORT_ERROR) diff --git a/src/fondant/runner.py b/src/fondant/runner.py index 75b75aee4..4ff924a8e 100644 --- a/src/fondant/runner.py +++ b/src/fondant/runner.py @@ -48,7 +48,7 @@ def _resolve_imports(self): self.kfp = kfp except ImportError: msg = """You need to install kfp to use the Kubeflow compiler,\n - you can install it with `pip install --extras pipelines`""" + you can install it with `pip install fondant[kfp]`""" raise ImportError( msg, ) diff --git a/tests/test_import_utils.py b/tests/test_import_utils.py deleted file mode 100644 index 363560d35..000000000 --- a/tests/test_import_utils.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Test scripts for import module functionality.""" -import importlib.metadata -from unittest import mock - -import pytest -from fondant.import_utils import ( - is_kfp_available, - is_package_available, -) - - -@pytest.mark.parametrize( - ("package_name", "import_error_msg", "expected_result"), - [ - ("jsonschema", "jsonschema package is not installed.", True), - ( - "nonexistentpackage", - "This package does not exist.", - pytest.raises(ModuleNotFoundError), - ), - ], -) -def test_is_package_available(package_name, import_error_msg, expected_result): - """Test function for is_package_available().""" - if isinstance(expected_result, bool): - assert is_package_available(package_name, import_error_msg) == expected_result - else: - with expected_result: - is_package_available(package_name, import_error_msg) - - -@mock.patch("importlib.util.find_spec", return_value="package") -@mock.patch("importlib.metadata.version", return_value="0.1.0") -def test_available_packages(importlib_util_find_spec, importlib_metadata_version): - """Test that is_datasets_available is not False when the packages are available.""" - assert is_kfp_available() is not False - - -@mock.patch( - "importlib.metadata.version", - side_effect=importlib.metadata.PackageNotFoundError, -) -def test_unavailable_packages(mock_importlib_metadata_version): - """Test that importing fondant related packages returns valid errors when not available.""" - with pytest.raises(ModuleNotFoundError): - is_kfp_available()