def import_path_from_file(filename, as_list=False):
    '''Returns a tuple of the import path and root module directory for the
    supplied file.
    '''
    module_path = []
    basename = os.path.splitext(os.path.basename(filename))[0]
    if basename != '__init__':
        module_path.append(basename)

    dirname = os.path.dirname(filename)
    while os.path.isfile(os.path.join(dirname, '__init__.py')):
        dirname, tail = os.path.split(dirname)
        module_path.insert(0, tail)

    if as_list:
        return module_path, dirname
    return '.'.join(module_path), dirname
dataset/ETHPy150Open tweekmonster/moult/moult/utils.py/import_path_from_file/original