# Path: templar/api/rules/core.py
# class Rule:
#     """Represents a preprocessor or postprocessor rule. Rules are applied in the order that they
#     are listed in the Config.
# 
#     When constructing a rule, the arguments `src` and `dst` are regular expressions; Templar will
#     only apply a rule if the source and destination of the publishing pipeline match the regexes.
#     """
#     def __init__(self, src=None, dst=None):
#         if src is not None and not isinstance(src, str):
#             raise InvalidRule(
#                     "Rule's source pattern must be a string or None, "
#                     "but was type '{}'".format(type(src).__name__))
#         if dst is not None and not isinstance(dst, str):
#             raise InvalidRule(
#                     "Rule's destination pattern must be a string or None, "
#                     "but was type '{}'".format(type(src).__name__))
#         self._src_pattern = src
#         self._dst_pattern = dst
# 
#     def applies(self, src, dst):
#         """Checks if this rule applies to the given src and dst paths, based on the src pattern and
#         dst pattern given in the constructor.
# 
#         If src pattern was None, this rule will apply to any given src path (same for dst).
#         """
#         if self._src_pattern and (src is None or re.search(self._src_pattern, src) is None):
#             return False
#         elif self._dst_pattern and (dst is None or re.search(self._dst_pattern, dst) is None):
#             return False
#         return True
# 
#     def apply(self, content):
#         """Applies this rule to the given content. A rule can do one or more of the following:
# 
#         - Return a string; this is taken to be the transformed version of content, and will be used
#           as the new content after applying this rule.
#         - Modify variables (a dict). Usually, Rules that modify this dictionary will add new
#           variables. However, a Rule can also delete or update key/value pairs in the dictionary.
#         """
#         raise NotImplementedError
# 
# Path: templar/exceptions.py
# class TemplarError(Exception):
#     """Top-level exception for Templar."""
#     pass


from templar.api.rules.core import Rule
from templar.exceptions import TemplarError
import importlib.machinery
import os.path
    def to_builder(self):
        return ConfigBuilder(
                self._template_dirs,
                self._variables,
                self._recursively_evaluate_jinja_expressions,
                self._compiler_rules,
                self._preprocess_rules,
                self._postprocess_rules)


def import_config(config_path):
    """Import a Config from a given path, relative to the current directory.

    The module specified by the config file must contain a variable called `configuration` that is
    assigned to a Config object.
    """
    if not os.path.isfile(config_path):
        raise ConfigBuilderError(
                'Could not find config file: ' + config_path)
    loader = importlib.machinery.SourceFileLoader(config_path, config_path)
    module = loader.load_module()

    if not hasattr(module, 'config') or not isinstance(module.config, Config):
        raise ConfigBuilderError(
            'Could not load config file "{}": config files must contain '
            'a variable called "config" that is '
            'assigned to a Config object.'.format(config_path))
    return module.config



# Path: templar/api/rules/core.py
# class Rule:
#     """Represents a preprocessor or postprocessor rule. Rules are applied in the order that they
#     are listed in the Config.
# 
#     When constructing a rule, the arguments `src` and `dst` are regular expressions; Templar will
#     only apply a rule if the source and destination of the publishing pipeline match the regexes.
#     """
#     def __init__(self, src=None, dst=None):
#         if src is not None and not isinstance(src, str):
#             raise InvalidRule(
#                     "Rule's source pattern must be a string or None, "
#                     "but was type '{}'".format(type(src).__name__))
#         if dst is not None and not isinstance(dst, str):
#             raise InvalidRule(
#                     "Rule's destination pattern must be a string or None, "
#                     "but was type '{}'".format(type(src).__name__))
#         self._src_pattern = src
#         self._dst_pattern = dst
# 
#     def applies(self, src, dst):
#         """Checks if this rule applies to the given src and dst paths, based on the src pattern and
#         dst pattern given in the constructor.
# 
#         If src pattern was None, this rule will apply to any given src path (same for dst).
#         """
#         if self._src_pattern and (src is None or re.search(self._src_pattern, src) is None):
#             return False
#         elif self._dst_pattern and (dst is None or re.search(self._dst_pattern, dst) is None):
#             return False
#         return True
# 
#     def apply(self, content):
#         """Applies this rule to the given content. A rule can do one or more of the following:
# 
#         - Return a string; this is taken to be the transformed version of content, and will be used
#           as the new content after applying this rule.
#         - Modify variables (a dict). Usually, Rules that modify this dictionary will add new
#           variables. However, a Rule can also delete or update key/value pairs in the dictionary.
#         """
#         raise NotImplementedError
# 
# Path: templar/exceptions.py
# class TemplarError(Exception):
#     """Top-level exception for Templar."""
#     pass


# Path: templar/api/config.py
from templar.api.rules.core import Rule
from templar.exceptions import TemplarError
import importlib.machinery
import os.path

    def to_builder(self):
        return ConfigBuilder(
                self._template_dirs,
                self._variables,
                self._recursively_evaluate_jinja_expressions,
                self._compiler_rules,
                self._preprocess_rules,
                self._postprocess_rules)


def import_config(config_path):
    """Import a Config from a given path, relative to the current directory.

    The module specified by the config file must contain a variable called `configuration` that is
    assigned to a Config object.
    """
    if not os.path.isfile(config_path):
        raise ConfigBuilderError(
                'Could not find config file: ' + config_path)
    loader = importlib.machinery.SourceFileLoader(config_path, config_path)
    module = loader.load_module()

    if not hasattr(module, 'config') or not isinstance(module.config, Config):
        raise ConfigBuilderError(
            'Could not load config file "{}": config files must contain '
            'a variable called "config" that is '
            'assigned to a Config object.'.format(config_path))
    return module.config



class ConfigBuilderError(TemplarError):