Form an AST for the code and produce a new version of the source.
332167
def parseLines(self):
        """"""
        inAst = parse(''.join(self.lines), self.inFilename)
        # Visit all the nodes in our tree and apply Doxygen tags to the source.
        self.visit(inAst)
1066867
def auto_create_version(class_name, version, filename="__init__.py"):
    
    version_filename = Path(
        "{classname}/{filename}".format(classname=class_name,
                                        filename=filename))
    with open(version_filename, "r") as f:
        content = f.read()

    if content != '__version__ = "{0}"'.format(version):
        banner("Updating version to {0}".format(version))
        with open(version_filename, "w") as text_file:
            text_file.write('__version__ = "{0:s}"'.format(version))
1020651
def transform_source(text):
    '''
    '''
    toks = tokenize.generate_tokens(StringIO(text).readline)
    result = []
    replacing_keyword = False
    for toktype, tokvalue, _, _, _ in toks:
        if toktype == tokenize.NAME and tokvalue == 'switch':
            result.extend([
                (tokenize.NAME, 'for'),
                (tokenize.NAME, '__case'),
                (tokenize.NAME, 'in'),
                (tokenize.NAME, '_Switch'),
                (tokenize.OP, '(')
            ])
            replacing_keyword = True
        elif toktype == tokenize.NAME and (tokvalue == 'case' or tokvalue == 'default'):
            result.extend([
                (tokenize.NAME, 'if'),
                (tokenize.NAME, '__case'),
                (tokenize.OP, '(')
            ])
            replacing_keyword = True
        elif replacing_keyword and tokvalue == ':':
            result.extend([
                (tokenize.OP, ')'),
                (tokenize.OP, ':')
            ])
            replacing_keyword = False
        else:
            result.append((toktype, tokvalue))
    return tokenize.untokenize(result)
754892
def rerun(client, revision, roots, siblings, inputs, paths):
    """"""
    graph = Graph(client)
    outputs = graph.build(paths=paths, revision=revision)

    # Check or extend siblings of outputs.
    outputs = siblings(graph, outputs)
    output_paths = {node.path for node in outputs}

    # Normalize and check all starting paths.
    roots = {graph.normalize_path(root) for root in roots}
    assert not roots & output_paths, '--from colides with output paths'

    # Generate workflow and check inputs.
    # NOTE The workflow creation is done before opening a new file.
    workflow = inputs(
        client,
        graph.ascwl(
            input_paths=roots,
            output_paths=output_paths,
            outputs=outputs,
        )
    )

    # Make sure all inputs are pulled from a storage.
    client.pull_paths_from_storage(
        *(path for _, path in workflow.iter_input_files(client.workflow_path))
    )

    # Store the generated workflow used for updating paths.
    import yaml

    output_file = client.workflow_path / '{0}.cwl'.format(uuid.uuid4().hex)
    with output_file.open('w') as f:
        f.write(
            yaml.dump(
                ascwl(
                    workflow,
                    filter=lambda _, x: x is not None,
                    basedir=client.workflow_path,
                ),
                default_flow_style=False
            )
        )

    # Execute the workflow and relocate all output files.
    from ._cwl import execute
    # FIXME get new output paths for edited tools
    # output_paths = {path for _, path in workflow.iter_output_files()}
    execute(
        client,
        output_file,
        output_paths=output_paths,
    )
1070708
def parse(code):
    
    try:
        ast_tree = ast.parse(code)
    except Exception:
        raise RuntimeError('Bad Python code')

    transformer = Transformer()
    try:
        transformer.visit(ast_tree)
    except AssertionError as exc:
        raise RuntimeError('%d: %s' % (ast_tree.last_line, exc.args[0]))

    if not transformer.annotated:
        return None

    last_future_import = -1
    import_nni = ast.Import(names=[ast.alias(name='nni', asname=None)])
    nodes = ast_tree.body
    for i, _ in enumerate(nodes):
        if type(nodes[i]) is ast.ImportFrom and nodes[i].module == '__future__':
            last_future_import = i
    nodes.insert(last_future_import + 1, import_nni)

    return astor.to_source(ast_tree)
542770
def refactor_create_inline(self, offset, only_this):
        """"""
        refactor = create_inline(self.project, self.resource, offset)
        if only_this:
            return self._get_changes(refactor, remove=False, only_current=True)
        else:
            return self._get_changes(refactor, remove=True, only_current=False)
