示例#1
0
    def _load_theme_config(self, name):
        """ Recursively load theme and any parent themes. """

        theme_dir = utils.get_theme_dir(name)
        self.dirs.append(theme_dir)

        try:
            file_path = os.path.join(theme_dir, 'elstir_theme.yml')
            with open(file_path, 'rb') as f:
                theme_config = utils.yaml_load(f)
                if theme_config is None:
                    theme_config = {}
        except OSError as e:
            log.debug(e)
            raise ValidationError(
                "The theme '{}' does not appear to have a configuration file. "
                "Please upgrade to a current version of the theme.".format(
                    name))

        log.debug("Loaded theme configuration for '%s' from '%s': %s", name,
                  file_path, theme_config)

        parent_theme = theme_config.pop('extends', None)
        if parent_theme:
            themes = utils.get_theme_names()
            if parent_theme not in themes:
                raise ValidationError(
                    "The theme '{}' inherits from '{}', which does not appear to be installed. "
                    "The available installed themes are: {}".format(
                        name, parent_theme, ', '.join(themes)))
            self._load_theme_config(parent_theme)

        self.static_templates.update(theme_config.pop('static_templates', []))
        self._vars.update(theme_config)
示例#2
0
    def test_get_themes_warning(self, mock_iter):

        theme1 = mock.Mock()
        theme1.name = 'elstir2'
        theme1.dist.name = 'elstir2'
        theme1.load().__file__ = "some/path1"

        theme2 = mock.Mock()
        theme2.name = 'elstir2'
        theme2.dist.name = 'elstir3'
        theme2.load().__file__ = "some/path2"

        mock_iter.return_value = [theme1, theme2]

        self.assertEqual(sorted(utils.get_theme_names()), sorted([
            'elstir2',
        ]))
示例#3
0
    def validate(self, value):
        if value is None and self.default is not None:
            value = {'name': self.default}

        if isinstance(value, str):
            value = {'name': value}

        themes = utils.get_theme_names()

        if isinstance(value, dict):
            if 'name' in value:
                if value['name'] is None or value['name'] in themes:
                    return value

                raise ValidationError(
                    "Unrecognised theme name: '{}'. The available installed themes "
                    "are: {}".format(value['name'], ', '.join(themes)))

            raise ValidationError("No theme name set.")

        raise ValidationError(
            'Invalid type "{}". Expected a string or key/value pairs.'.format(
                type(value)))
示例#4
0
    def test_get_themes(self):

        self.assertEqual(sorted(utils.get_theme_names()),
                         ['elstir', 'readthedocs'])
示例#5
0
        self.counter = utils.log_counter
        self.counter.setLevel(logging.WARNING)
        self.logger.addHandler(self.counter)


pass_state = click.make_pass_decorator(State, ensure=True)

clean_help = "Remove old files from the site_dir before building (the default)."
config_help = "Provide a specific elstir config"
dev_addr_help = (
    "IP address and port to serve documentation locally (default: "
    "localhost:8000)")
strict_help = ("Enable strict mode. This will cause elstir to abort the build "
               "on any warnings.")
theme_help = "The theme to use when building your documentation."
theme_choices = utils.get_theme_names()
site_dir_help = "The directory to output the result of the documentation build."
use_directory_urls_help = "Use directory URLs when building pages (the default)."
reload_help = "Enable the live reloading in the development server (this is the default)"
no_reload_help = "Disable the live reloading in the development server."
dirty_reload_help = "Enable the live reloading in the development server, but only re-build files that have changed"
commit_message_help = (
    "A commit message to use when committing to the "
    "Github Pages remote branch. Commit {sha} and elstir {version} are available as expansions"
)
remote_branch_help = ("The remote branch to commit to for Github Pages. This "
                      "overrides the value specified in config")
remote_name_help = ("The remote name to commit to for Github Pages. This "
                    "overrides the value specified in config")
force_help = "Force the push to the repository."
ignore_version_help = "Ignore check that build is not being deployed with an older version of MkDocs."
示例#6
0
    - Build with different configuration options.
    - Build documentation other than just elstir as it is relatively simple.
"""

import click
import logging
import os
import subprocess

from elstir import utils

log = logging.getLogger('elstir')

DIR = os.path.dirname(__file__)
elstir_CONFIG = os.path.abspath(os.path.join(DIR, '../../elstir.yml'))
elstir_THEMES = utils.get_theme_names()
TEST_PROJECTS = os.path.abspath(os.path.join(DIR, 'integration'))


@click.command()
@click.option('--output',
              help="The output directory to use when building themes",
              type=click.Path(file_okay=False, writable=True),
              required=True)
def main(output=None):

    log.propagate = False
    stream = logging.StreamHandler()
    formatter = logging.Formatter(
        "\033[1m\033[1;32m *** %(message)s *** \033[0m")
    stream.setFormatter(formatter)