def __format__(self, format_specification=''): r'''Formats scheme. Set `format_specification` to `''`', `'lilypond'` or ``'storage'``. Interprets `''` equal to `'lilypond'`. .. container:: example Scheme LilyPond format: >>> scheme = abjad.Scheme('foo') >>> format(scheme) '#foo' .. container:: example Scheme storage format: >>> abjad.f(scheme) abjad.Scheme( 'foo' ) Returns string. ''' from abjad.tools import systemtools if format_specification in ('', 'lilypond'): return self._get_lilypond_format() elif format_specification == 'storage': return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def __format__(self, format_specification=''): r'''Formats stem tremolo. .. container:: example With two beams: >>> tremolo = abjad.Tremolo(beam_count=2) >>> print(format(tremolo)) abjad.Tremolo( beam_count=2, ) .. container:: example With three beams: >>> tremolo = abjad.Tremolo(beam_count=3) >>> print(format(tremolo)) abjad.Tremolo( beam_count=3, ) Returns string. ''' from abjad.tools import systemtools if format_specification in ('', 'storage'): return systemtools.StorageFormatManager(self).get_storage_format() elif format_specification == 'lilypond': message = 'no LilyPond format available.' raise Exception(message) else: message = "format_specification must be 'storage' or ''." raise Exception(message)
def __format__(self, format_specification='') -> str: r'''Formats note-head. ''' from abjad.tools import systemtools if format_specification in ('', 'lilypond'): return self._get_lilypond_format() elif format_specification == 'storage': return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def _get_format_specification(self): from abjad.tools import systemtools agent = systemtools.StorageFormatManager(self) names = agent.signature_names return systemtools.FormatSpecification( client=self, repr_is_indented=True, template_names=names, )
def _keyword_argument_names(self): from abjad.tools import systemtools agent = systemtools.StorageFormatManager(self) keyword_argument_names = list(agent.signature_keyword_names) if 'client' in keyword_argument_names: keyword_argument_names.remove('client') if 'tweak_pairs' in keyword_argument_names: keyword_argument_names.remove('tweak_pairs') keyword_argument_names = tuple(keyword_argument_names) return keyword_argument_names
def __repr__(self): r'''Gets interpreter representation of nonreduced fraction. .. container:: example >>> abjad.NonreducedFraction(3, 6) NonreducedFraction(3, 6) Returns string. ''' return systemtools.StorageFormatManager(self).get_repr_format()
def __format__(self, format_specification=''): r'''Formats woodwind fingering. Set `format_specification` to `''` or `'storage'`. Returns string. ''' from abjad.tools import systemtools if format_specification in ('', 'storage'): return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def _get_format_specification(self): agent = systemtools.StorageFormatManager(self) names = agent.signature_keyword_names for name in ('attachments',): if not getattr(self, name, None) and name in names: names.remove(name) return systemtools.FormatSpecification( client=self, repr_is_indented=False, storage_format_kwargs_names=names, )
def __format__(self, format_specification=''): r'''Formats q-event. Set `format_specification` to `''` or `'storage'`. Interprets `''` equal to `'storage'`. Returns string. ''' from abjad.tools import systemtools if format_specification in ('', 'storage'): return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def _get_format_specification(self): from abjad.tools import systemtools agent = systemtools.StorageFormatManager(self) names = list(agent.signature_keyword_names) if 'items' in names: names.remove('items') return systemtools.FormatSpecification( self, repr_is_indented=False, storage_format_args_values=[self._collection], storage_format_kwargs_names=names, )
def _get_format_specification(self): agent = systemtools.StorageFormatManager(self) names = agent.signature_names template_names = names[:] if 'q_event_proxies' in names and not self.q_event_proxies: names.remove('q_event_proxies') return systemtools.FormatSpecification( client=self, repr_is_indented=True, storage_format_kwargs_names=names, template_names=template_names, )
def __copy__(self): r'''Copies tree node. ''' from abjad.tools import systemtools agent = systemtools.StorageFormatManager(self) arguments = [] for value in agent.get_template_dict().values(): if isinstance(value, tuple): value = tuple(copy.copy(_) for _ in value) else: value = copy.copy(value) arguments.append(value) return type(self)(*arguments)
def __hash__(self): r'''Hashes Abjad value object. Returns integer. ''' from abjad.tools import systemtools hash_values = systemtools.StorageFormatManager(self).get_hash_values() try: result = hash(hash_values) except TypeError: message = 'unhashable type: {}'.format(self) raise TypeError(message) return result
def _get_format_specification(self): from abjad.tools import systemtools agent = systemtools.StorageFormatManager(self) names = list(agent.signature_keyword_names) template_names = names[:] for name in ('children',): if not getattr(self, name, None) and name in names: names.remove(name) return systemtools.FormatSpecification( client=self, repr_is_indented=True, storage_format_kwargs_names=names, template_names=template_names, )
def __format__(self, format_specification=''): r'''Formats q-event sequence. Set `format_specification` to `''` or `'storage'`. Interprets `''` equal to `'storage'`. >>> durations = (1000, -500, 1250, -500, 750) >>> sequence = \ ... abjad.quantizationtools.QEventSequence.from_millisecond_durations( ... durations) >>> print(format(sequence)) abjad.quantizationtools.QEventSequence( ( abjad.quantizationtools.PitchedQEvent( offset=abjad.Offset(0, 1), pitches=( abjad.NamedPitch("c'"), ), ), abjad.quantizationtools.SilentQEvent( offset=abjad.Offset(1000, 1), ), abjad.quantizationtools.PitchedQEvent( offset=abjad.Offset(1500, 1), pitches=( abjad.NamedPitch("c'"), ), ), abjad.quantizationtools.SilentQEvent( offset=abjad.Offset(2750, 1), ), abjad.quantizationtools.PitchedQEvent( offset=abjad.Offset(3250, 1), pitches=( abjad.NamedPitch("c'"), ), ), abjad.quantizationtools.TerminalQEvent( offset=abjad.Offset(4000, 1), ), ) ) Returns string. ''' from abjad.tools import systemtools if format_specification in ('', 'storage'): return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def _get_format_specification(self): agent = systemtools.StorageFormatManager(self) names = list(agent.signature_keyword_names) names.extend(sorted(self._collection.keys())) if 'items' in names: names.remove('items') if not self.autoincrement: names.remove('autoincrement') return systemtools.FormatSpecification( self, repr_is_indented=False, storage_format_args_values=[], storage_format_kwargs_names=names, template_names=names, )
def _get_format_specification(self): arguments = [repr(str(self))] arguments.extend(self.tweak._get_attribute_pairs()) arguments = ', '.join([str(x) for x in arguments]) repr_text = '{}({})'.format(type(self).__name__, arguments) agent = systemtools.StorageFormatManager(self) names = list(agent.signature_keyword_names) if 'client' in names: names.remove('client') if 'tweak_pairs' in names: names.remove('tweak_pairs') return systemtools.FormatSpecification( self, repr_text=repr_text, storage_format_kwargs_names=names, )
def _get_format_specification(self): from abjad.tools import systemtools agent = systemtools.StorageFormatManager(self) names = list(agent.signature_keyword_names) for name in names[:]: if name == 'talea_denominator': continue if not getattr(self, name): names.remove(name) # TODO: keywords defaults checking if self.fill_with_notes: names.remove('fill_with_notes') return systemtools.FormatSpecification( client=self, storage_format_kwargs_names=names, )
def __format__(self, format_specification=''): r'''Formats LilyPond language token. .. container:: example >>> token = abjad.LilyPondLanguageToken() >>> print(format(token)) \language "english" Returns string. ''' from abjad.tools import systemtools if format_specification in ('', 'lilypond'): return self._get_lilypond_format() elif format_specification == 'storage': return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def __format__(self, format_specification=''): r'''Formats nonreduced fraction. Set `format_specification` to `''` or `'storage'`. Interprets `''` equal to `'storage'`. .. container:: example >>> fraction = abjad.NonreducedFraction(-6, 3) >>> print(format(fraction)) abjad.NonreducedFraction(-6, 3) Returns string. ''' if format_specification in ('', 'storage'): return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def __format__(self, format_specification=''): r'''Formats LilyPond version token. .. container:: example >>> token = abjad.LilyPondVersionToken() >>> print(format(token)) # doctest: +SKIP \version "2.19.0" Return string. ''' from abjad.tools import systemtools if format_specification in ('', 'lilypond'): return self._get_lilypond_format() elif format_specification == 'storage': return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def as_module(self, module_file_path, object_name): r'''Persists client as Python module. .. container:: example >>> timespans = abjad.TimespanList([ ... abjad.Timespan(0, 1), ... abjad.Timespan(2, 4), ... abjad.Timespan(6, 8), ... ]) >>> abjad.persist(timespans).as_module( # doctest: +SKIP ... '~/example.py', ... 'timespans', ... ) Returns none. ''' from abjad.tools import systemtools agent = systemtools.StorageFormatManager(self._client) result = [] import_statements = agent.get_import_statements() result.extend(import_statements) result.extend(('', '')) if ( '_get_storage_format_specification' in dir(self._client) or '_get_format_specification' in dir(self._client) ): storage_pieces = format(self._client, 'storage') else: try: storage_pieces = agent._dispatch_formatting(self._client) storage_pieces = ''.join(storage_pieces) except ValueError: storage_pieces = repr(self._client) storage_pieces = storage_pieces.splitlines() line = '{} = {}'.format(object_name, storage_pieces[0]) result.append(line) result.extend(storage_pieces[1:]) result = '\n'.join(result) module_file_path = os.path.expanduser(module_file_path) directory = os.path.dirname(module_file_path) systemtools.IOManager._ensure_directory_existence(directory) with open(module_file_path, 'w') as f: f.write(result)
def __format__(self, format_specification=''): r'''Formats date / time token. .. container:: example :: >>> token = abjad.DateTimeToken() >>> print(format(token)) # doctest: +SKIP 2014-01-04 14:42 Returns string. ''' from abjad.tools import systemtools if format_specification in ('', 'lilypond'): return self._get_lilypond_format() elif format_specification == 'storage': return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def __format__(self, format_specification=''): r'''Formats package git commit token. .. container:: example >>> token = abjad.PackageGitCommitToken('abjad') >>> print(format(token)) # doctest: +SKIP package "abjad" @ b6a48a7 [implement-lpf-git-token] (2016-02-02 13:36:25) Return string. ''' from abjad.tools import systemtools if not self.package_name: return '' if format_specification in ('', 'lilypond'): return self._get_lilypond_format() elif format_specification == 'storage': return systemtools.StorageFormatManager(self).get_storage_format() return str(self)
def _copy_with_memo(node): from abjad.tools import systemtools agent = systemtools.StorageFormatManager(node) edges = set(getattr(node, '_edges', ())) mapping = dict() arguments = agent.get_template_dict() if 'children' not in arguments: copied_node = new(node) mapping[node] = copied_node else: copied_node = new(node, children=None) mapping[node] = copied_node for child in arguments['children']: ( copied_child, child_edges, child_mapping, ) = GraphvizMixin._copy_with_memo(child) copied_node.append(copied_child) edges.update(child_edges) mapping.update(child_mapping) return copied_node, edges, mapping