# Path: pyoptix/utils.py
# def glob_recursive(path, pattern):
#     matches = []
#     for dirpath, dirnames, filenames in os.walk(path):
#         for filename in fnmatch.filter(filenames, pattern):
#             matches.append(os.path.join(dirpath, filename))
#     return matches
# 
# def find_sub_path(sub_path, search_paths):
#     import os.path
# 
#     for search_path in search_paths:
#         path = os.path.join(search_path, sub_path)
#         if os.path.exists(path):
#             return path
# 
#     raise ValueError('Sub-path not found in searched paths: {0}'.format(sub_path))


import logging
import re
import os
import sys
import shlex
import fnmatch
from stat import S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, S_IWOTH, S_IXUSR, S_IXGRP, S_IXOTH
from subprocess import check_call, CalledProcessError
from pyoptix.utils import glob_recursive, find_sub_path
    from configparser import ConfigParser
    from ConfigParser import SafeConfigParser as ConfigParser
            bash_command += " ".join(cls.extra_compile_args)
            bash_command += " -ptx"
            if cls.use_fast_math:
                bash_command += " --use_fast_math"
            for include_path in cls._program_directories:
                if os.path.exists(include_path):
                    bash_command += " -I=" + include_path
            bash_command += " " + source_path
            bash_command += " -o=" + output_ptx_path
            logger.debug("Executing: {0}".format(bash_command))
            try:
                check_call(shlex.split(bash_command))
            except CalledProcessError as e:
                logger.error(e)

            if not os.path.exists(output_ptx_path):
                logger.error("Could not compile {0}".format(source_path))
                raise RuntimeError("Could not compile {0}".format(source_path))
            else:
                os.chmod(output_ptx_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)

        else:
            logger.debug("No compiling required for {0}".format(source_path))
            is_compiled = False

        return output_ptx_path, is_compiled

    @classmethod
    def compile_all_directories(cls, source_extension='.cu'):
        for program_dir in cls._program_directories:

# Path: pyoptix/utils.py
# def glob_recursive(path, pattern):
#     matches = []
#     for dirpath, dirnames, filenames in os.walk(path):
#         for filename in fnmatch.filter(filenames, pattern):
#             matches.append(os.path.join(dirpath, filename))
#     return matches
# 
# def find_sub_path(sub_path, search_paths):
#     import os.path
# 
#     for search_path in search_paths:
#         path = os.path.join(search_path, sub_path)
#         if os.path.exists(path):
#             return path
# 
#     raise ValueError('Sub-path not found in searched paths: {0}'.format(sub_path))


# Path: pyoptix/compiler.py
import logging
import re
import os
import sys
import shlex
import fnmatch
from stat import S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, S_IWOTH, S_IXUSR, S_IXGRP, S_IXOTH
from subprocess import check_call, CalledProcessError
from pyoptix.utils import glob_recursive, find_sub_path
    from configparser import ConfigParser
    from ConfigParser import SafeConfigParser as ConfigParser

            bash_command += " ".join(cls.extra_compile_args)
            bash_command += " -ptx"
            if cls.use_fast_math:
                bash_command += " --use_fast_math"
            for include_path in cls._program_directories:
                if os.path.exists(include_path):
                    bash_command += " -I=" + include_path
            bash_command += " " + source_path
            bash_command += " -o=" + output_ptx_path
            logger.debug("Executing: {0}".format(bash_command))
            try:
                check_call(shlex.split(bash_command))
            except CalledProcessError as e:
                logger.error(e)

            if not os.path.exists(output_ptx_path):
                logger.error("Could not compile {0}".format(source_path))
                raise RuntimeError("Could not compile {0}".format(source_path))
            else:
                os.chmod(output_ptx_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)

        else:
            logger.debug("No compiling required for {0}".format(source_path))
            is_compiled = False

        return output_ptx_path, is_compiled

    @classmethod
    def compile_all_directories(cls, source_extension='.cu'):
        for program_dir in cls._program_directories:

            for program_path in glob_recursive(program_dir, '*' + source_extension):