<commit_before>import os
import sys
import json
import uuid
import functools
import subprocess

# NOTE: The multiprocessing module is not compatible with SCons due to conflict on cPickle


def run_in_subprocess(builder_function):

    @functools.wraps(builder_function)
    def wrapper(target, source, env):

        # Convert SCons Node instances to absolute paths
        target = [node.srcnode().abspath for node in target]
        source = [node.srcnode().abspath for node in source]

        # Short circuit on non-Windows platforms
        if os.name != 'nt':
            return builder_function(target, source, None)

        # Identify module
        module_name = builder_function.__module__
        function_name = builder_function.__name__
        module_path = sys.modules[module_name].__file__
        if module_path.endswith('.pyc') or module_path.endswith('.pyo'):
            module_path = module_path[:-1]

        # Subprocess environment
        subprocess_env = os.environ.copy()
        subprocess_env['PYTHONPATH'] = os.pathsep.join([os.getcwd()] + sys.path)

        # Save parameters
        args = (target, source, None)
        data = dict(fn=function_name, args=args)
        json_path = os.path.join(os.environ['TMP'], uuid.uuid4().hex + '.json')
        with open(json_path, 'wt') as json_file:
            json.dump(data, json_file, indent=2)
        try:
            print('Executing builder function in subprocess: module_path=%r; data=%r' % (module_path, data))
            exit_code = subprocess.call([sys.executable, module_path, json_path], env=subprocess_env)
        finally:
            try:
                os.remove(json_path)
            except (OSError, IOError) as e:
                # Do not fail the entire build if it cannot delete a temporary file
                print('WARNING: Could not delete temporary file: path=%r; [%s] %s' %<commit_msg>Fixed Mac build by running builders in subprocess only on Windows<commit_after>import os
import sys
import json
import uuid
import functools
import subprocess

# NOTE: The multiprocessing module is not compatible with SCons due to conflict on cPickle

if sys.version_info[0] < 3:
    JSON_SERIALIZABLE_TYPES = (bool, int, long, float, basestring)
else:
    JSON_SERIALIZABLE_TYPES = (bool, int, float, str)


def run_in_subprocess(builder_function):

    # Run in subprocess only while running the build on Windows
    if sys.platform not in ('win32', 'cygwin'):
        return builder_function

    @functools.wraps(builder_function)
    def wrapper(target, source, env):

        # Convert SCons Node instances to absolute paths
        target = [node.srcnode().abspath for node in target]
        source = [node.srcnode().abspath for node in source]

        # Identify module
        module_name = builder_function.__module__
        function_name = builder_function.__name__
        module_path = sys.modules[module_name].__file__
        if module_path.endswith('.pyc') or module_path.endswith('.pyo'):
            module_path = module_path[:-1]

        # Subprocess environment
        subprocess_env = os.environ.copy()
        subprocess_env['PYTHONPATH'] = os.pathsep.join([os.getcwd()] + sys.path)

        # Keep only JSON serializable environment items
        filtered_env = dict(
            (key, value)
            for key, value in env.items()
            if isinstance(value, JSON_SERIALIZABLE_TYPES)
        )

        # Save parameters
        args = (target, source, filtered_env)
        data = dict(fn=function_name, args=args)
        json_path = os.path.join(os.environ['TMP'], uuid.uuid4().hex + '.json')
        with open(json_path, 'wt') as json_file:
            json.dump(data, json_file, indent=2)
        json_file_size = os.stat(json_path).st_size

        print('Executing builder function in subprocess: '
              'module_path=%r, parameter_file=%r, parameter_file_size=%r, target=%r, source=%r' % (
               module_path, json_path, json_file_size, target, source))
        try:
            exit_code = subprocess.call([sys.executable, module_path, json_path], env=subprocess_env)
        finally:
            try:
                os.remove(json_path)
            except (OSError, IOError) as e:
                # Do not fail the entire build if it cannot delete a temporary file
                print('WARNING: Could not delete temporary file: path=%r; [%s] %s' %
{'fraction_non_alphanumeric': 0.09580022701475596, 'fraction_numerical': 0.0022701475595913734, 'mean_word_length': 2.6994122586062135, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1505647', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1279, 'n_words': 361}