33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""Site customization to ensure tests can import legacy underscore package
|
|
namespaced modules when running in editable install contexts.
|
|
|
|
This hack loads the local opengrowth_privacy_preserving_federated_ package
|
|
so imports like `from opengrowth_privacy_preserving_federated_ import ...`
|
|
work reliably regardless of packaging discovery.
|
|
"""
|
|
import importlib.util
|
|
import sys
|
|
import os
|
|
|
|
|
|
def _load_underscore_package_alias():
|
|
# Path to the local underscore package __init__.py
|
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
init_path = os.path.join(base_dir, "opengrowth_privacy_preserving_federated_", "__init__.py")
|
|
if not os.path.exists(init_path):
|
|
return
|
|
spec = importlib.util.spec_from_file_location(
|
|
"opengrowth_privacy_preserving_federated_", init_path
|
|
)
|
|
if spec and spec.loader:
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module) # type: ignore
|
|
sys.modules["opengrowth_privacy_preserving_federated_"] = module
|
|
|
|
|
|
try:
|
|
_load_underscore_package_alias()
|
|
except Exception:
|
|
# Do not fail test startup if this heuristic cannot be applied
|
|
pass
|