in build_docs.py [0:0]
def run():
# try to import requirements, and complain if they can't be found.
try:
from sphinx import version_info as sphinx_version
print("Using Sphinx version %s.%s.%s" % sphinx_version[0:3])
except:
print(SPHINX_MISSING)
sys.exit(1)
build_target = 'html' # by default
cmd_switches = []
for arg in sys.argv[1:]:
if arg.startswith('--'):
cmd_switches.append(arg)
else:
# the only non-switch argument is the output format.
build_target = arg
print("Building '%s' target." % build_target)
#
# Step 0: empty the build dir if it's there.
#
check_and_remove_dir(BUILD_DIR)
check_and_remove_dir(SHARED_DIR)
check_and_remove_dir(OUTPUT_DIR)
#
# Step 1: grab the shared content and copy it into BUILD_DIR.
#
print("Getting shared content from " + AWS_SHARED_REPO)
try:
subprocess.check_call(['git', 'clone', '--depth', '1', AWS_SHARED_REPO,
SHARED_DIR])
except:
print(FAILED_CHECKOUT)
sys.exit(1)
shared_input_dir = os.path.join(SHARED_DIR, SHARED_SUBDIR)
print("Copying shared content from %s to %s" % (shared_input_dir,
BUILD_DIR))
copy_dir_contents_with_overwrite(shared_input_dir, BUILD_DIR)
#
# Step 2: copy the contents of SOURCE_DIR into the BUILD_DIR.
#
print("Copying doc sources from %s to %s" % (SOURCE_DIR, BUILD_DIR))
copy_dir_contents_with_overwrite(SOURCE_DIR, BUILD_DIR)
#
# Append the contents of any files in the 'build/_conf' directory to the
# project's conf.py file (so that shared content can add commonly-used
# extlinks, etc.).
#
conf_py_path = os.path.join(BUILD_DIR, 'conf.py')
extra_conf_path = os.path.join(BUILD_DIR, '_conf')
# first, open the conf.py file for appending...
with open(conf_py_path, 'a') as conf_file:
# now, add the contents of each file in alpha-sorted order.
for filename in sorted(os.listdir(extra_conf_path)):
print(" - %s" % filename)
conf_file.write('# ** added by extra conf file: %s **\n' % filename)
with open(os.path.join(extra_conf_path, filename), 'r') as extra_conf_file:
conf_file.write(extra_conf_file.read())
conf_file.write('# ** end of content from %s **\n' % filename)
#
# Step 3: build the docs
#
print("Building documentation.")
try:
subprocess.check_call(['sphinx-build', '-b', build_target, BUILD_DIR,
OUTPUT_DIR])
except:
print(FAILED_CHECKOUT)
sys.exit(1)
#
# Step 4: Clean up the build dir and shared content.
#
if '--noclean' not in cmd_switches:
print("Cleaning up.")
check_and_remove_dir(BUILD_DIR)
check_and_remove_dir(SHARED_DIR)
print("Finished! You'll find the built docs in the '%s' directory." %
OUTPUT_DIR)