Ejemplo n.º 1
0
def add_sphinx_build_options(action_spec, action, options, conf):
    """
    :param dict action_spec: A reference to a dictionary that defines a

    Modifies the ``action_spec`` document to define a build operation with the
    appropriate options, based on the operation (``action``) and the
    ``options``.

    If the options do not specify one or more editions in a project that uses
    editions, will add all configured editions to the build operation.
    """

    sphinx_builders = avalible_sphinx_builders()

    if action in sphinx_builders:
        action_spec['builders'].add(action)

    for build_option in options:
        if build_option in sphinx_builders:
            action_spec['builders'].add(build_option)
        elif build_option in conf.project.edition_list:
            action_spec['editions'].add(build_option)
        elif build_option in conf.system.files.data.integration:
            action_spec['languages'].add(build_option)
        elif build_option == 'fast' and action != 'publish' and 'publish' not in options:
            conf.runstate.fast = True

    if 'editions' in conf.project and len(action_spec['editions']) == 0:
        action_spec['editions'].update(conf.project.edition_list)
Ejemplo n.º 2
0
def add_sphinx_build_options(action_spec, action, options, conf):
    """
    :param dict action_spec: A reference to a dictionary that defines a

    Modifies the ``action_spec`` document to define a build operation with the
    appropriate options, based on the operation (``action``) and the
    ``options``.

    If the options do not specify one or more editions in a project that uses
    editions, will add all configured editions to the build operation.
    """

    sphinx_builders = avalible_sphinx_builders()

    if action in sphinx_builders:
        action_spec['builders'].add(action)

    for build_option in options:
        if build_option in sphinx_builders:
            action_spec['builders'].add(build_option)
        elif build_option in conf.project.edition_list:
            action_spec['editions'].add(build_option)
        elif build_option in conf.system.files.data.integration:
            action_spec['languages'].add(build_option)
        elif build_option == 'fast' and action != 'publish' and 'publish' not in options:
            conf.runstate.fast = True

    if 'editions' in conf.project and len(action_spec['editions']) == 0:
        action_spec['editions'].update(conf.project.edition_list)
Ejemplo n.º 3
0
    def builder(self, value):
        if not isinstance(value, list):
            value = [value]

        for idx, builder in enumerate(value):
            if builder.startswith('pdf'):
                builder = 'latex'
                value[idx] = builder

            if builder not in avalible_sphinx_builders():
                raise TypeError("{0} is not a valid builder".format(builder))

        self.state['builder'] = value
Ejemplo n.º 4
0
    def builder(self, value):
        if not isinstance(value, list):
            value = [value]

        for idx, builder in enumerate(value):
            if builder.startswith('pdf'):
                builder = 'latex'
                value[idx] = builder

            if builder not in avalible_sphinx_builders():
                raise TypeError("{0} is not a valid builder".format(builder))

        self.state['builder'] = value
Ejemplo n.º 5
0
def run_make_operations(targets, conf):
    """
    :param list targets: A list of tuples in the form of ``(<action>, [option,
         option])`` that define build targets.

    :param Configuration conf: The top level configuration object.

    Parses the ``targets`` list and runs tasks defined, including all specified
    sphinx targets, all ``push`` deployment targets, and will create the ``env``
    packages. Noteworthy behavior:

    - The order of options *except* for the action in the first option is not
      important.

    - If you run ``push`` target with the ``deploy`` option
      (i.e. ``push-deploy`` or ``push-<edition>-deploy``), ``giza`` will *not*
      run the ``publish`` Sphinx build.

    - This interface assumes that all deployment targets (defined in each
      project begin with ``push-`` or ``stage-``.) If you have a project with
      different deployment targets, you will need to call ``giza deploy``
      directly.

    - The ``env`` cache targets take the same options as the Sphinx builders and
      package the environment for only those builders. If you specify ``env``
      after a Sphinx target, ``giza`` will build the cache for only that
      package.
    """

    sphinx_opts = {
        "worker": sphinx_publication,
        "languages": set(),
        "editions": set(),
        "builders": set()
    }
    push_opts = {"worker": deploy_tasks, "targets": set(), "type": None}
    packaging_opts = {}

    sphinx_builders = avalible_sphinx_builders()
    deploy_configs = dict_from_list('target', conf.system.files.data.push)

    tasks = []
    for action, options in targets:
        if action in sphinx_builders:
            tasks.append(sphinx_opts)

            add_sphinx_build_options(sphinx_opts, action, options, conf)
        elif action in ('stage', 'push'):
            tasks.append(push_opts)
            push_opts['type'] = action

            if 'deploy' not in options:
                sphinx_opts['builders'].add('publish')
                tasks.append(sphinx_opts)
                add_sphinx_build_options(sphinx_opts, action, options, conf)
                conf.runstate.fast = False

            if action in deploy_configs:
                push_opts['targets'].add(action)

            for build_option in options:
                deploy_target_name = hyph_concat(action, build_option)

                if build_option in deploy_configs:
                    push_opts['targets'].add(build_option)
                elif deploy_target_name in deploy_configs:
                    push_opts['targets'].add(deploy_target_name)
        elif action.startswith('env'):
            if len(packaging_opts) > 0:
                packaging_opts = copy.copy(sphinx_opts)
                packaging_opts['worker'] = env_package_worker

            tasks.append(packaging_opts)
            add_sphinx_build_options(packaging_opts, False, options, conf)
        else:
            logger.error(
                'target: {0} not defined in the make interface'.format(action))

    with BuildApp.context(conf) as app:
        if sphinx_opts in tasks:
            conf.runstate.languages_to_build = list(sphinx_opts['languages'])
            conf.runstate.editions_to_build = list(sphinx_opts['editions'])
            conf.runstate.builder = list(sphinx_opts['builders'])

            if 'publish' in conf.runstate.builder:
                conf.runstate.fast = False

            derive_command('sphinx', conf)

            sphinx_opts['worker'](conf, conf.runstate, app)

        if push_opts in tasks:
            if len(push_opts['targets']) == 0:
                for lang, edition in itertools.product(
                        conf.runstate.languages_to_build,
                        conf.runstate.editions_to_build):
                    push_target_name = [push_opts['type']]
                    for opt in (edition, lang):
                        if opt is not None:
                            push_target_name.append(opt)
                    push_target_name = '-'.join(push_target_name)
                    push_opts['targets'].add(push_target_name)

            conf.runstate.push_targets = list(push_opts['targets'])
            push_opts['worker'](conf, app)
            derive_command('deploy', conf)

        if packaging_opts in tasks:
            derive_command('env', conf)

            task = app.add('task')
            task.job = env_package_worker
            task.args = (conf.runstate, conf)
            task.target = False
            task.dependency = False
