Let’s monky patch!¶
Did you want to further expand ‘sphinx-quickstart-plus’? Editing ‘sphinx-quickstart-plus’ source code for extension is not cool.
Let’s monky patch!
Below is an example of a simple extension.
from sphinx_qsp import quickstart_plus
# Setting your extension.
your_extension = quickstart_plus.Extension(
"ext_your_ext", "your extensions description.",
conf_py="""
# ----Your Extension
import your_extension_package
extension.append("your-extension_name")
)
""",
package=["your_extension_packge"]
)
# Add your extension.
quickstart_plus.qsp_extensions.extend([
your_extension
])
# Run sphinx-quickstart-plus.
quickstart_plus.main()
The base class of extension is the following code.
class Extension(object):
def __init__(self, key, description, conf_py=None, new_makefile=None,
makefile=None, package=None):
self.key = key
self.description = description
self.conf_py = conf_py
self.new_makefile = new_makefile
self.makefile = makefile
self.package = package or []
# noinspection PyUnusedLocal
def extend_conf_py(self, d):
return self.conf_py
def extend_makefile(self, d, make_mode):
return self.new_makefile if make_mode else self.makefile
The extended class of ‘sphinx-autobuild’ is the following code.
class AutoBuildExtension(Extension):
def extend_makefile(self, d, make_mode):
if d['batchfile']:
batchfile_path = os.path.join(d['path'], 'auto_build.bat')
source_dir = d['sep'] and 'source' or '.'
build_dir = d['sep'] and 'build' or d['dot'] + 'build'
open(batchfile_path, "w").write(
AUTO_BUILD_BATCH.format(
build_dir=build_dir, source_dir=source_dir,
AUTOBUILD_IGNORE=" ".join(AUTOBUILD_IGNORE),
)
)
makefile = self.new_makefile if make_mode else self.makefile
return makefile.format(" ".join(AUTOBUILD_IGNORE))