From 9f858b19f7116d6e213e17f402b7c3f971c40ae5 Mon Sep 17 00:00:00 2001 From: Jihyeon Yi Date: Thu, 18 Apr 2024 16:01:18 +0900 Subject: [PATCH] Handling tfds import part to prevent cli error when installing datumaro with default option only (#1454) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Summary This is a bug fix for the issue #1444 ### How to test 1. uninstall tfds if it exists. 2. install datumaro with default option (`pip install datumaro[default]` or `pip install -e .[default]`) 3. run `datum --version` or `datum --help` ### Checklist - [ ] I have added unit tests to cover my changes.​ - [ ] I have added integration tests to cover my changes.​ - [x] I have added the description of my changes into [CHANGELOG](https://github.com/openvinotoolkit/datumaro/blob/develop/CHANGELOG.md).​ - [ ] I have updated the [documentation](https://github.com/openvinotoolkit/datumaro/tree/develop/docs) accordingly ### License - [x] I submit _my code changes_ under the same [MIT License](https://github.com/openvinotoolkit/datumaro/blob/develop/LICENSE) that covers the project. Feel free to contact the maintainers if that's a concern. - [x] I have updated the license header for each file (see an example below). ```python # Copyright (C) 2024 Intel Corporation # # SPDX-License-Identifier: MIT ``` --- CHANGELOG.md | 2 ++ src/datumaro/components/extractor_tfds.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca7ffc9719..3665c7e43f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 () ### Bug fixes +- Fix CLI error occurring when installed with default option only + (, ) - Relax Pillow dependency constraint () - Modify Numpy dependency constraint diff --git a/src/datumaro/components/extractor_tfds.py b/src/datumaro/components/extractor_tfds.py index ba47d0fe89..47334ea6f2 100644 --- a/src/datumaro/components/extractor_tfds.py +++ b/src/datumaro/components/extractor_tfds.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2023 Intel Corporation +# Copyright (C) 2024 Intel Corporation # # SPDX-License-Identifier: MIT @@ -30,23 +30,23 @@ from datumaro.components.annotation import AnnotationType, Bbox, Label, LabelCategories from datumaro.components.dataset_base import CategoriesInfo, DatasetInfo, DatasetItem, IDataset from datumaro.components.media import Image, MediaElement +from datumaro.util.import_util import lazy_import from datumaro.util.tf_util import import_tf TFDS_EXTRACTOR_AVAILABLE = True if find_spec("tensorflow_datasets") is not None else False -if TYPE_CHECKING: +if TFDS_EXTRACTOR_AVAILABLE: try: - tf = import_tf() - import tensorflow_datasets as tfds + if TYPE_CHECKING: + tf = import_tf() + import tensorflow_datasets as tfds + else: + tfds = lazy_import("tensorflow_datasets") except ImportError: log.debug( "Unable to import TensorFlow or TensorFlow Datasets. " "Dataset downloading via TFDS is disabled." ) -else: - from datumaro.util.import_util import lazy_import - - tfds = lazy_import("tensorflow_datasets") @frozen(kw_only=True)