Changeset View
Changeset View
Standalone View
Standalone View
python_modules/dagster/dagster/core/code_pointer.py
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | def rebase_file(relative_path_in_file, file_path_resides_in): | ||||
) | ) | ||||
def load_python_file(python_file, working_directory): | def load_python_file(python_file, working_directory): | ||||
""" | """ | ||||
Takes a path to a python file and returns a loaded module | Takes a path to a python file and returns a loaded module | ||||
""" | """ | ||||
check.str_param(python_file, "python_file") | check.str_param(python_file, "python_file") | ||||
# First verify that the file exists | |||||
os.stat(python_file) | |||||
module_name = os.path.splitext(os.path.basename(python_file))[0] | module_name = os.path.splitext(os.path.basename(python_file))[0] | ||||
cwd = sys.path[0] | cwd = sys.path[0] | ||||
if working_directory: | if working_directory: | ||||
try: | try: | ||||
with alter_sys_path(to_add=[working_directory], to_remove=[cwd]): | with alter_sys_path(to_add=[working_directory], to_remove=[cwd]): | ||||
return import_module_from_path(module_name, python_file) | return import_module_from_path(module_name, python_file) | ||||
except ImportError as ie: | except ImportError as ie: | ||||
msg = get_import_error_message(ie) | msg = get_import_error_message(ie) | ||||
▲ Show 20 Lines • Show All 319 Lines • Show Last 20 Lines |