Convert module-level optional dependency imports to lazy imports with @dependencies_required #3809
+99
−40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Multiple modules import optional dependencies (
torch,numpy,pandas,datasets,tqdm,rouge,tree_sitter) at module level, causingImportErrorwhen those packages aren't installed.Changes
camel/models/reward/skywork_model.py— Add@dependencies_required('torch', 'transformers')on__init__;torchalready deferred into methodscamel/datasets/static_dataset.py—HFDatasetvia try/except withNonefallback + isinstance guardcamel/datasets/base_generator.py— try/except fallback stub fortorch.utils.data.IterableDatasetcamel/benchmarks/ragbench.py—TYPE_CHECKINGforDatasettype hints, lazynumpy/datasetsin functions,@dependencies_required('datasets')on class initcamel/benchmarks/nexus.py—@dependencies_required('datasets', 'pandas'), lazypandas/datasets/tqdmcamel/benchmarks/apibank.py— Lazynumpy,rouge,tqdmcamel/benchmarks/apibench.py— Lazytree_sitter_python,tree_sitter,tqdmcamel/benchmarks/gaia.py,camel/datagen/evol_instruct/evol_instruct.py,camel/datagen/source2synth/data_processor.py,camel/runtimes/docker_runtime.py— Lazytqdmcamel/datagen/self_instruct/filter/filter_function.py— Lazyrougecamel/personas/persona_hub.py— LazynumpyPattern
Follows existing codebase convention:
All 66 subpackages import cleanly without optional deps installed.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.