Skip to content

fix(loading): forward download_config to LocalEvaluationModuleFactory#755

Open
xodn348 wants to merge 1 commit intohuggingface:mainfrom
xodn348:fix/local-download-config-passthrough
Open

fix(loading): forward download_config to LocalEvaluationModuleFactory#755
xodn348 wants to merge 1 commit intohuggingface:mainfrom
xodn348:fix/local-download-config-passthrough

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented May 4, 2026

Summary

evaluation_module_factory has two code paths for loading a local metric script (lines 619–621 and 625–627 of src/evaluate/loading.py). Both paths construct a LocalEvaluationModuleFactory but omit the download_config argument that the caller explicitly passed in. As a result, the factory falls back to a blank DownloadConfig() for any secondary downloads it performs (e.g. fetching external requirements files declared in the script's _HF_REQUIRES_PYTHON imports). This silently ignores caller-supplied settings such as local_files_only=True, cache_dir, or custom proxies, which can cause unexpected network requests or connection failures in air-gapped / offline environments.

The fix is a two-line change: pass download_config=download_config to the LocalEvaluationModuleFactory constructor in both branches. The class already accepts and uses the parameter — it was just never forwarded from evaluation_module_factory.

Two regression tests were added that spy on LocalEvaluationModuleFactory.__init__ (via unittest.mock.patch(wraps=…)) to assert the download_config object is forwarded for both the direct-.py-path branch and the directory-path branch.

Issue

Fixes #709

Local verification

$ cd /tmp/evaluate
$ python -m pytest tests/test_load.py::ModuleFactoryTest::test_LocalMetricModuleFactory \
    tests/test_load.py::ModuleFactoryTest::test_evaluation_module_factory_local_py_path_passes_download_config \
    tests/test_load.py::ModuleFactoryTest::test_evaluation_module_factory_local_dir_path_passes_download_config \
    -v

============================= test session starts ==============================
platform linux -- Python 3.11.15, pytest-9.0.3, pluggy-1.6.0
collecting ... collected 3 items

tests/test_load.py::ModuleFactoryTest::test_LocalMetricModuleFactory PASSED [ 33%]
tests/test_load.py::ModuleFactoryTest::test_evaluation_module_factory_local_py_path_passes_download_config PASSED [ 66%]
tests/test_load.py::ModuleFactoryTest::test_evaluation_module_factory_local_dir_path_passes_download_config PASSED [100%]

============================== 3 passed in 1.52s ==============================
=== LOCAL_TEST_PASSED ===

(The other tests in test_load.py require connectivity to huggingface.co and fail with ConnectionError 403 in this offline environment; they fail identically on the unmodified main branch.)

Risk

The change is a pure addition of a previously-missing argument that was already declared in LocalEvaluationModuleFactory.__init__. It does not alter the existing download_config object, does not change the fallback default for callers that do not pass one (they still get DownloadConfig() via the or DownloadConfig() guard in the factory constructor), and has no effect on Hub-based loading paths. The only behaviour change is that callers who do pass a download_config will now have it respected for local scripts — closing a silent data-loss bug.

When evaluation_module_factory resolves a local .py path or a directory
containing a metric script, it creates a LocalEvaluationModuleFactory
without passing the caller's download_config.  This means extra-module
downloads (e.g. a requirements file fetched from a remote URL) silently
use a default DownloadConfig, ignoring settings such as local_files_only,
cache_dir, or proxies that the caller explicitly supplied.

Pass download_config to both LocalEvaluationModuleFactory call sites.
Also add regression tests that spy on the factory constructor to verify
the argument is forwarded in both the .py-path branch and the
directory-path branch.

Fixes huggingface#709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DownloadConfig is not passed to LocalEvaluationModuleFactory when loading from local file, causing uncontrollable download behavior

1 participant