From 4c056ddbc6a5ced310920f3449ffc68f52985bc1 Mon Sep 17 00:00:00 2001 From: yangxuan Date: Tue, 14 May 2024 14:31:36 +0800 Subject: [PATCH] enhance: Make bulk_writer's requirments optional See also: #2067 Signed-off-by: yangxuan --- examples/example_bulkwriter.py | 5 ++++- pymilvus/__init__.py | 22 ---------------------- pymilvus/bulk_writer/__init__.py | 28 ++++++++++++++++++++++++++++ pyproject.toml | 14 +++++++++----- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/examples/example_bulkwriter.py b/examples/example_bulkwriter.py index 161fe8899..aed1f414d 100644 --- a/examples/example_bulkwriter.py +++ b/examples/example_bulkwriter.py @@ -26,13 +26,16 @@ FieldSchema, CollectionSchema, DataType, Collection, utility, + BulkInsertState, +) + +from pymilvus.bulk_writer import ( LocalBulkWriter, RemoteBulkWriter, BulkFileType, bulk_import, get_import_progress, list_import_jobs, - BulkInsertState, ) # minio diff --git a/pymilvus/__init__.py b/pymilvus/__init__.py index a8201da42..80ffb2f49 100644 --- a/pymilvus/__init__.py +++ b/pymilvus/__init__.py @@ -10,22 +10,6 @@ # or implied. See the License for the specific language governing permissions and limitations under # the License. -from .bulk_writer.bulk_import import ( - bulk_import, - get_import_progress, - list_import_jobs, -) - -# bulk writer -from .bulk_writer.constants import ( - BulkFileType, -) -from .bulk_writer.local_bulk_writer import ( - LocalBulkWriter, -) -from .bulk_writer.remote_bulk_writer import ( - RemoteBulkWriter, -) from .client import __version__ from .client.abstract import AnnSearchRequest, Hit, Hits, RRFRanker, SearchResult, WeightedRanker from .client.asynch import SearchFuture @@ -143,12 +127,6 @@ "ResourceGroupInfo", "Connections", "IndexType", - "BulkFileType", - "LocalBulkWriter", - "RemoteBulkWriter", - "bulk_import", - "get_import_progress", - "list_import_jobs", "AnnSearchRequest", "RRFRanker", "WeightedRanker", diff --git a/pymilvus/bulk_writer/__init__.py b/pymilvus/bulk_writer/__init__.py index e69de29bb..507b0e02e 100644 --- a/pymilvus/bulk_writer/__init__.py +++ b/pymilvus/bulk_writer/__init__.py @@ -0,0 +1,28 @@ +from importlib.util import find_spec + +expected_pkgs = ["minio", "azure", "requests", "pyarrow"] + +missing = [pkg for pkg in expected_pkgs if find_spec(pkg) is None] + +if len(missing) > 0: + msg = f"Missing packages: {missing}. Please install bulk_writer by pip install pymilvus[bulk_writer] first" + raise ModuleNotFoundError(msg) + + +from .bulk_import import ( + bulk_import, + get_import_progress, + list_import_jobs, +) +from .constants import BulkFileType +from .local_bulk_writer import LocalBulkWriter +from .remote_bulk_writer import RemoteBulkWriter + +__all__ = [ + "BulkFileType", + "LocalBulkWriter", + "RemoteBulkWriter", + "bulk_import", + "get_import_progress", + "list_import_jobs", +] diff --git a/pyproject.toml b/pyproject.toml index 08d8858eb..134a2d79c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,10 +24,6 @@ dependencies=[ "ujson>=2.0.0", "pandas>=1.2.4", "numpy<1.25.0;python_version<='3.8'", - "requests", - "minio>=7.0.0", - "pyarrow>=12.0.0", - "azure-storage-blob", "milvus-lite>=2.4.0", ] @@ -42,6 +38,13 @@ dynamic = ["version"] "repository" = 'https://github.com/milvus-io/pymilvus' [project.optional-dependencies] +bulk_writer = [ + "requests", + "minio>=7.0.0", + "pyarrow>=12.0.0", + "azure-storage-blob", +] + model = [ "milvus-model>=0.1.0", ] @@ -51,7 +54,7 @@ test = [ "pytest-cov>=2.8.1", "pytest-timeout>=1.3.4", "grpcio-testing", - "ruff>=0.3.3", + "ruff>0.4.0", "black", ] @@ -113,6 +116,7 @@ lint.ignore = [ "PLR0915", # To many statements TODO "C901", # TODO "PYI041", # TODO + "E402", ] # Allow autofix for all enabled rules (when `--fix`) is provided.