152029
def make_source(self, groups, code_opts, gen_opts):
        """"""
        modules = self.make_modules(groups, code_opts)
        var_decls = modules.var_decls
        relocs = AttrsGetter(modules.relocs)
        x86, x64 = relocs.get_attrs('x86', 'x64')
        if code_opts.windll:
            structs, x86_reloc, x64_reloc = make_windll(
                modules.structs
            )
            x86 += x86_reloc
            x64 += x64_reloc
        else:
            structs = ''.join(modules.structs)
        c_relocs = reloc_both(relocs.strings + x86, x64)
        data = var_decls.strip()
        c_header = make_c_header(
            gen_opts.filename, 'NOTICE',
            modules.typedefs + structs + data
        )
        c_source = make_init(
            modules.hashes + c_relocs + modules.libprocs,
            callable(code_opts.hash_func)
        )
        return [c_header, c_source]
337079
def write_code(self, name, code):
        
        file_path = self.gen_file_path(name)
        with open(file_path,'w') as f:
            f.write(code)
45805
def new_code_block(self, **kwargs):
        """"""
        proto = {'content': '',
                 'type': self.code,
                 'IO': '',
                 'attributes': ''}
        proto.update(**kwargs)
        return proto
68434
def run(self, *args):
        """"""

        params = self.parser.parse_args(args)

        code = self.unify(params.matching, params.sources,
                          params.fast_matching, params.no_strict,
                          params.interactive, params.recovery)

        return code
1023256
def _compilecode(function, name, impl, args, varargs, kwargs):
    

    newcodestr, generatedname, impl_name = _generatecode(
        function=function, name=name, impl=impl,
        args=args, varargs=varargs, kwargs=kwargs
    )

    try:
        __file__ = getfile(function)
    except TypeError:
        __file__ = '<string>'

    # compile newcodestr
    code = compile(newcodestr, __file__, 'single')

    # define the code with the new function
    _globals = {}
    exec_(code, _globals)

    # get new code
    _var = _globals[generatedname]
    newco = get_function_code(_var)

    # get new consts list
    newconsts = list(newco.co_consts)

    if PY3:
        newcode = list(newco.co_code)
    else:
        newcode = [ord(co) for co in newco.co_code]

    consts_values = {impl_name: impl}

    # change LOAD_GLOBAL to LOAD_CONST
    index = 0
    newcodelen = len(newcode)
    while index < newcodelen:
        if newcode[index] == LOAD_GLOBAL:
            oparg = newcode[index + 1] + (newcode[index + 2] << 8)
            name = newco.co_names[oparg]
            if name in consts_values:
                const_value = consts_values[name]
                if const_value in newconsts:
                    pos = newconsts.index(const_value)
                else:
                    pos = len(newconsts)
                    newconsts.append(consts_values[name])
                newcode[index] = LOAD_CONST
                newcode[index + 1] = pos & 0xFF
                newcode[index + 2] = pos >> 8
        index += 1

    codeobj = getcodeobj(newconsts, newcode, newco, get_function_code(function))
    # instanciate a new function
    if function is None or isbuiltin(function):
        result = FunctionType(codeobj, {})

    else:
        result = type(function)(
            codeobj,
            get_function_globals(function),
            function.__name__,
            get_function_defaults(function),
            get_function_closure(function)
        )

    return result
