Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
allow_exceptions = self.code_block_specifier.allow_exceptions
with systemtools.RedirectedStreams(self, self):
is_incomplete_statement = console.push(line)
if console.errored:
if allow_exceptions:
console.unregister_error()
else:
message = 'Abjad-book error on '
if self.document_source:
message += str(self.document_source)
message += ':{}'
else:
message += 'line number {}'
line_number += self.starting_line_number
message = message.format(line_number)
message = bold(red(message))
message += '\n '
message = message + '\n '.join(self.current_lines)
raise abjad.book.AbjadBookError(message)
return is_incomplete_statement
print('''
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).''')
if 'path' in d:
print(bold('''
Selected root path: %s''' % d['path']))
else:
print('''
Enter the root path for documentation.''')
do_prompt(d, 'path', 'Root path for the documentation', '.', is_path)
while path.isfile(path.join(d['path'], 'conf.py')) or \
path.isfile(path.join(d['path'], 'source', 'conf.py')):
print()
print(bold('Error: an existing conf.py has been found in the '
'selected root path.'))
print('sphinx-quickstart will not overwrite existing Sphinx projects.')
print()
do_prompt(d, 'path', 'Please enter a new root path (or just Enter '
'to exit)', '', is_path)
if not d['path']:
sys.exit(1)
if 'sep' not in d:
print('''
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.''')
do_prompt(d, 'sep', 'Separate source and build directories (y/n)', 'n',
boolean)
def finish(self):
super(DjangoStandaloneHTMLBuilder, self).finish()
self.info(bold("writing templatebuiltins.js..."))
xrefs = self.env.domaindata["std"]["objects"]
templatebuiltins = {
"ttags": [n for ((t, n), (l, a)) in xrefs.items()
if t == "templatetag" and l == "ref/templates/builtins"],
"tfilters": [n for ((t, n), (l, a)) in xrefs.items()
if t == "templatefilter" and l == "ref/templates/builtins"],
}
outfilename = os.path.join(self.outdir, "templatebuiltins.js")
with open(outfilename, 'w') as fp:
fp.write('var django_template_builtins = ')
json.dump(templatebuiltins, fp)
fp.write(';\n')
def cli_docs(app):
info(bold('creating CLI documentation...'))
documented_cmds, undocumented_cmds = get_cli_docs()
documented_cmds.sort(key=lambda x: x[0])
undocumented_cmds.sort()
documented = [' '*4 + c[0] for c in documented_cmds]
undocumented = [' * ' + c for c in undocumented_cmds]
raw = (CLI_INDEX % cli_index_strings()[:5]).format(documented='\n'.join(documented),
undocumented='\n'.join(undocumented))
if not os.path.exists('cli'):
os.makedirs('cli')
update_cli_doc('cli-index', raw, app)
for cmd, parser in documented_cmds:
usage = [mark_options(i) for i in parser.usage.replace('%prog', cmd).splitlines()]
def finish(self):
super(DjangoStandaloneHTMLBuilder, self).finish()
if json is None:
self.warn("cannot create templatebuiltins.js due to missing simplejson dependency")
return
self.info(bold("writing templatebuiltins.js..."))
xrefs = self.env.domaindata["std"]["objects"]
templatebuiltins = {
"ttags": [n for ((t, n), (l, a)) in xrefs.items()
if t == "templatetag" and l == "ref/templates/builtins"],
"tfilters": [n for ((t, n), (l, a)) in xrefs.items()
if t == "templatefilter" and l == "ref/templates/builtins"],
}
outfilename = os.path.join(self.outdir, "templatebuiltins.js")
f = open(outfilename, 'wb')
f.write('var django_template_builtins = ')
json.dump(templatebuiltins, f)
f.write(';\n')
f.close();
def build(self, docnames, summary=None, method='update'):
if summary:
self.info(bold('building [%s]: ' % self.name), nonl=1)
self.info(summary)
updated_docnames = []
# while reading, collect all warnings from docutils
warnings = []
self.env.set_warnfunc(warnings.append)
self.info(bold('updating environment: '), nonl=1)
iterator = self.env.update(self.config, self.srcdir, self.doctreedir, self.app)
# the first item in the iterator is a summary message
self.info(iterator.next())
for docname in self.status_iterator(iterator, 'reading sources... ', purple):
updated_docnames.append(docname)
# nothing further to do, the environment has already done the reading
for warning in warnings:
if warning.strip():
self.warn(warning)
self.env.set_warnfunc(self.warn)
if updated_docnames:
# save the environment
self.info(bold('pickling environment... '), nonl=True)
self.env.topickle(path.join(self.doctreedir, ENV_PICKLE_FILENAME))
self.info('done')
for docname in self.status_iterator(iterator, 'reading sources... ', purple):
updated_docnames.append(docname)
# nothing further to do, the environment has already done the reading
for warning in warnings:
if warning.strip():
self.warn(warning)
self.env.set_warnfunc(self.warn)
if updated_docnames:
# save the environment
self.info(bold('pickling environment... '), nonl=True)
self.env.topickle(path.join(self.doctreedir, ENV_PICKLE_FILENAME))
self.info('done')
# global actions
self.info(bold('checking consistency... '), nonl=True)
self.env.check_consistency()
self.info('done')
else:
if method == 'update' and not docnames:
self.info(bold('no targets are out of date.'))
return
# another indirection to support methods which don't build files
# individually
self.write(docnames, updated_docnames, method)
# finish (write static files etc.)
self.finish()
status = self.app.statuscode == 0 and 'succeeded' or 'finished with problems'
if self.app._warncount:
self.info(bold('build %s, %s warning%s.' %
def ask_user(d):
"""Wrap sphinx.quickstart.ask_user, and add additional questions."""
# Print welcome message
msg = bold('Welcome to the Hieroglyph %s quickstart utility.') % (
version(),
)
print(msg)
msg = """
This will ask questions for creating a Hieroglyph project, and then ask
some basic Sphinx questions.
"""
print(msg)
# set a few defaults that we don't usually care about for Hieroglyph
d.update({
'version': datetime.date.today().strftime('%Y.%m.%d'),
'release': datetime.date.today().strftime('%Y.%m.%d'),
'make_mode': True,
})
ordered_items.sort(
cmp=lambda x,y: cmp(x['pubDate'],y['pubDate']),
reverse=True)
for item in ordered_items:
feed.items.append(item)
path = os.path.join(app.builder.outdir,
app.config.feed_filename)
feed.format_rss2_file(path)
from os import path
from sphinx.application import ENV_PICKLE_FILENAME
from sphinx.util.console import bold
# save the environment
builder = app.builder
builder.info(bold('pickling environment... '), nonl=True)
builder.env.topickle(path.join(builder.doctreedir, ENV_PICKLE_FILENAME))
builder.info('done')
# global actions
builder.info(bold('checking consistency... '), nonl=True)
builder.env.check_consistency()
builder.info('done')
self.env.check_consistency()
self.info('done')
else:
if method == 'update' and not docnames:
self.info(bold('no targets are out of date.'))
return
# another indirection to support methods which don't build files
# individually
self.write(docnames, updated_docnames, method)
# finish (write static files etc.)
self.finish()
status = self.app.statuscode == 0 and 'succeeded' or 'finished with problems'
if self.app._warncount:
self.info(bold('build %s, %s warning%s.' %
(status, self.app._warncount,
self.app._warncount != 1 and 's' or '')))
else:
self.info(bold('build %s.' % status))