Ejemplo n.º 6
0
def get_existing_builders(conf):
    return [
        b for b in avalible_sphinx_builders() if os.path.isdir(
            os.path.join(conf.paths.projectroot, conf.paths.branch_output, b))
    ]
Ejemplo n.º 7
0
def get_existing_builders(conf):
    return [b
            for b in avalible_sphinx_builders()
            if os.path.isdir(os.path.join(conf.paths.projectroot, conf.paths.branch_output, b))]
Ejemplo n.º 8
0
def run_make_operations(targets, conf):
    """
    :param list targets: A list of tuples in the form of ``(<action>, [option,
         option])`` that define build targets.

    :param Configuration conf: The top level configuration object.

    Parses the ``targets`` list and runs tasks defined, including all specified
    sphinx targets, all ``push`` deployment targets, and will create the ``env``
    packages. Noteworthy behavior:

    - The order of options *except* for the action in the first option is not
      important.

    - If you run ``push`` target with the ``deploy`` option
      (i.e. ``push-deploy`` or ``push-<edition>-deploy``), ``giza`` will *not*
      run the ``publish`` Sphinx build.

    - This interface assumes that all deployment targets (defined in each
      project begin with ``push-`` or ``stage-``.) If you have a project with
      different deployment targets, you will need to call ``giza deploy``
      directly.

    - The ``env`` cache targets take the same options as the Sphinx builders and
      package the environment for only those builders. If you specify ``env``
      after a Sphinx target, ``giza`` will build the cache for only that
      package.
    """

    sphinx_opts = {"languages": set(),
                   "editions": set(),
                   "builders": set()}
    push_opts = {"targets": set(),
                 "type": None}
    packaging_opts = {}

    sphinx_builders = avalible_sphinx_builders()
    deploy_configs = dict((item['target'], item) for item in conf.system.files.data.push)

    tasks = []
    for action, options in targets:
        if action in sphinx_builders:
            tasks.append(sphinx_opts)

            add_sphinx_build_options(sphinx_opts, action, options, conf)
        elif action in ('stage', 'push'):
            tasks.append(push_opts)
            push_opts['type'] = action

            if 'deploy' not in options:
                sphinx_opts['builders'].add('publish')
                tasks.append(sphinx_opts)
                add_sphinx_build_options(sphinx_opts, action, options, conf)
                conf.runstate.fast = False

            if action in deploy_configs:
                push_opts['targets'].add(action)

            for build_option in options:
                deploy_target_name = '-'.join((action, build_option))

                if build_option in deploy_configs:
                    push_opts['targets'].add(build_option)
                elif deploy_target_name in deploy_configs:
                    push_opts['targets'].add(deploy_target_name)
        elif action.startswith('env'):
            if len(packaging_opts) > 0:
                packaging_opts = copy.copy(sphinx_opts)

            tasks.append(packaging_opts)
            add_sphinx_build_options(packaging_opts, False, options, conf)
        else:
            logger.error('target: {0} not defined in the make interface'.format(action))

    app = BuildApp.new(pool_type=conf.runstate.runner,
                       force=conf.runstate.force,
                       pool_size=conf.runstate.pool_size)

    if sphinx_opts in tasks:
        conf.runstate.languages_to_build = list(sphinx_opts['languages'])
        conf.runstate.editions_to_build = list(sphinx_opts['editions'])
        conf.runstate.builder = list(sphinx_opts['builders'])

        if 'publish' in conf.runstate.builder:
            conf.runstate.fast = False

        derive_command('sphinx', conf)

        sphinx_publication(conf, app)

    if push_opts in tasks:
        if len(push_opts['targets']) == 0:
            for lang, edition in itertools.product(conf.runstate.languages_to_build,
                                                   conf.runstate.editions_to_build):
                push_target_name = [push_opts['type']]
                for opt in (edition, lang):
                    if opt is not None:
                        push_target_name.append(opt)
                push_target_name = '-'.join(push_target_name)
                push_opts['targets'].add(push_target_name)

        conf.runstate.push_targets = list(push_opts['targets'])
        deploy_tasks(conf, app)
        derive_command('deploy', conf)

    if packaging_opts in tasks:
        derive_command('env', conf)

        app.add(Task(job=env_package_worker,
                     args=(conf.runstate, conf),
                     target=True,
                     dependency=None))

    if len(app.queue) >= 1:
        app.run()