Skip to content

Commit

Permalink
some refactoring of the sphinx-plugin code
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Wolf committed Apr 16, 2015
1 parent 8c574e4 commit da7b228
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions src/main/python/pybuilder/plugins/python/sphinx_plugin.py
Expand Up @@ -28,6 +28,7 @@
from pybuilder.utils import assert_can_execute
from pybuilder.utils import execute_command
from pybuilder import scaffolding as SCAFFODING
from pybuilder.core import NAME_ATTRIBUTE

__author__ = 'Thomas Prebble', 'Marcel Wolf'

Expand Down Expand Up @@ -84,22 +85,38 @@ def assert_sphinx_quickstart_is_available(logger):
["sphinx-quickstart", "--version"], "sphinx", "plugin python.sphinx")


def run_build(task_name, logger, project):
logger.info("Running %s" % task_name)
log_file = project.expand_path(
"$dir_target/reports/{0}".format(task_name))
if task_name == "sphinx_quickstart":
build_command = get_sphinx_quickstart_command(project)

This comment has been minimized.

Copy link
@mriehl

mriehl Apr 16, 2015

Member

Imho the command should be built by the task. This would remove the need for a dispatch based on the task name.

if task_name == "sphinx_generate_documentation":
build_command = get_sphinx_build_command(project)

if project.get_property("verbose"):
logger.info(build_command)
exit_code = execute_command(build_command, log_file, shell=True)
if exit_code != 0:
raise BuildFailedException("Sphinx build command failed. See %s for details.", log_file)


@task("sphinx_generate_documentation", "Generates documentation with sphinx")
@depends("prepare")
def sphinx_generate(project, logger):
"""Runs sphinx-build against rst sources for the given project.
"""
task_name = getattr(sphinx_generate, NAME_ATTRIBUTE)
run_build(task_name, logger, project)


@task("sphinx_quickstart", "starts a new sphinx project")
@depends("prepare")
def sphinx_quickstart_generate(project, logger):
"""Runs sphinx-build against rst sources for the given project.
"""
logger.info("Running sphinx-quickstart")

log_file = project.expand_path(
"$dir_target/reports/{0}".format("sphinx-quickstart"))
build_command = get_sphinx_quickstart_command(project)
if project.get_property("verbose"):
logger.info(build_command)
exit_code = execute_command(build_command, log_file, shell=True)
if exit_code != 0:
raise BuildFailedException(
"Sphinx build command failed. See %s for details.", log_file)
task_name = getattr(sphinx_quickstart_generate, NAME_ATTRIBUTE)
run_build(task_name, logger, project)


def get_sphinx_quickstart_command(project):
Expand All @@ -118,26 +135,6 @@ def get_sphinx_quickstart_command(project):
return "sphinx-quickstart %s" % " ".join(options)


@task("sphinx_generate_documentation", "Generates documentation with sphinx")
@depends("prepare")
def sphinx_generate(project, logger):
"""Runs sphinx-build against rst sources for the given project.
"""
logger.info("Running sphinx-build")
log_file = project.expand_path(
"$dir_target/reports/{0}".format("sphinx-build"))
build_command = get_sphinx_build_command(project)
if project.get_property("verbose"):
logger.info(build_command)
exit_code = execute_command(build_command, log_file, shell=True)
logger.info("documentation was build as %s"
% project.doc_builder + ", check %s"
% DEFAULT_SPHINX_OUTPUT_DIR)
if exit_code != 0:
raise BuildFailedException(
"Sphinx build command failed. See %s for details.", log_file)


def get_sphinx_build_command(project):
"""Builds the sphinx-build command using properties.
"""
Expand Down

0 comments on commit da7b228

Please sign in to comment.