def load_python_module(module_name, warn_only=False, remove_from_path_fn=None):
    check.str_param(module_name, 'module_name')
    check.bool_param(warn_only, 'warn_only')
    check.opt_callable_param(remove_from_path_fn, 'remove_from_path_fn')
    error = None
    remove_paths = (remove_from_path_fn() if remove_from_path_fn else [])
    remove_paths.insert(0, sys.path[0])
    with alter_sys_path(to_add=[], to_remove=remove_paths):
        try:
            module = importlib.import_module(module_name)
        except ImportError as ie:
            error = ie
    if error:
        try:
            module = importlib.import_module(module_name)
            if warn_only:
                warnings.warn('Module {module} was resolved using the working directory. The ability to load uninstalled modules from the working directory is deprecated and will be removed in a future release.  Please use the python-file based load arguments or install {module} to your python environment.'.format(module=module_name))
            else:
                six.raise_from(DagsterInvariantViolationError('Module {module} not found. Packages must be installed rather than relying on the working directory to resolve module loading.'.format(module=module_name)), error)
        except ImportError as ie:
            raise error
    return module
def load_python_module(module_name, warn_only=False, remove_from_path_fn=None):
    check.str_param(module_name, 'module_name')
    check.bool_param(warn_only, 'warn_only')
    check.opt_callable_param(remove_from_path_fn, 'remove_from_path_fn')
    error = None
    remove_paths = (remove_from_path_fn() if remove_from_path_fn else [])
    remove_paths.insert(0, sys.path[0])
    with alter_sys_path(to_add=[], to_remove=remove_paths):
        try:
            module = importlib.import_module(module_name)
        except ImportError as ie:
            error = ie
    if error:
        try:
            module = importlib.import_module(module_name)
            if warn_only:
                warnings.warn('Module {module} was resolved using the working directory. The ability to load uninstalled modules from the working directory is deprecated and will be removed in a future release.  Please use the python-file based load arguments or install {module} to your python environment.'.format(module=module_name))
            else:
                six.raise_from(DagsterInvariantViolationError('Module {module} not found. Packages must be installed rather than relying on the working directory to resolve module loading.'.format(module=module_name)), error)
        except ImportError as ie:
            raise error
    return module