<commit_before>"""Clowder yaml printing"""
import os
import sys
from clowder.utility.clowder_utilities import parse_yaml
from clowder.utility.print_utilities import print_open_file_error

# Disable errors shown by pylint for no specified exception types
# pylint: disable=W0702

def print_yaml(root_directory):
    """Print current clowder yaml"""
    yaml_file = os.path.join(root_directory, 'clowder.yaml')
    parsed_yaml = parse_yaml(yaml_file)
    yaml_files = []
    while True:
        yaml_files.append(yaml_file)
        if 'import' not in parsed_yaml:
            break
        imported_yaml = parsed_yaml['import']
        if imported_yaml == 'default':
            yaml_file = os.path.join(root_directory,
                                     '.clowder',
                                     'clowder.yaml')
        else:
            yaml_file = os.path.join(root_directory,
                                     '.clowder',
                                     'versions',
                                     imported_yaml,
                                     'clowder.yaml')
        parsed_yaml = parse_yaml(yaml_file)
    for parsed_yaml in reversed(yaml_files):
        if os.path.isfile(yaml_file):
            try:
                with open(yaml_file) as file:
                    contents = file.read()
                    print(contents)
            except Exception as err:
                print_open_file_error(yaml_file)
                sys.exit(1)<commit_msg>Better output formatting for printing clowder.yaml<commit_after>"""Clowder yaml printing"""
import os
import sys
from clowder.utility.clowder_utilities import parse_yaml
from clowder.utility.print_utilities import (
    format_path,
    format_symlink_target,
    print_open_file_error,
    remove_prefix
)

# Disable errors shown by pylint for no specified exception types
# pylint: disable=W0702

def print_yaml(root_directory):
    """Print current clowder yaml"""
    yaml_file = os.path.join(root_directory, 'clowder.yaml')
    parsed_yaml = parse_yaml(yaml_file)
    yaml_files = []
    while True:
        yaml_files.append(yaml_file)
        if 'import' not in parsed_yaml:
            break
        imported_yaml = parsed_yaml['import']
        if imported_yaml == 'default':
            yaml_file = os.path.join(root_directory,
                                     '.clowder',
                                     'clowder.yaml')
        else:
            yaml_file = os.path.join(root_directory,
                                     '.clowder',
                                     'versions',
                                     imported_yaml,
                                     'clowder.yaml')
        parsed_yaml = parse_yaml(yaml_file)
    for parsed_yaml in reversed(yaml_files):
        if os.path.isfile(yaml_file):
            try:
                with open(yaml_file) as file:
                    contents = file.read()
                    print('-' * 80)
                    if os.path.islink(yaml_file):
                        path = format_symlink_target(yaml_file)
                        path = remove_prefix(path, root_directory)
                        path = remove_prefix(path, '/')
                        print()
                        print(format_path('clowder.yaml') + ' -> ' + format_path(path))
                        print()
                    else:
                        path = remove_prefix(path, root_directory)
                        path = remove_prefix(path, '/')
                        print('\n' + format_path(path) + '\n')
                    print(contents)
            except:
                print_open_file_error(yaml_file)
                sys.exit(1)
    sys.exit() # exit early to prevent printing extra newline
{'fraction_non_alphanumeric': 0.08249068653539117, 'fraction_numerical': 0.0031931878658861094, 'mean_word_length': 1.5043304463690872, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3617088', 'n_tokens_mistral': 1034, 'n_tokens_neox': 980, 'n_words': 208}