import importlib


def get_modules_by_filename(files):
    """Get modules from their code file."""
    modules = dict()
    for file in files:
        path = file.strip(".py")
        path = path.replace("/", ".")
        try:
            module = importlib.import_module(path)
        except ImportError as err:
            print(f"Bad import: module path {path} derived from {file}.")
            print(f"Exception: {err}")
            raise
        else:
            modules[file] = module
    return modules