Skip to content

Commit

Permalink
feat: dynamically import dependencies from path
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamir David authored and Tamir David committed Sep 3, 2024
1 parent 3995628 commit d39a9c3
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 20 deletions.
19 changes: 19 additions & 0 deletions initializer/lib_handling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import sys
import os
import importlib.util

# Constants
ODIGOS_PROTOBUF_PATH = '/var/odigos/python/google/protobuf'

def reorder_python_path():
paths_to_move = [path for path in sys.path if path.startswith('/var/odigos/')]
Expand Down Expand Up @@ -39,3 +44,17 @@ def reload_distro_modules() -> None:

if any(module.startswith(prefix) for prefix in needed_module_prefixes):
del sys.modules[module]


def import_module_from_path(unique_name, path):
''' Import a module from a file path and return it '''
if not os.path.isfile(path):
raise ImportError(f"Module '{unique_name}' not found at path '{path}'")

spec = importlib.util.spec_from_file_location(unique_name, path)

module = importlib.util.module_from_spec(spec)

spec.loader.exec_module(module)

return module
40 changes: 30 additions & 10 deletions opamp/anyvalue_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d39a9c3

Please sign in to comment.