Skip to content

Commit

Permalink
Refresh sys.path upon loading a new module
Browse files Browse the repository at this point in the history
  • Loading branch information
dongreenberg committed May 21, 2024
1 parent c64663d commit 9876f2e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions runhouse/resources/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import inspect
import logging
import os
import site
import sys
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
Expand Down Expand Up @@ -368,8 +369,13 @@ def _get_obj_from_pointers(module_path, module_name, obj_name, reload=True):
"""Helper method to load a class or function from a module path, module name, and class name."""
if module_path:
abs_path = str((Path.home() / module_path).expanduser().resolve())
sys.path.insert(0, abs_path)
logger.debug(f"Appending {module_path} to sys.path")
if abs_path not in sys.path:
sys.path.insert(0, abs_path)
logger.debug(f"Appending {module_path} to sys.path")

# This updates the sys.path with any new paths that have been added since the last time we imported
# e.g. if the user ran cluster.run(["pip install my_package"]) since this env was created.
importlib.reload(site)

if module_name in obj_store.imported_modules and reload:
importlib.invalidate_caches()
Expand Down

0 comments on commit 9876f2e

Please sign in to comment.