291936
def create_parser():
    """"""
    from argparse import ArgumentParser, FileType

    description = ("PEP8 clean only the parts of the files which you have "
                   "touched since the last commit, a previous commit or "
                   "(the merge-base of) a branch.")
    epilog = ("Run before you commit, against a previous commit or "
              "branch before merging.")
    parser = ArgumentParser(description=description,
                            epilog=epilog,
                            prog='pep8radius')

    parser.add_argument('rev',
                        help='commit or name of branch to compare against',
                        nargs='?')

    parser.add_argument('--version',
                        help='print version number and exit',
                        action='store_true')

    parser.add_argument('-d', '--diff', action='store_true', dest='diff',
                        help='print the diff of fixed source vs original')
    parser.add_argument('--error-status', action='store_true',
                        dest='error_status',
                        help="return a shell status code of 1 if there are"
                             " any fixes")
    parser.add_argument('-i', '--in-place', action='store_true',
                        help="make the fixes in place; modify the files")
    parser.add_argument('--no-color', action='store_true',
                        help='do not print diffs in color '
                             '(default is to use color)')
    parser.add_argument('-v', '--verbose', action='count', dest='verbose',
                        default=0,
                        help='print verbose messages; '
                        'multiple -v result in more verbose messages '
                        '(one less -v is passed to autopep8)')
    parser.add_argument('--from-diff', type=FileType('r'), metavar='DIFF',
                        help="Experimental: rather than calling out to version"
                             " control, just pass in a diff; "
                             "the modified lines will be fixed")

    ap = parser.add_argument_group('pep8', 'Pep8 options to pass to autopep8.')
    ap.add_argument('-p', '--pep8-passes', metavar='n',
                    default=-1, type=int,
                    help='maximum number of additional pep8 passes '
                    '(default: infinite)')
    ap.add_argument('-a', '--aggressive', action='count', default=0,
                    help='enable non-whitespace changes; '
                    'multiple -a result in more aggressive changes')
    ap.add_argument('--experimental', action='store_true',
                    help='enable experimental fixes')
    ap.add_argument('--exclude', metavar='globs',
                    help='exclude file/directory names that match these '
                    'comma-separated globs')
    ap.add_argument('--list-fixes', action='store_true',
                    help='list codes for fixes and exit; '
                    'used by --ignore and --select')
    ap.add_argument('--ignore', metavar='errors', default='',
                    help='do not fix these errors/warnings '
                    '(default: {0})'.format(DEFAULT_IGNORE))
    ap.add_argument('--select', metavar='errors', default='',
                    help='fix only these errors/warnings (e.g. E4,W)')
    ap.add_argument('--max-line-length', metavar='n', default=79, type=int,
                    help='set maximum allowed line length '
                    '(default: %(default)s)')
    ap.add_argument('--indent-size', default=DEFAULT_INDENT_SIZE,
                    type=int, metavar='n',
                    help='number of spaces per indent level '
                    '(default %(default)s)')

    df = parser.add_argument_group('docformatter',
                                   'Fix docstrings for PEP257.')
    df.add_argument('-f', '--docformatter', action='store_true',
                    help='Use docformatter')
    df.add_argument('--no-blank', dest='post_description_blank',
                    action='store_false',
                    help='Do not add blank line after description')
    df.add_argument('--pre-summary-newline',
                    action='store_true',
                    help='add a newline before the summary of a '
                    'multi-line docstring')
    df.add_argument('--force-wrap', action='store_true',
                    help='force descriptions to be wrapped even if it may '
                    'result in a mess')

    cg = parser.add_argument_group('config',
                                   'Change default options based on global '
                                   'or local (project) config files.')
    cg.add_argument('--global-config',
                    default=DEFAULT_CONFIG,
                    metavar='filename',
                    help='path to global pep8 config file; ' +
                    " if this file does not exist then this is ignored" +
                    '(default: %s)' % DEFAULT_CONFIG)
    cg.add_argument('--ignore-local-config', action='store_true',
                    help="don't look for and apply local config files; "
                    'if not passed, defaults are updated with any '
                    "config files in the project's root directory")

    yp = parser.add_argument_group('yapf',
                                   'Options for yapf, alternative to autopep8. '
                                   'Currently any other options are ignored.')
    yp.add_argument('-y', '--yapf', action='store_true',
                    help='Use yapf rather than autopep8. '
                    'This ignores other arguments outside of this group.')
    yp.add_argument('--style', metavar='', default='pep8',
                    help='style either pep8, google, name of file with style'
                    'settings, or a dict')

    return parser
961583
def recompile(filename):
    """"""
    # Most of the code here based on the compile.py module.
    import os
    import imp
    import marshal
    import struct

    f = open(filename, 'U')
    try:
        timestamp = long(os.fstat(f.fileno()).st_mtime)
    except AttributeError:
        timestamp = long(os.stat(filename).st_mtime)
    codestring = f.read()
    f.close()
    if codestring and codestring[-1] != '\n':
        codestring = codestring + '\n'
    try:
        codeobject = compile(codestring, filename, 'exec')
    except SyntaxError:
        print >> sys.stderr, "Skipping %s - syntax error." % filename
        return
    cod = Code.from_code(codeobject)
    message = "reassembled %r imported.\n" % filename
    cod.code[:0] = [ # __import__('sys').stderr.write(message)
        (LOAD_GLOBAL, '__import__'),
        (LOAD_CONST, 'sys'),
        (CALL_FUNCTION, 1),
        (LOAD_ATTR, 'stderr'),
        (LOAD_ATTR, 'write'),
        (LOAD_CONST, message),
        (CALL_FUNCTION, 1),
        (POP_TOP, None),
        ]
    codeobject2 = cod.to_code()
    fc = open(filename+'c', 'wb')
    fc.write('\0\0\0\0')
    fc.write(struct.pack('<l', timestamp))
    marshal.dump(codeobject2, fc)
    fc.flush()
    fc.seek(0, 0)
    fc.write(imp.get_magic())
    fc.close()
