<commit_before># ----------------------------------------------------------------------------
# Copyright (c) 2016--, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------

import os
import zipfile

import click
import qiime


@click.group(help='Tools for working with QIIME files.')
def tools():
    pass


@tools.command(name='import', short_help='Import data.',
               help="Import data to create a new QIIME Artifact. See "
                    "http://2.qiime.org/Importing-data for usage examples "
                    "and details on the file types and associated semantic "
                    "types that can be imported.")
@click.option('--type', required=True,
              help='The semantic type of the new artifact.')
@click.option('--input-path', required=True,
              type=click.Path(exists=True, dir_okay=True),
              help='Path to file or directory that should be imported.')
@click.option('--output-path', required=True,
              type=click.Path(exists=False, dir_okay=False),
              help='Path where output artifact should be written.')
def import_data(type, input_path, output_path):
    artifact = qiime.sdk.Artifact.import_data(type, input_path)
    # TODO remove hardcoding of extension pending
    # https://github.com/qiime2/qiime2/issues/59
    if not output_path.endswith('.qza'):
        output_path = '%s.qza' % output_path
    artifact.save(output_path)


@tools.command(short_help='View a QIIME Visualization.',
               help="Displays a QIIME Visualization until the command exits. "
                    "To open a QIIME Visualization so it can be used after "
                    "the command exits, use 'qiime extract'.")
@click.argument('visualization-path',
                type=click.Path(exists=True, dir_okay=False))
@click.option('--index-extension', required=False, default='html',<commit_msg>ENH: Adds plugin-init command to qiime tools to initialize a plugin package from a template<commit_after># ----------------------------------------------------------------------------
# Copyright (c) 2016--, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------

import os
import zipfile

import click
import qiime
import qiime.plugin


@click.group(help='Tools for working with QIIME files.')
def tools():
    pass


@tools.command(name='plugin-init',
               short_help='Initialize plugin package from template.',
               help="Initializes plugin package from template to specified"
                    " output directory. Use this command if you are a"
                    " plugin developer starting to develop a new plugin.")
@click.pass_context
@click.option('--output-dir', required=False,
              type=click.Path(exists=False, file_okay=False, dir_okay=True,
                              writable=True),
              help='Directory in which to create plugin package.',
              default='.')
def plugin_init(ctx, output_dir):
    try:
        path = qiime.plugin.plugin_init(output_dir=output_dir)
    except FileExistsError as e:
        click.secho("Plugin package directory name already exists under %s"
                    % (output_dir if output_dir != '.' else
                       'the current directory'),
                    err=True, fg='red')
        click.secho("Original error message:\n%s" % e, err=True, fg='red')
        ctx.exit(1)
    click.secho("Your plugin package has been created at %s" % path,
                fg='green')


@tools.command(name='import', short_help='Import data.',
               help="Import data to create a new QIIME Artifact. See "
                    "http://2.qiime.org/Importing-data for usage examples "
                    "and details on the file types and associated semantic "
                    "types that can be imported.")
@click.option('--type', required=True,
              help='The semantic type of the new artifact.')
@click.option('--input-path', required=True,
              type=click.Path(exists=True, dir_okay=True),
              help='Path to file or directory that should be imported.')
@click.option('--output-path', required=True,
              type=click.Path(exists=False, dir_okay=False),
              help='Path where output artifact should be written.')
def import_data(type, input_path, output_path):
    artifact = qiime.sdk.Artifact.import_data(type, input_path)
    # TODO remove hardcoding of extension pending
    # https://github.com/qiime2/qiime2/issues/59
    if not output_path.endswith('.qza'):
        output_path = '%s.qza' % output_path
    artifact.save(output_path)


@tools.command(short_help='View a QIIME Visualization.',
               help="Displays a QIIME Visualization until the command exits. "
                    "To open a QIIME Visualization so it can be used after "
                    "the command exits, use 'qiime extract'.")
@click.argument('visualization-path',
                type=click.Path(exists=True, dir_okay=False))
@click.option('--index-extension', required=False, default='html',
{'fraction_non_alphanumeric': 0.15843050157320007, 'fraction_numerical': 0.003886729594669628, 'mean_word_length': 2.1750881316098707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1405267', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1393, 'n_words': 434}