<commit_before># Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import abc
import logging
import os.path

import gflags as flags
import pkg_resources

FLAGS = flags.FLAGS

flags.DEFINE_multistring('data_search_paths', ['.', 'data'],
                         'Additional paths to search for data files.')


class ResourceNotFound(ValueError):
  """Error raised when a resource could not be found on the search path."""
  pass


class ResourceLoader(object):
  """An interface for loading named resources."""

  __metaclass__ = abc.ABCMeta

  @abc.abstractmethod
  def ResourceExists(self, name):
    """Checks for existence of the resource 'name'.

    Args:
      name: string. Name of the resource. Typically a file name.

    Returns:<commit_msg>add a docstring<commit_after># Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This module defines an interface for finding named resources.

Due to license restrictions, not all software dependences can be shipped with
PerfKitBenchmarker.
Those that can be included in perfkitbenchmarker/data, and are loaded via a
PackageResourceLoader.

Users can specify additional paths to search for required data files using the
`--data_search_paths` flag.
"""

import abc
import logging
import os.path

import gflags as flags
import pkg_resources

FLAGS = flags.FLAGS

flags.DEFINE_multistring('data_search_paths', ['.', 'data'],
                         'Additional paths to search for data files. '
                         'These paths will be searched prior to using files '
                         'bundled with PerfKitBenchmarker')


class ResourceNotFound(ValueError):
  """Error raised when a resource could not be found on the search path."""
  pass


class ResourceLoader(object):
  """An interface for loading named resources."""

  __metaclass__ = abc.ABCMeta

  @abc.abstractmethod
  def ResourceExists(self, name):
    """Checks for existence of the resource 'name'.

    Args:
      name: string. Name of the resource. Typically a file name.

    Returns:
{'fraction_non_alphanumeric': 0.07306083038300612, 'fraction_numerical': 0.005149662053427744, 'mean_word_length': 3.659670164917541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2630226', 'n_tokens_mistral': 810, 'n_tokens_neox': 777, 'n_words': 379}