<commit_before>from __future__ import division

import os
import sys
import traceback

import click

import pyximport; pyximport.install()
import cyhdfs3

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


def main():
    try:
        cli(obj={})
    except Exception as e:
        click.echo(traceback.format_exc(), err=True)
        sys.exit(1)


@click.group(context_settings=CONTEXT_SETTINGS)
@click.option('--namenode', '-n', default='localhost', required=False, help='Namenode host', show_default=True)
@click.option('--port', '-p', default=8020, required=False, help='Namenode port', show_default=True)
@click.pass_context
def cli(ctx, namenode, port):
    os.environ["LIBHDFS3_CONF"] = "/etc/hadoop/conf/hdfs-site.xml"

    ctx.obj = {}
    ctx.obj['client'] = cyhdfs3.HDFSClient()


@cli.command(short_help='Display the first (n) bytes of a file')
@click.argument('path', required=False, default='/')
@click.option('--bytes', '-b', 'nbytes', default=1*2**10, required=False, help='Number of bytes', show_default=True)
@click.pass_context
def head(ctx, path, nbytes):
    client = ctx.obj['client']
    try:
        with client.open(path, 'r') as f:
            click.echo(f.read(length=nbytes))
    except IOError:
        if client.path_info(path).kind == 'd':
            click.echo("head: error reading '{}': Is a directory".format(path), err=True)
            sys.exit(1)


@cli.command(short_help='Display the last (n) bytes of a file')
@click.argument('path', required=False, default='/')
@click.option('--bytes', '-b', 'nbytes', default=1*2**10, required=False, help='Number of bytes', show_default=True)
@click.pass_context
def tail(ctx, path, nbytes):
    client = ctx.obj['client']
    try:
        with client.open(path, 'r') as f:
            start = max(0, f.info.size - nbytes)<commit_msg>Move some imports inside functions<commit_after>from __future__ import division

import sys
import click

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


def main():
    try:
        cli(obj={})
    except Exception as e:
        import traceback
        click.echo(traceback.format_exc(), err=True)
        sys.exit(1)


@click.group(context_settings=CONTEXT_SETTINGS)
@click.option('--namenode', '-n', default='localhost', required=False, help='Namenode host', show_default=True)
@click.option('--port', '-p', default=8020, required=False, help='Namenode port', show_default=True)
@click.pass_context
def cli(ctx, namenode, port):
    import pyximport; pyximport.install()
    import os
    import cyhdfs3
    os.environ["LIBHDFS3_CONF"] = "/etc/hadoop/conf/hdfs-site.xml"
    ctx.obj = {}
    ctx.obj['client'] = cyhdfs3.HDFSClient()


@cli.command(short_help='Display the first (n) bytes of a file')
@click.argument('path', required=False, default='/')
@click.option('--bytes', '-b', 'nbytes', default=1*2**10, required=False, help='Number of bytes', show_default=True)
@click.pass_context
def head(ctx, path, nbytes):
    client = ctx.obj['client']
    try:
        with client.open(path, 'r') as f:
            click.echo(f.read(length=nbytes))
    except IOError:
        if client.path_info(path).kind == 'd':
            click.echo("head: error reading '{}': Is a directory".format(path), err=True)
            sys.exit(1)


@cli.command(short_help='Display the last (n) bytes of a file')
@click.argument('path', required=False, default='/')
@click.option('--bytes', '-b', 'nbytes', default=1*2**10, required=False, help='Number of bytes', show_default=True)
@click.pass_context
def tail(ctx, path, nbytes):
    client = ctx.obj['client']
    try:
        with client.open(path, 'r') as f:
            start = max(0, f.info.size - nbytes)
{'fraction_non_alphanumeric': 0.16938110749185667, 'fraction_numerical': 0.009771986970684038, 'mean_word_length': 4.020435967302452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4067041', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1243, 'n_words': 283}