def _consolidate_package_modules(cmake_source_dir, packages, package_dir, py_modules, package_data, hide_listing):
    'This function consolidates packages having modules located in\n    both the source tree and the CMake install tree into one location.\n\n    The one location is the CMake install tree\n    (see :func:`.constants.CMAKE_INSTALL_DIR()`).\n\n    Why ? This is a necessary evil because ``Setuptools`` keeps track of\n    packages and modules files to install using a dictionary of lists where\n    the key are package names (e.g ``foo.bar``) and the values are lists of\n    module files (e.g ``[\'__init__.py\', \'baz.py\']``. Since this doesn\'t allow\n    to "split" files associated with a given module in multiple location, one\n    location is selected, and files are copied over.\n\n    How? It currently searches for modules across both locations using\n    the :class:`.utils.PythonModuleFinder`. then with the help\n    of :func:`_package_data_contain_module`, it identifies which\n    one are either already included or missing from the distribution.\n\n    Once a module has been identified as ``missing``, it is both copied\n    into the :func:`.constants.CMAKE_INSTALL_DIR()` and added to the\n    ``package_data`` dictionary so that it can be considered by\n    the upstream setup function.\n    '
    try:
        modules = PythonModuleFinder(packages, package_dir, py_modules, alternative_build_base=CMAKE_INSTALL_DIR()).find_all_modules()
    except DistutilsError as msg:
        raise SystemExit('error: {}'.format(str(msg)))
    print('')
    for entry in modules:
        if _package_data_contain_module(entry, package_data):
            continue
        (package, _, src_module_file) = entry
        if os.path.exists(src_module_file):
            dest_module_file = os.path.join(CMAKE_INSTALL_DIR(), src_module_file)
            _copy_file(src_module_file, dest_module_file, hide_listing)
        package_parts = []
        if cmake_source_dir:
            package_parts = cmake_source_dir.split(os.path.sep)
        package_parts += package.split('.')
        stripped_module_file = strip_package(package_parts, src_module_file)
        try:
            package_data[package].append(stripped_module_file)
        except KeyError:
            package_data[package] = [stripped_module_file]
This function consolidates packages having modules located in
both the source tree and the CMake install tree into one location.

The one location is the CMake install tree
(see :func:`.constants.CMAKE_INSTALL_DIR()`).

Why ? This is a necessary evil because ``Setuptools`` keeps track of
packages and modules files to install using a dictionary of lists where
the key are package names (e.g ``foo.bar``) and the values are lists of
module files (e.g ``['__init__.py', 'baz.py']``. Since this doesn't allow
to "split" files associated with a given module in multiple location, one
location is selected, and files are copied over.

How? It currently searches for modules across both locations using
the :class:`.utils.PythonModuleFinder`. then with the help
of :func:`_package_data_contain_module`, it identifies which
one are either already included or missing from the distribution.

Once a module has been identified as ``missing``, it is both copied
into the :func:`.constants.CMAKE_INSTALL_DIR()` and added to the
``package_data`` dictionary so that it can be considered by
the upstream setup function.
def _consolidate_package_modules(cmake_source_dir, packages, package_dir, py_modules, package_data, hide_listing):
    'This function consolidates packages having modules located in\n    both the source tree and the CMake install tree into one location.\n\n    The one location is the CMake install tree\n    (see :func:`.constants.CMAKE_INSTALL_DIR()`).\n\n    Why ? This is a necessary evil because ``Setuptools`` keeps track of\n    packages and modules files to install using a dictionary of lists where\n    the key are package names (e.g ``foo.bar``) and the values are lists of\n    module files (e.g ``[\'__init__.py\', \'baz.py\']``. Since this doesn\'t allow\n    to "split" files associated with a given module in multiple location, one\n    location is selected, and files are copied over.\n\n    How? It currently searches for modules across both locations using\n    the :class:`.utils.PythonModuleFinder`. then with the help\n    of :func:`_package_data_contain_module`, it identifies which\n    one are either already included or missing from the distribution.\n\n    Once a module has been identified as ``missing``, it is both copied\n    into the :func:`.constants.CMAKE_INSTALL_DIR()` and added to the\n    ``package_data`` dictionary so that it can be considered by\n    the upstream setup function.\n    '
    try:
        modules = PythonModuleFinder(packages, package_dir, py_modules, alternative_build_base=CMAKE_INSTALL_DIR()).find_all_modules()
    except DistutilsError as msg:
        raise SystemExit('error: {}'.format(str(msg)))
    print()
    for entry in modules:
        if _package_data_contain_module(entry, package_data):
            continue
        (package, _, src_module_file) = entry
        if os.path.exists(src_module_file):
            dest_module_file = os.path.join(CMAKE_INSTALL_DIR(), src_module_file)
            _copy_file(src_module_file, dest_module_file, hide_listing)
        package_parts = []
        if cmake_source_dir:
            package_parts = cmake_source_dir.split(os.path.sep)
        package_parts += package.split('.')
        stripped_module_file = strip_package(package_parts, src_module_file)
        try:
            package_data[package].append(stripped_module_file)
        except KeyError:
            package_data[package] = [stripped_module_file]