<commit_before># Copyright 2015 datawire. All rights reserved.
#
# 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.

"""
Adaptive

Usage:
  adaptive client [--java=<dir>] [--python=<dir>] [--ruby=<dir>] <file> ...
  adaptive server [--java=<dir>] [--python=<dir>] [--ruby=<dir>] <file> ...
  adaptive -h | --help
  adaptive --version

Options:
  -h --help       Show this screen.
  --version       Show version.
  --java=<dir>    Emit java code to specified directory.
  --python=<dir>  Emit python code to specified directory.
  --ruby=<dir>    Emit ruby code to specified directory.
"""

import sys

from docopt import docopt

import _metadata, generate
from quark.compiler import Compiler, ParseError, CompileError
from quark.backend import Java

def main(args):
    if args["--version"]:
        sys.stderr.write("Adaptive %s\n" % _metadata.__version__)
        return
    filenames = args["<file>"]

    java = args["--java"]
    python = args["--python"]
    ruby = args["--ruby"]
    if python: return "python is not yet supported"
    if ruby: return "ruby is not yet supported"

    compiler = Compiler()
    compiler.annotator("value", generate.value)

    if args["client"]:
        compiler.annotator("service", generate.service_client)
    elif args["server"]:
        compiler.annotator("service", generate.service_server)
    else:
        assert False

    try:
        for name in filenames:
            with open(name, "rb") as fd:
                compiler.parse(name, fd.read())
    except IOError, e:
        return e
    except ParseError, e:
        return e
    finally:
        if java:
            compiler.write(java)

    try:
        compiler.compile()
    except CompileError, e:
        return e


    if java:
        j = Java()
        compiler.emit(j)
        j.write(java)

    if not java and not python and not ruby:
        return "no output languages specified"

def call_main():
    exit(main(docopt(__doc__)))

if __name__ == "__main__":
    call_main()<commit_msg>added python backend<commit_after># Copyright 2015 datawire. All rights reserved.
#
# 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.

"""
Adaptive

Usage:
  adaptive client [--java=<dir>] [--python=<dir>] <file> ...
  adaptive server [--java=<dir>] [--python=<dir>] <file> ...
  adaptive -h | --help
  adaptive --version

Options:
  -h --help       Show this screen.
  --version       Show version.
  --java=<dir>    Emit java code to specified directory.
  --python=<dir>  Emit python code to specified directory.
"""

import sys

from docopt import docopt

import _metadata, generate
from quark.compiler import Compiler, ParseError, CompileError
from quark.backend import Java, Python

def main(args):
    if args["--version"]:
        sys.stderr.write("Adaptive %s\n" % _metadata.__version__)
        return

    compiler = Compiler()
    compiler.annotator("value", generate.value)

    if args["client"]:
        compiler.annotator("service", generate.service_client)
    elif args["server"]:
        compiler.annotator("service", generate.service_server)
    else:
        assert False

    java = args["--java"]
    python = args["--python"]
    if java: compiler.emitter(Java, java)
    if python: compiler.emitter(Python, python)

    try:
        for name in args["<file>"]:
            with open(name, "rb") as fd:
                compiler.parse(name, fd.read())
        compiler.compile()
    except IOError, e:
        return e
    except ParseError, e:
        return e
    except CompileError, e:
        return e

    if not java and not python:
        return "no output languages specified"

def call_main():
    exit(main(docopt(__doc__)))

if __name__ == "__main__":
    call_main()
{'fraction_non_alphanumeric': 0.11352502662406816, 'fraction_numerical': 0.0034078807241746537, 'mean_word_length': 2.8428805237315875, 'pattern_counts': {'":': 2, '<': 24, '<?xml version=': 0, '>': 24, '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': '5354287', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1338, 'n_words': 487}