<commit_before>#!/usr/bin/env python
"""
The JIP job runner that executes a jip scrip on the local machine

usage: jip-run [-h] [-f] [-k] [-C <cpus>] [--dry] [--show] <file> [<args>...]

Options:
  -f, --force              force command execution
  -k, --keep               do not perform a cleanup step after job failure or
                           cancellation
  -C, --cpus <cpus>        number of threads assigned to the process
  --show                   show the rendered script rather than running it
  --dry                    show the configuration of the script/pipeline
  <file>                   the script that will be executed
  <args>                   optional script argument

Other Options:
    -h --help             Show this help message

"""
import sys

from . import parse_args
from jip import find, create_jobs, run_job, ValidationError, ParserException


def main(argv=None):
    args = parse_args(__doc__, argv=argv)
    script_file = args["<file>"]
    script_args = args["<args>"]

    try:
        script = find(script_file)
    except LookupError, e:
        print >>sys.stderr, str(e)
        sys.exit(1)

    try:
        script.parse_args(script_args)
        run_script(script, keep=args["--keep"],
                   force=args["--force"],
                   dry=args["--dry"],
                   show=args['--show'])
    except ValidationError, va:
        sys.stderr.write(str(va))
        sys.stderr.write("\n")
        sys.exit(1)
    except ParserException, va:
        sys.stderr.write(str(va))
        sys.stderr.write("\n")
        sys.exit(va.status)
    except Exception:
        raise


def run_script(script, keep=False, force=False, dry=False, show=False):
    # persis the script to in memoru database
    import jip.db
    from jip.db import create_session
    if not force and script.is_done():
        sys.stderr.write("Results exist! Skipping "
                         "(use --force to force execution\n")
        return
    jip.db.init(in_memory=True)
    # create the jobs
    session = create_session()
    jobs = create_jobs(script.pipeline(),
                       parent_tool=script,
                       keep=keep,
                       session=session)
    if dry:
        show_dry_run(jobs)
        return
    if show:
        show_command(jobs)
        return
    # run all main jobs<commit_msg>Almost finished refactoring to the new structure<commit_after>#!/usr/bin/env python
"""
The JIP job runner that executes a jip scrip on the local machine

usage: jip-run [-h] [-f] [-k] [-C <cpus>] [--dry] [--show] <file> [<args>...]

Options:
  -f, --force              force command execution
  -k, --keep               do not perform a cleanup step after job failure or
                           cancellation
  -C, --cpus <cpus>        number of threads assigned to the process
  --show                   show the rendered script rather than running it
  --dry                    show the configuration of the script/pipeline
  <file>                   the script that will be executed
  <args>                   optional script argument

Other Options:
    -h --help             Show this help message

"""
import sys

from . import parse_args
from jip import find, create_jobs, run_job, ValidationError, ParserException


def main(argv=None):
    args = parse_args(__doc__, argv=argv)
    script_file = args["<file>"]
    script_args = args["<args>"]

    try:
        script = find(script_file)
    except LookupError, e:
        print >>sys.stderr, str(e)
        sys.exit(1)

    try:
        script.parse_args(script_args)
        run_script(script, keep=args["--keep"],
                   force=args["--force"],
                   dry=args["--dry"],
                   show=args['--show'])
    except ValidationError, va:
        sys.stderr.write(str(va))
        sys.stderr.write("\n")
        sys.exit(1)
    except ParserException, va:
        sys.stderr.write(str(va))
        sys.stderr.write("\n")
        sys.exit(va.status)
    except Exception:
        raise


def run_script(script, keep=False, force=False, dry=False, show=False):
    # persis the script to in memoru database
    if not force and script.is_done() and not dry and not show:
        sys.stderr.write("Results exist! Skipping "
                         "(use --force to force execution\n")
        return
    import jip.db
    from jip.db import create_session
    jip.db.init(in_memory=True)
    # create the jobs
    session = create_session()
    jobs = create_jobs(script.pipeline(),
                       parent_tool=script,
                       keep=keep,
                       session=session)
    if dry:
        show_dry_run(jobs)
        return
    if show:
        show_command(jobs)
        return
    # run all main jobs
{'fraction_non_alphanumeric': 0.10572503134141245, 'fraction_numerical': 0.0008357709987463436, 'mean_word_length': 1.8613269575612672, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, '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': '1024202', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1345, 'n_words': 411}