<commit_before># Copyright 2014 ARM Limited
#
# Licensed under the Apache License, Version 2.0
# See LICENSE file for details.

# standard library modules, , ,
from __future__ import print_function
import logging
import os

# colorama, BSD 3-Clause license, cross-platform terminal colours, pip install colorama
import colorama

# validate, , validate things, internal
from .lib import validate
# access, , get components (and check versions), internal
from .lib import access
# fsutils, , misc filesystem utils, internal
from .lib import fsutils

def addOptions(parser):
    parser.add_argument('--all', '-a', dest='show_all', default=False, action='store_true',
        help='Show all dependencies (including repeats, and test-only dependencies)'
    )
    parser.add_argument('--json', '-j', dest='json', default=False, action='store_true',
        help='Output json representation of dependencies.'
    )

def execCommand(args, following_args):
    c = validate.currentDirectoryModule()
    if not c:
        return 1

    if not args.target:
        logging.error('No target has been set, use "yotta target" to set one.')
        return 1

    target, errors = c.satisfyTarget(args.target)
    if errors:
        for error in errors:
            logging.error(error)
        return 1

    installed_modules = c.getDependenciesRecursive(
                      target = target,
        available_components = [(c.getName(), c)],
                        test = True
    )
    if args.json:
        dependency_graph = resolveDependencyGraph(target, c, installed_modules)
        print(formatDependencyGraphAsJSON(dependency_graph))
    else:
        putln(
            ComponentDepsFormatter(
                               target = target,
                 available_components = installed_modules,
                                plain = args.plain,
                             list_all = args.show_all
            ).format(
                c, [c.getName()]
            )
        )

def formatDependencyGraphAsJSON(dep_graph):
    from .lib import ordered_json
    return ordered_json.dumps(dep_graph)

def resolveDependencyGraph(target, top_component, available_modules, processed=None):
    from collections import OrderedDict
    r = OrderedDict()

    if processed is None:
        processed = set()

    r['name']     = top_component.getName(),
    r['version']  = str(top_component.getVersion())
    r['path']     = top_component.path
    if top_component.installedLinked():
        r['linkedTo'] = fsutils.realpath(top_component.path)<commit_msg>remove errant comma making the name property a list<commit_after># Copyright 2014 ARM Limited
#
# Licensed under the Apache License, Version 2.0
# See LICENSE file for details.

# standard library modules, , ,
from __future__ import print_function
import logging
import os

# colorama, BSD 3-Clause license, cross-platform terminal colours, pip install colorama
import colorama

# validate, , validate things, internal
from .lib import validate
# access, , get components (and check versions), internal
from .lib import access
# fsutils, , misc filesystem utils, internal
from .lib import fsutils

def addOptions(parser):
    parser.add_argument('--all', '-a', dest='show_all', default=False, action='store_true',
        help='Show all dependencies (including repeats, and test-only dependencies)'
    )
    parser.add_argument('--json', '-j', dest='json', default=False, action='store_true',
        help='Output json representation of dependencies.'
    )

def execCommand(args, following_args):
    c = validate.currentDirectoryModule()
    if not c:
        return 1

    if not args.target:
        logging.error('No target has been set, use "yotta target" to set one.')
        return 1

    target, errors = c.satisfyTarget(args.target)
    if errors:
        for error in errors:
            logging.error(error)
        return 1

    installed_modules = c.getDependenciesRecursive(
                      target = target,
        available_components = [(c.getName(), c)],
                        test = True
    )
    if args.json:
        dependency_graph = resolveDependencyGraph(target, c, installed_modules)
        print(formatDependencyGraphAsJSON(dependency_graph))
    else:
        putln(
            ComponentDepsFormatter(
                               target = target,
                 available_components = installed_modules,
                                plain = args.plain,
                             list_all = args.show_all
            ).format(
                c, [c.getName()]
            )
        )

def formatDependencyGraphAsJSON(dep_graph):
    from .lib import ordered_json
    return ordered_json.dumps(dep_graph)

def resolveDependencyGraph(target, top_component, available_modules, processed=None):
    from collections import OrderedDict
    r = OrderedDict()

    if processed is None:
        processed = set()

    r['name']     = top_component.getName()
    r['version']  = str(top_component.getVersion())
    r['path']     = top_component.path
    if top_component.installedLinked():
        r['linkedTo'] = fsutils.realpath(top_component.path)
{'fraction_non_alphanumeric': 0.09143855562026791, 'fraction_numerical': 0.0038827412152980002, 'mean_word_length': 2.6103714085494043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '565894', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1332, 'n_words': 399}