<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

# Standard library imports
import os
import sys

# Local imports
import cpenv
from cpenv import (
    LocalRepo,
    Resolver,
    Copier,
    ResolveError,
    api,
    cli,
    shell,
    utils,
)
from cpenv.module import parse_module_path, is_partial_match, best_match


class CpenvCLI(cli.CLI):
    '''
    Create, activate and manage Modules.

    A Module is a folder containing a module.yml file describing the Module's
    name, version, requirements, and environment variables. Module's can also
    contain a hooks folder with python files that respond to specific events.
    '''

    name = 'cpenv'
    usage = 'cpenv [-h] <command> [<args>...]'

    def commands(self):
        return [
            Activate(self),
            Clone(self),
            Copy(self),
            Create(self),
            List(self),
            Localize(self),
            Publish(self),
            Remove(self),
            Repo(self),
            Version(self),
        ]


class Activate(cli.CLI):
    '''Activate a list of Modules.'''

    usage = 'cpenv [-h] [<modules>...]'

    def setup_parser(self, parser):
        parser.add_argument(
            'modules',
            help='Space separated list of modules.',
            nargs='*',
        )

    def run(self, args):
        cli.echo()
        cli.echo('- Resolving modules...', end='')
        try:
            activated_modules = api.activate(*args.modules)
        except ResolveError:
            cli.echo('OOPS!')
            cli.echo()
            cli.echo('Error: failed to resolve %s' % args.modules)
            sys.exit(1)
        cli.echo('OK!')

        cli.echo()
        for module in activated_modules:
            cli.echo('  ' + module.real_name)
        cli.echo()
<commit_msg>add: info cli command - displays metadata for resolved modules<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

# Standard library imports
import argparse
import os
import re
import sys

# Local imports
import cpenv
from cpenv import (
    LocalRepo,
    Resolver,
    Copier,
    ResolveError,
    api,
    cli,
    shell,
    utils,
)
from cpenv.module import parse_module_path, is_partial_match, best_match


class CpenvCLI(cli.CLI):
    '''
    Create, activate and manage Modules.

    A Module is a folder containing a module.yml file describing the Module's
    name, version, requirements, and environment variables. Module's can also
    contain a hooks folder with python files that respond to specific events.
    '''

    name = 'cpenv'
    usage = 'cpenv [-h] <command> [<args>...]'

    def commands(self):
        return [
            Activate(self),
            Clone(self),
            Copy(self),
            Create(self),
            Info(self),
            List(self),
            Localize(self),
            Publish(self),
            Remove(self),
            Repo(self),
            Version(self),
        ]


class Info(cli.CLI):
    '''Show Module info'''

    usage = 'cpenv info [-h] [<modules>...]'

    def setup_parser(self, parser):
        parser.add_argument(
            'modules',
            help='Space separated list of modules.',
            nargs='+',
        )

    def run(self, args):
        cli.echo()
        cli.echo('- Resolving modules...', end='')
        try:
            module_specs = api.resolve(*args.modules)
        except ResolveError:
            cli.echo('OOPS!')
            cli.echo()
            cli.echo('Error: failed to resolve %s' % args.modules)
            sys.exit(1)
        cli.echo('OK!')

        cli.echo()
        for spec in module_specs:
            cli.echo(cli.format_section(
                spec.real_name,
                [(k, str(v)) for k, v in sorted(spec._asdict().items())]
            ))
            cli.echo()


class Activate(cli.CLI):
    '''Activate a list of Modules.'''

    usage = 'cpenv activate [-h] [<modules>...]'

    def setup_parser(self, parser):
        parser.add_argument(
            'modules',
            help='Space separated list of modules.',
            nargs='+',
        )

    def run(self, args):
        cli.echo()
        cli.echo('- Resolving modules...', end='')
        try:
            activated_modules = api.activate(*args.modules)
        except ResolveError:
            cli.echo('OOPS!')
            cli.echo()
            cli.echo('Error: failed to resolve %s' % args.modules)
            sys.exit(1)
        cli.echo('OK!')

        cli.echo()
        for module in activated_modules:
            cli.echo('  ' + module.real_name)
        cli.echo()

{'fraction_non_alphanumeric': 0.1202139037433155, 'fraction_numerical': 0.0010695187165775401, 'mean_word_length': 1.8529591214154972, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '7344964', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1349, 'n_words': 371}