Skip to content

Add import guards for optional dependencies #147

@nikos-livathinos

Description

@nikos-livathinos

Optional dependencies like boto3 are imported without guards (e.g. in /Users/nli/nikos/code/public_github/DS4SD/docling-eval/docling-eval/docling_eval/dataset_builders/dataset_builder.py). Therefore when a python venv without the optional packages is created, calling the docling-eval CLI causes a ModuleNotFoundError.

This is how to reproduce it:

Create venv and install docling-eval packages from pypi

python -m venv venv
. venv/bin/activate
pip install docling-eval

Try to run docling-eval CLI:

docling-eval --help

Traceback (most recent call last):
  File "/Users/nli/tmp/del/venv/bin/docling-eval", line 5, in <module>
    from docling_eval.cli.main import app
  File "/Users/nli/tmp/del/venv/lib/python3.13/site-packages/docling_eval/cli/main.py", line 48, in <module>
    from docling_eval.dataset_builders.cvat_dataset_builder import CvatDatasetBuilder
  File "/Users/nli/tmp/del/venv/lib/python3.13/site-packages/docling_eval/dataset_builders/cvat_dataset_builder.py", line 43, in <module>
    from docling_eval.dataset_builders.dataset_builder import BaseEvaluationDatasetBuilder
  File "/Users/nli/tmp/del/venv/lib/python3.13/site-packages/docling_eval/dataset_builders/dataset_builder.py", line 9, in <module>
    import ibm_boto3  # type: ignore
    ^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'ibm_boto3'

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions