<commit_before>#!/usr/bin/env python
#
# -----------------------------------------------------------------------------
# Copyright (c) 2015   <NAME> <<EMAIL>>
# Copyright (c) 2015   Indiana University
#
# This file is part of genhub (http://github.com/standage/genhub) and is
# licensed under the BSD 3-clause license: see LICENSE.txt.
# -----------------------------------------------------------------------------

"""Module for handling genome configuration files."""

from __future__ import print_function
import itertools
import os
import pkg_resources
import tempfile
import yaml
import genhub


def load_genome(label, user_dirs=None):
    """
    Load a genome configuration file.

    - `label`: the filename of the genome configuration file, without `.yml`
      extension
    - `user_dir`: a list of user-specified directories in which to look for
      configuration files; if specified, they take precedence over the primary
      GenHub genome configuration directory
    """
    cfgdirs = list()
    if user_dirs:
        cfgdirs.extend(user_dirs)
    genhubdir = pkg_resources.resource_filename('genhub', 'genomes')
    cfgdirs.append(genhubdir)

    for cfgdir in cfgdirs:
        cfgfile = '%s/%s.yml' % (cfgdir, label)
        if os.path.isfile(cfgfile):
            with open(cfgfile, 'r') as infile:
                return yaml.load(infile)

    message = 'genome configuration file "%s.yml" not found' % label
    raise FileNotFoundError(message)


def load_genomes(labels, user_dirs=None):
    """Load a list of genome configuration files from memory."""<commit_msg>Python 2.7 compatibility for FileNotFoundError<commit_after>#!/usr/bin/env python
#
# -----------------------------------------------------------------------------
# Copyright (c) 2015   <NAME> <<EMAIL>>
# Copyright (c) 2015   Indiana University
#
# This file is part of genhub (http://github.com/standage/genhub) and is
# licensed under the BSD 3-clause license: see LICENSE.txt.
# -----------------------------------------------------------------------------

"""Module for handling genome configuration files."""

from __future__ import print_function
import itertools
import os
import pkg_resources
import tempfile
import yaml
import genhub
try:
    FileNotFoundError
except NameError:
    FileNotFoundError = IOError


def load_genome(label, user_dirs=None):
    """
    Load a genome configuration file.

    - `label`: the filename of the genome configuration file, without `.yml`
      extension
    - `user_dir`: a list of user-specified directories in which to look for
      configuration files; if specified, they take precedence over the primary
      GenHub genome configuration directory
    """
    cfgdirs = list()
    if user_dirs:
        cfgdirs.extend(user_dirs)
    genhubdir = pkg_resources.resource_filename('genhub', 'genomes')
    cfgdirs.append(genhubdir)

    for cfgdir in cfgdirs:
        cfgfile = '%s/%s.yml' % (cfgdir, label)
        if os.path.isfile(cfgfile):
            with open(cfgfile, 'r') as infile:
                return yaml.load(infile)

    message = 'genome configuration file "%s.yml" not found' % label
    raise FileNotFoundError(message)


def load_genomes(labels, user_dirs=None):
    """Load a list of genome configuration files from memory."""
{'fraction_non_alphanumeric': 0.17954960438222764, 'fraction_numerical': 0.006086427267194157, 'mean_word_length': 2.3643807574206757, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2523514', 'n_tokens_mistral': 930, 'n_tokens_neox': 861, 'n_words': 295}