<commit_before>#
# Copyright 2015-2016 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import sys
import subprocess
import codecs
import json
sys.path.append('../actionProxy')
from actionproxy import ActionRunner, main, setRunner

SRC_EPILOGUE_FILE = "./epilogue.swift"
DEST_SCRIPT_FILE = "/swift3Action/spm-build/main.swift"
DEST_SCRIPT_DIR = "/swift3Action/spm-build"
DEST_BIN_FILE = "/swift3Action/spm-build/.build/release/Action"

BUILD_PROCESS = [ "./swiftbuildandlink.sh"]

class Swift3Runner(ActionRunner):

    def __init__(self):
        ActionRunner.__init__(self, DEST_SCRIPT_FILE, DEST_BIN_FILE)

    def epilogue(self, fp):
        with codecs.open(SRC_EPILOGUE_FILE, "r", "utf-8") as ep:
            fp.write(ep.read())

    def build(self):
        p = subprocess.Popen(BUILD_PROCESS, cwd=DEST_SCRIPT_DIR)
        (o, e) = p.communicate()

        if o is not None:
            sys.stdout.write(o)

        if e is not None:
            sys.stderr.write(e)

    def env(self, message):
        env = ActionRunner.env(self, message)
        args = message.get('value', {}) if message else {}
        env['WHISK_INPUT'] = json.dumps(args)
        return env

if __name__ == "__main__":
    setRunner(Swift3Runner())
    main()
<commit_msg>Add flush statements to Swift 3 runner (#1438)<commit_after>#
# Copyright 2015-2016 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import sys
import subprocess
import codecs
import json
sys.path.append('../actionProxy')
from actionproxy import ActionRunner, main, setRunner

SRC_EPILOGUE_FILE = "./epilogue.swift"
DEST_SCRIPT_FILE = "/swift3Action/spm-build/main.swift"
DEST_SCRIPT_DIR = "/swift3Action/spm-build"
DEST_BIN_FILE = "/swift3Action/spm-build/.build/release/Action"

BUILD_PROCESS = [ "./swiftbuildandlink.sh"]

class Swift3Runner(ActionRunner):

    def __init__(self):
        ActionRunner.__init__(self, DEST_SCRIPT_FILE, DEST_BIN_FILE)

    def epilogue(self, fp):
        with codecs.open(SRC_EPILOGUE_FILE, "r", "utf-8") as ep:
            fp.write(ep.read())

    def build(self):
        p = subprocess.Popen(BUILD_PROCESS, cwd=DEST_SCRIPT_DIR)
        (o, e) = p.communicate()

        if o is not None:
            sys.stdout.write(o)
            sys.stdout.flush()

        if e is not None:
            sys.stderr.write(e)
            sys.stderr.flush()

    def env(self, message):
        env = ActionRunner.env(self, message)
        args = message.get('value', {}) if message else {}
        env['WHISK_INPUT'] = json.dumps(args)
        return env

if __name__ == "__main__":
    setRunner(Swift3Runner())
    main()

{'fraction_non_alphanumeric': 0.10731034482758621, 'fraction_numerical': 0.011310344827586206, 'mean_word_length': 3.358173076923077, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3725119', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1117, 'n_words': 339}