takes in a path to a folder or file and return the module path and the path to the module

    the module is idenitified by
        the path being in os.path, e.g. if /Users/Projects/Python/ is in os.path,
        then folder_name = '/Users/PycharmProjects/pylabcontrol/pylabcontrol/scripts/script_dummy.pyc'
        returns '/Users/PycharmProjects/' as the path and pylabcontrol.scripts.script_dummy as the module

    Args:
        folder_name: path to a file of the form
        '/Users/PycharmProjects/pylabcontrol/pylabcontrol/scripts/script_dummy.pyc'

    Returns:
        module: a string of the form, e.g. pylabcontrol.scripts.script_dummy ...
        path: a string with the path to the module, e.g. /Users/PycharmProjects/

def module_name_from_path(folder_name, verbose=False):
    """
    takes in a path to a folder or file and return the module path and the path to the module

    the module is idenitified by
        the path being in os.path, e.g. if /Users/Projects/Python/ is in os.path,
        then folder_name = '/Users/PycharmProjects/pylabcontrol/pylabcontrol/scripts/script_dummy.pyc'
        returns '/Users/PycharmProjects/' as the path and pylabcontrol.scripts.script_dummy as the module

    Args:
        folder_name: path to a file of the form
        '/Users/PycharmProjects/pylabcontrol/pylabcontrol/scripts/script_dummy.pyc'

    Returns:
        module: a string of the form, e.g. pylabcontrol.scripts.script_dummy ...
        path: a string with the path to the module, e.g. /Users/PycharmProjects/

    """
    # strip off endings
    folder_name = folder_name.split('.pyc')[0]
    folder_name = folder_name.split('.py')[0]

    folder_name = os.path.normpath(folder_name)

    path = folder_name + '/'

    package = get_python_package(path)
    # path = folder_name
    module = []

    if verbose:
        print(('folder_name', folder_name))

    # os_sys_path = os.sys.path
    #
    # if os.path.normpath(path) in os_sys_path:
    #     if verbose:
    #         print('warning: path in sys.path!')
    #     os_sys_path.remove(os.path.normpath(path))
    #
    #
    # if verbose:
    #     for elem in os_sys_path:
    #
    #         print('os.sys.path', elem)



    while True:

        path = os.path.dirname(path)

        module.append(os.path.basename(path))
        if os.path.basename(path) == package:
            path = os.path.dirname(path)
            break

        # failed to identify the module
        if os.path.dirname(path) == path:
            path, module = None, None
            break

        if verbose:
            print(('path', path, os.path.dirname(path)))

        # if path == os.path.dirname(path):
        #     if verbose:
        #         print('break --  os.path.dirname(path)', os.path.dirname(path))
        #     # path, module = None, None
        #     break
        #

        if verbose:
            print(('module', module))


    # OLD START
    # while path not in os_sys_path:
    #     path = os.path.dirname(path)
    #
    #     if verbose:
    #         print('path', path, os.path.dirname(path))
    #
    #     if path == os.path.dirname(path):
    #         if verbose:
    #             print('break --  os.path.dirname(path)', os.path.dirname(path))
    #         # path, module = None, None
    #         break
    #     module.append(os.path.basename(path))
    #
    #     if verbose:
    #         print('module', module)
    # OLD END

    if verbose:
        print(('module', module))


    # module = module[:-1]
    # print('mod', module)
    # from the list construct the path like b26_toolkit.pylabcontrol.scripts and load it
    module.reverse()
    module = '.'.join(module)

    return module, path