Пример #1
0
def include_headers(headers_paths):
    """
    Includes the C++ headers to be declared before execution. Each
    header is also declared on the current running session.

    Args:
        headers_paths (str, iter): A string or an iterable (such as a
            list, set...) containing the paths to all necessary C++ headers as
            strings. This function accepts both paths to the headers
            themselves and paths to directories containing the headers.
    """
    global current_backend, includes_headers
    headers_to_include = set()

    if isinstance(headers_paths, str):
        headers_to_include.update(_get_paths_set_from_string(headers_paths))
    else:
        for path_string in headers_paths:
            headers_to_include.update(_get_paths_set_from_string(path_string))

    # If not on the local backend, distribute files to executors
    if not isinstance(current_backend, Local):
        current_backend.distribute_files(headers_to_include)

    # Declare the headers in ROOT
    Utils.declare_headers(headers_to_include)

    # Finally, add everything to the includes set
    includes_headers.update(headers_to_include)
Пример #2
0
        def spark_mapper(current_range):
            """
            Gets the paths to the file(s) in the current executor, then
            declares the headers found.

            Args:
                current_range (tuple): A pair that contains the starting and
                    ending values of the current range.

            Returns:
                function: The map function to be executed on each executor,
                complete with all headers needed for the analysis.
            """
            # Get and declare headers on each worker
            headers_on_executor = [
                SparkFiles.get(ntpath.basename(filepath))
                for filepath in includes_headers
            ]
            Utils.declare_headers(headers_on_executor)

            # Get and declare shared libraries on each worker
            shared_libs_on_ex = [
                SparkFiles.get(ntpath.basename(filepath))
                for filepath in includes_shared_libraries
            ]
            Utils.declare_shared_libraries(shared_libs_on_ex)

            return mapper(current_range)
Пример #3
0
    def test_single_header_declare(self):
        """
        Test case to check the working of 'declare_headers'
        function when a single header needs to be included.

        """
        Utils.declare_headers(["tests/unit/backend/test_headers/header1.hxx"])

        self.assertEqual(ROOT.f(1), True)
Пример #4
0
    def test_multiple_headers_declare(self):
        """'declare_headers' with multiple headers to be included."""
        Utils.declare_headers([
            "tests/unit/backend/test_headers/header2.hxx",
            "tests/unit/backend/test_headers/header3.hxx"
        ])

        self.assertEqual(ROOT.a(1), True)
        self.assertEqual(ROOT.f1(2), 2)
        self.assertEqual(ROOT.f2("myString"), "myString")
Пример #5
0
    def test_multiple_headers_declare(self):
        """
        Test case to check the working of 'declare_headers'
        function when multiple headers need to be included.

        """
        Utils.declare_headers([
            "tests/unit/backend/test_headers/header1.hxx",
            "tests/unit/backend/test_headers/header2.hxx"
        ])

        self.assertEqual(ROOT.f(1), True)
        self.assertEqual(ROOT.f1(2), 2)
        self.assertEqual(ROOT.f2("myString"), "myString")
Пример #6
0
def include_shared_libraries(shared_libraries_paths):
    """
    Includes the C++ shared libraries to be declared before execution.
    Each library is also declared on the current running session. If any pcm
    file is present in the same folder as the shared libraries, the function
    will try to retrieve them (and distribute them if working on a distributed
    backend).

    Args:
        shared_libraries_paths (str, iter): A string or an iterable (such as a
            list, set...) containing the paths to all necessary C++ shared
            libraries as strings. This function accepts both paths to the
            libraries themselves and paths to directories containing the
            libraries.
    """
    global current_backend, includes_shared_libraries
    libraries_to_include = set()
    pcm_to_include = set()

    if isinstance(shared_libraries_paths, str):
        pcm_to_include, libraries_to_include = _check_pcm_in_library_path(
            shared_libraries_paths
        )
    else:
        for path_string in shared_libraries_paths:
            pcm, libraries = _check_pcm_in_library_path(
                path_string
            )
            libraries_to_include.update(libraries)
            pcm_to_include.update(pcm)

    # If not on the local backend, distribute files to executors
    if not isinstance(current_backend, Local):
        current_backend.distribute_files(libraries_to_include)
        current_backend.distribute_files(pcm_to_include)

    # Declare the shared libraries in ROOT
    Utils.declare_shared_libraries(libraries_to_include)

    # Finally, add everything to the includes set
    includes_shared_libraries.update(includes_shared_libraries)
Пример #7
0
    def test_single_header_declare(self):
        """'declare_headers' with a single header to be included."""
        Utils.declare_headers(["tests/unit/backend/test_headers/header1.hxx"])

        self.assertEqual(ROOT.f(1), True)