def __init__( self, payload, image_layout_specifier=None, image_render_specifier=None, ): from abjad.tools import abjadbooktools ImageOutputProxy.__init__( self, image_layout_specifier=image_layout_specifier, image_render_specifier=image_render_specifier, ) payload = copy.deepcopy(payload) if image_render_specifier is None: image_render_specifier = abjadbooktools.ImageRenderSpecifier() if (not image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet): payload = documentationtools.make_reference_manual_lilypond_file( payload) manager = systemtools.IOManager lilypond_file = manager._insert_expr_into_lilypond_file(payload) lilypond_file.file_initial_system_comments[:] = [] token = lilypondfiletools.LilyPondVersionToken("2.19.0", ) lilypond_file.file_initial_system_includes[0] = token if (image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet): lilypond_file.use_relative_includes = True lilypond_file.file_initial_user_includes[:] = [ image_render_specifier.stylesheet ] self._payload = lilypond_file
def __init__( self, payload, image_layout_specifier=None, image_render_specifier=None, ): from abjad.tools import abjadbooktools from abjad.tools import lilypondfiletools from abjad.tools import markuptools ImageOutputProxy.__init__( self, image_layout_specifier=image_layout_specifier, image_render_specifier=image_render_specifier, ) payload = copy.deepcopy(payload) if image_render_specifier is None: image_render_specifier = abjadbooktools.ImageRenderSpecifier() if (not image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet): payload = documentationtools.make_reference_manual_lilypond_file( payload) lilypond_file = payload assert isinstance(lilypond_file, lilypondfiletools.LilyPondFile) lilypond_file.header_block.tagline = markuptools.Markup('""') lilypond_file._date_time_token = None token = lilypondfiletools.LilyPondVersionToken("2.19.0", ) lilypond_file._lilypond_version_token = token if (image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet): if not lilypond_file.includes: lilypond_file._use_relative_includes = True includes = [image_render_specifier.stylesheet] lilypond_file._includes = tuple(includes) self._payload = lilypond_file
def __init__( self, payload, image_layout_specifier=None, image_render_specifier=None, ): from abjad.tools import abjadbooktools ImageOutputProxy.__init__( self, image_layout_specifier=image_layout_specifier, image_render_specifier=image_render_specifier, ) payload = copy.deepcopy(payload) if image_render_specifier is None: image_render_specifier = abjadbooktools.ImageRenderSpecifier() if ( not image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet ): payload = documentationtools.make_reference_manual_lilypond_file( payload) manager = systemtools.IOManager lilypond_file = manager._insert_expr_into_lilypond_file(payload) lilypond_file.file_initial_system_comments[:] = [] token = lilypondfiletools.LilyPondVersionToken( "2.19.0", ) lilypond_file.file_initial_system_includes[0] = token if ( image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet ): lilypond_file.use_relative_includes = True lilypond_file.file_initial_user_includes[:] = [image_render_specifier.stylesheet] self._payload = lilypond_file
def process_literal_block_pairs(literal_block_pairs): environment = { '__builtins__': __builtins__, 'print_function': print_function, } exec('from abjad import *\n', environment) try: experimental = importlib.import_module('experimental') environment.update(experimental.__dict__) except ImportError: pass string_io = StringIO() with systemtools.RedirectedStreams(stdout=string_io): for literal_block, all_lines in literal_block_pairs: original_lines = literal_block[0].splitlines() replacement_blocks = [] lines_to_execute = [] previous_line_number = 0 for i, line in all_lines: lines_to_execute.append(line) if line.startswith('__abjad_book__ ='): if '__abjad_book__' in environment: del(environment['__abjad_book__']) try: exec('\n'.join(lines_to_execute), environment) except Exception as e: traceback.print_exc() kind, obj = environment['__abjad_book__'] new_abjad_book_block = abjad_book_block() new_abjad_book_block['kind'] = kind if kind == 'lilypond': lilypond_file = documentationtools.make_reference_manual_lilypond_file(obj) new_abjad_book_block['code'] = format(lilypond_file) new_abjad_book_block['raw_code'] = format(obj) elif kind == 'graphviz': graphviz_graph = documentationtools.make_reference_manual_graphviz_graph(obj) new_abjad_book_block['code'] = graphviz_graph.graphviz_format text = '\n'.join(original_lines[previous_line_number:i + 1]) new_literal_block = literal_block.deepcopy() new_literal_block.rawsource = text new_literal_block[0].rawsource = text new_literal_block[0].text = text replacement_blocks.extend([new_literal_block, new_abjad_book_block]) lines_to_execute = [] previous_line_number = i + 1 if lines_to_execute: try: exec('\n'.join(lines_to_execute), environment) except: pass if replacement_blocks: text = '\n'.join(original_lines[previous_line_number:]) new_literal_block = literal_block.deepcopy() new_literal_block.rawsource = text new_literal_block[0].rawsource = text new_literal_block[0].text = text replacement_blocks.append(new_literal_block) if replacement_blocks: literal_block.replace_self(replacement_blocks)
def process_literal_block_pairs(literal_block_pairs): environment = {'__builtins__': __builtins__} exec('from abjad import *\n', environment) for literal_block, all_lines in literal_block_pairs: original_lines = literal_block[0].splitlines() replacement_blocks = [] lines_to_execute = [] previous_line_number = 0 for i, line in all_lines: lines_to_execute.append(line) if line.startswith('__abjad_book__ ='): if '__abjad_book__' in environment: del(environment['__abjad_book__']) try: exec('\n'.join(lines_to_execute), environment) except Exception as e: traceback.print_exc() kind, obj = environment['__abjad_book__'] new_abjad_book_block = abjad_book_block() new_abjad_book_block['kind'] = kind if kind == 'lilypond': lilypond_file = documentationtools.make_reference_manual_lilypond_file(obj) new_abjad_book_block['code'] = format(lilypond_file) new_abjad_book_block['raw_code'] = format(obj) elif kind == 'graphviz': graphviz_graph = documentationtools.make_reference_manual_graphviz_graph(obj) new_abjad_book_block['code'] = graphviz_graph.graphviz_format text = '\n'.join(original_lines[previous_line_number:i + 1]) new_literal_block = literal_block.deepcopy() new_literal_block.rawsource = text new_literal_block[0].rawsource = text new_literal_block[0].text = text replacement_blocks.extend([new_literal_block, new_abjad_book_block]) lines_to_execute = [] previous_line_number = i + 1 if lines_to_execute: try: exec('\n'.join(lines_to_execute), environment) except: pass if replacement_blocks: text = '\n'.join(original_lines[previous_line_number:]) new_literal_block = literal_block.deepcopy() new_literal_block.rawsource = text new_literal_block[0].rawsource = text new_literal_block[0].text = text replacement_blocks.append(new_literal_block) if replacement_blocks: literal_block.replace_self(replacement_blocks)
def __init__(self, payload, pages=None, stylesheet=None): payload = copy.deepcopy(payload) if not stylesheet: payload = documentationtools.make_reference_manual_lilypond_file( payload) manager = systemtools.IOManager lilypond_file = manager._insert_expr_into_lilypond_file(payload) lilypond_file.file_initial_system_comments[:] = [] token = lilypondfiletools.LilyPondVersionToken( "2.19.0", ) lilypond_file.file_initial_system_includes[0] = token self._stylesheet = stylesheet if stylesheet: lilypond_file.use_relative_includes = True lilypond_file.file_initial_user_includes[:] = [stylesheet] self._payload = lilypond_file self._pages = pages or None
def __init__( self, payload, image_layout_specifier=None, image_render_specifier=None, ): from abjad.tools import abjadbooktools ImageOutputProxy.__init__( self, image_layout_specifier=image_layout_specifier, image_render_specifier=image_render_specifier, ) payload = copy.deepcopy(payload) if image_render_specifier is None: image_render_specifier = abjadbooktools.ImageRenderSpecifier() if ( not image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet ): payload = documentationtools.make_reference_manual_lilypond_file( payload) lilypond_file = payload assert isinstance(lilypond_file, lilypondfiletools.LilyPondFile) if lilypond_file.header_block is None: header_block = lilypondfiletools.Block(name='header') lilypond_file.items.insert(0, header_block) lilypond_file.header_block.tagline = False lilypond_file._date_time_token = None token = lilypondfiletools.LilyPondVersionToken( "2.19.0", ) lilypond_file._lilypond_version_token = token if ( image_render_specifier.stylesheet and not image_render_specifier.no_stylesheet ): if not lilypond_file.includes: lilypond_file._use_relative_includes = True includes = [image_render_specifier.stylesheet] lilypond_file._includes = tuple(includes) self._payload = lilypond_file
def write_expr_to_ly( expr, file_name, print_status=False, tagline=False, docs=False, ): r'''Writes `expr` to `file_name`. :: >>> note = Note("c'4") >>> iotools.write_expr_to_ly(note, '/home/user/foo.ly') # doctest: +SKIP Returns none. ''' from abjad.tools import iotools file_name = os.path.expanduser(file_name) if not file_name.endswith('.ly'): file_name += '.ly' try: outfile = open(file_name, 'w') if docs: expr = documentationtools.make_reference_manual_lilypond_file(expr) lilypond_file = iotools.insert_expr_into_lilypond_file( expr, tagline=tagline) # the following line is necessary for Windows *not* to keep # outfile open after writing; # why this should be the case is, however, a complete mystery. output = lilypond_file.lilypond_format outfile.write(output) outfile.close() except IOError: print 'ERROR: cound not open file %s' % file_name dirname = os.path.dirname(file_name) if dirname: print 'Make sure "%s" exists in your system.' % dirname if print_status: print 'LilyPond file written to %r ...' % os.path.basename(file_name)