477989
def emit(self, ast_reg, ast_guide):
        '''  '''
        if (ast_reg):
            self.visit(ast_reg)
        codegen_reg = self.codegen
        self.codegen = self.cg_type()
        if (ast_guide):
            self.visit(ast_guide)
        return (codegen_reg, self.codegen)
548057
public static function create()
	{
		switch (func_num_args()) {
			case 0:
				return new SourceCodeInfo();
			case 1:
				return new SourceCodeInfo(func_get_arg(0));
			case 2:
				return new SourceCodeInfo(func_get_arg(0), func_get_arg(1));
			case 3:
				return new SourceCodeInfo(func_get_arg(0), func_get_arg(1), func_get_arg(2));
			case 4:
				return new SourceCodeInfo(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3));
			case 5:
				return new SourceCodeInfo(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4));
			case 6:
				return new SourceCodeInfo(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5));
			case 7:
				return new SourceCodeInfo(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5), func_get_arg(6));
			case 8:
				return new SourceCodeInfo(func_get_arg(0), func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4), func_get_arg(5), func_get_arg(6), func_get_arg(7));
			default:
				throw new \InvalidArgumentException('More than 8 arguments supplied, please be reasonable.');
		}
	}
810196
def build_ast(self):
        """"""
        n = self.root_node
        if n.type == syms.file_input:
            stmts = []
            for i in range(len(n.children) - 1):
                stmt = n.children[i]
                if stmt.type == tokens.NEWLINE:
                    continue
                sub_stmts_count = self.number_of_statements(stmt)
                if sub_stmts_count == 1:
                    stmts.append(self.handle_stmt(stmt))
                else:
                    stmt = stmt.children[0]
                    for j in range(sub_stmts_count):
                        small_stmt = stmt.children[j * 2]
                        stmts.append(self.handle_stmt(small_stmt))
            return ast.Module(stmts)
        elif n.type == syms.eval_input:
            body = self.handle_testlist(n.children[0])
            return ast.Expression(body)
        elif n.type == syms.single_input:
            first_child = n.children[0]
            if first_child.type == tokens.NEWLINE:
                # An empty line.
                return ast.Interactive([])
            else:
                num_stmts = self.number_of_statements(first_child)
                if num_stmts == 1:
                    stmts = [self.handle_stmt(first_child)]
                else:
                    stmts = []
                    for i in range(0, len(first_child.children), 2):
                        stmt = first_child.children[i]
                        if stmt.type == tokens.NEWLINE:
                            break
                        stmts.append(self.handle_stmt(stmt))
                return ast.Interactive(stmts)
        else:
            raise AssertionError("unknown root node")
380760
def wrap_code(code: str, args: str = '') -> ast.Module:
    

    if sys.version_info >= (3, 7):
        user_code = import_expression.parse(code, mode='exec')
        injected = ''
    else:
        injected = code

    mod = import_expression.parse(CORO_CODE.format(args, textwrap.indent(injected, ' ' * 8)), mode='exec')

    definition = mod.body[-1]  # async def ...:
    assert isinstance(definition, ast.AsyncFunctionDef)

    try_block = definition.body[-1]  # try:
    assert isinstance(try_block, ast.Try)

    if sys.version_info >= (3, 7):
        try_block.body.extend(user_code.body)
    else:
        ast.increment_lineno(mod, -16)  # bring line numbers back in sync with repl

    ast.fix_missing_locations(mod)

    is_asyncgen = any(isinstance(node, ast.Yield) for node in ast.walk(try_block))

    last_expr = try_block.body[-1]

    # if the last part isn't an expression, ignore it
    if not isinstance(last_expr, ast.Expr):
        return mod

    # if the last expression is not a yield
    if not isinstance(last_expr.value, ast.Yield):
        # copy the expression into a return/yield
        if is_asyncgen:
            # copy the value of the expression into a yield
            yield_stmt = ast.Yield(last_expr.value)
            ast.copy_location(yield_stmt, last_expr)
            # place the yield into its own expression
            yield_expr = ast.Expr(yield_stmt)
            ast.copy_location(yield_expr, last_expr)

            # place the yield where the original expression was
            try_block.body[-1] = yield_expr
        else:
            # copy the expression into a return
            return_stmt = ast.Return(last_expr.value)
            ast.copy_location(return_stmt, last_expr)

            # place the return where the original expression was
            try_block.body[-1] = return_stmt

    return mod