# Path: catkin_tools/common.py
# def log(*args, **kwargs):
#     """Wrapper for print, allowing for special handling where necessary"""
#     global unicode_error_printed
#     try:
#         print(*args, **kwargs)
#     except UnicodeEncodeError:
#         # Strip unicode characters from string args
#         sanitized_args = [unicode_sanitizer.sub('?', a)
#                           if isinstance(a, str)
#                           else a
#                           for a in args]
#         print(*sanitized_args, **kwargs)
# 
#         # Warn the user that
#         if not unicode_error_printed:
#             print('WARNING: Could not encode unicode characters. Please set the'
#                   ' PYTHONIOENCODING environment variable to see complete output.'
#                   ' (i.e. PYTHONIOENCODING=UTF-8)',
#                   file=sys.stderr)
#             unicode_error_printed = True
# 
# Path: catkin_tools/common.py
# def version_tuple(v):
#     """Get an integer version tuple from a string."""
#     return tuple(map(int, (str(v).split("."))))
# 
# Path: catkin_tools/terminal_color.py
# class ColorMapper(object):
# 
#     """This class encapsulates a set of human-readable format strings and the
#     functionality to convert them into colorized version.
#     """
# 
#     # This map translates more human readable format strings into colorized versions
#     default_color_translation_map = {
#         # 'output': 'colorized_output'
#         '': fmt('@!' + sanitize('') + '@|')
#     }
# 
#     def __init__(self, color_map={}):
#         """Create a color mapper with a given map.
# 
#         :param color_map: A dictionary of format strings and colorized versions
#         :type color_map: dict
#         """
#         self.color_map = ColorMapper.default_color_translation_map
#         self.color_map.update(color_map)
# 
#     def clr(self, key):
#         """Returns a colorized version of the string given.
# 
#         This is accomplished by either returning a hit from the color translation
#         map or by calling :py:func:`fmt` on the string and returning it.
# 
#         :param key: string to be colorized
#         :type key: str
#         """
#         global _color_on
#         if not _color_on:
#             return fmt(key)
#         val = self.color_map.get(key, None)
#         if val is None:
#             return fmt(key)
#         return val


import array
import fcntl
import os
import re
import subprocess
import time
        import psutil
from multiprocessing import cpu_count
from tempfile import mkstemp
from termios import FIONREAD
from catkin_tools.common import log
from catkin_tools.common import version_tuple
from catkin_tools.terminal_color import ColorMapper

    :param max_jobs: the maximum number of jobs available
    :param max_load: do not dispatch additional jobs if this system load
    value is exceeded
    :param max_mem: do not dispatch additional jobs if system physical
    memory usage exceeds this value (see _set_max_mem for additional
    documentation)
    :param gnu_make_enabled: Set gnu make compatibility enabled
    """

    # Check initialization
    if JobServer._initialized is True:
        return

    # Check if the jobserver is supported
    if JobServer._gnu_make is None:
        JobServer._gnu_make = GnuMake()

    if not JobServer._gnu_make.is_supported():
        log(clr('@!@{yf}WARNING:@| Make job server not supported. The number of Make '
                'jobs may exceed the number of CPU cores.@|'))

    # Set gnu make compatibility enabled
    JobServer._gnu_make_enabled = gnu_make_enabled

    # Set the maximum number of jobs
    if max_jobs is None:
        try:
            max_jobs = cpu_count()
        except NotImplementedError:

# Path: catkin_tools/common.py
# def log(*args, **kwargs):
#     """Wrapper for print, allowing for special handling where necessary"""
#     global unicode_error_printed
#     try:
#         print(*args, **kwargs)
#     except UnicodeEncodeError:
#         # Strip unicode characters from string args
#         sanitized_args = [unicode_sanitizer.sub('?', a)
#                           if isinstance(a, str)
#                           else a
#                           for a in args]
#         print(*sanitized_args, **kwargs)
# 
#         # Warn the user that
#         if not unicode_error_printed:
#             print('WARNING: Could not encode unicode characters. Please set the'
#                   ' PYTHONIOENCODING environment variable to see complete output.'
#                   ' (i.e. PYTHONIOENCODING=UTF-8)',
#                   file=sys.stderr)
#             unicode_error_printed = True
# 
# Path: catkin_tools/common.py
# def version_tuple(v):
#     """Get an integer version tuple from a string."""
#     return tuple(map(int, (str(v).split("."))))
# 
# Path: catkin_tools/terminal_color.py
# class ColorMapper(object):
# 
#     """This class encapsulates a set of human-readable format strings and the
#     functionality to convert them into colorized version.
#     """
# 
#     # This map translates more human readable format strings into colorized versions
#     default_color_translation_map = {
#         # 'output': 'colorized_output'
#         '': fmt('@!' + sanitize('') + '@|')
#     }
# 
#     def __init__(self, color_map={}):
#         """Create a color mapper with a given map.
# 
#         :param color_map: A dictionary of format strings and colorized versions
#         :type color_map: dict
#         """
#         self.color_map = ColorMapper.default_color_translation_map
#         self.color_map.update(color_map)
# 
#     def clr(self, key):
#         """Returns a colorized version of the string given.
# 
#         This is accomplished by either returning a hit from the color translation
#         map or by calling :py:func:`fmt` on the string and returning it.
# 
#         :param key: string to be colorized
#         :type key: str
#         """
#         global _color_on
#         if not _color_on:
#             return fmt(key)
#         val = self.color_map.get(key, None)
#         if val is None:
#             return fmt(key)
#         return val


# Path: catkin_tools/execution/job_server.py
import array
import fcntl
import os
import re
import subprocess
import time
        import psutil
from multiprocessing import cpu_count
from tempfile import mkstemp
from termios import FIONREAD
from catkin_tools.common import log
from catkin_tools.common import version_tuple
from catkin_tools.terminal_color import ColorMapper


    :param max_jobs: the maximum number of jobs available
    :param max_load: do not dispatch additional jobs if this system load
    value is exceeded
    :param max_mem: do not dispatch additional jobs if system physical
    memory usage exceeds this value (see _set_max_mem for additional
    documentation)
    :param gnu_make_enabled: Set gnu make compatibility enabled
    """

    # Check initialization
    if JobServer._initialized is True:
        return

    # Check if the jobserver is supported
    if JobServer._gnu_make is None:
        JobServer._gnu_make = GnuMake()

    if not JobServer._gnu_make.is_supported():
        log(clr('@!@{yf}WARNING:@| Make job server not supported. The number of Make '
                'jobs may exceed the number of CPU cores.@|'))

    # Set gnu make compatibility enabled
    JobServer._gnu_make_enabled = gnu_make_enabled

    # Set the maximum number of jobs
    if max_jobs is None:
        try:
            max_jobs = cpu_count()
        except NotImplementedError:

            log('@{yf}WARNING: Failed to determine the cpu_count, falling back to 1 jobs as the default.@|')