Changeset 994


Ignore:
Timestamp:
Jul 6, 2012 2:15:32 PM (11 years ago)
Author:
jemian
Message:

refs #8, add autospecdir, no options supported yet

Location:
specdomain/trunk/src/specdomain
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • specdomain/trunk/src/specdomain/sphinxcontrib/specdomain.py

    r989 r994  
    130130        #self.add_directive_header(sig)
    131131       
    132         # TODO: provide links from each to highlighted source code blocks (like Python documenters).
    133         # This works for now.
    134132        self.add_line(u'', '<autodoc>')
    135133        self.add_line(u'.. index:: SPEC macro file; %s' % macrofile, '<autodoc>')
    136134        self.add_line(u'.. index:: !%s' % os.path.split(macrofile)[1], '<autodoc>')
    137135        self.add_line(u'', '<autodoc>')
     136        self.add_line(u'', '<autodoc>')
     137        title = 'SPEC Macro File: %s' %  macrofile
     138        self.add_line('@'*len(title), '<autodoc>')
     139        self.add_line(title, '<autodoc>')
     140        self.add_line('@'*len(title), '<autodoc>')
     141        self.add_line(u'', '<autodoc>')
     142        # TODO: provide links from each to highlighted source code blocks (like Python documenters).
     143        # This works for now.
    138144        line = 'source code:  :download:`%s <%s>`' % (macrofile, macrofile)
    139145        self.add_line(line, macrofile)
     
    165171                                'given for autospecmacro %s' % self.fullname)
    166172        return ret
     173
     174
     175class SpecDirDocumenter(Documenter):
     176    objtype = 'specdir'
     177    member_order = 50
     178    priority = 0
     179    #: true if the generated content may contain titles
     180    titles_allowed = True
     181    option_spec = {
     182        'include_subdirs': bool_option,
     183    }
     184
     185    @classmethod
     186    def can_document_member(cls, member, membername, isattr, parent):
     187        return membername in ('SpecDirDocumenter', )
     188   
     189    def generate(self, *args, **kw):
     190        """
     191        Look at the named directory and
     192        Generate reST for the object given by *self.name*, and possibly for
     193        its members.
     194        """
     195        # now, parse the .mac files in the SPEC directory
     196        specdir = self.name
     197#        self.add_line(u'', '<autodoc>')
     198#        self.add_line(u'directory:\n   ``%s``' % specdir, '<autodoc>')
     199        if os.path.exists(specdir):
     200            for f in sorted(os.listdir(specdir)):
     201                filename = os.path.join(specdir, f)
     202                if os.path.isfile(filename) and filename.endswith('.mac'):
     203                    # TODO: support a user choice for pattern match to the file name (glob v. re)
     204                    # TODO: support the option to include subdirectories (include_subdirs)
     205                    # TODO: do not add the same SPEC macro file more than once
     206                    self.add_line(u'', '<autodoc>')
     207                    self.add_line(u'.. autospecmacro:: %s' % filename, '<autodoc>')
     208                    # TODO: any options?
     209                    self.add_line(u'', '<autodoc>')
     210                    # TODO: suppress delimiter after last file
     211                    self.add_line(u'-'*15, '<autodoc>')         # delimiter between files
     212        else:
     213            self.add_line(u'', '<autodoc>')
     214            self.add_line(u'Could not find directory: ``%s``' % specdir, '<autodoc>')
     215
    167216
    168217
     
    355404    app.add_domain(SpecDomain)
    356405    app.add_autodocumenter(SpecMacroDocumenter)
     406    app.add_autodocumenter(SpecDirDocumenter)
    357407    app.add_config_value('autospecmacrodir_process_subdirs', True, True)
  • specdomain/trunk/src/specdomain/sphinxcontrib/specmacrofileparser.py

    r993 r994  
    381381        macros = []             # def, cdef, and rdef macros
    382382        functions = []          # def and rdef function macros
    383         #title = 'Extended Comments'
    384         #s = ['', title, '='*len(title), ]
    385383        s = []
    386384        for r in self.findings:
    387385            if r['objtype'] == 'extended comment':
     386                # TODO: apply rules to suppress reporting under certain circumstances
    388387                s.append( '' )
    389388                s.append( '.. %s %s %d %d' % (self.filename,
     
    394393                s.append(r['text'])
    395394            elif r['objtype'] in ('def', 'rdef', 'cdef', ):
     395                # TODO: apply rules to suppress reporting under certain circumstances
    396396                macros.append(r)
    397397                s.append( '' )
     
    402402                                              r['end_line']) )
    403403                s.append( '' )
     404                # TODO: make this next be part of the signature display (in specdomain)
    404405                s.append( '.. rubric:: %s macro declaration' % r['objtype']  )
    405406                s.append( '' )
    406                 #s.append( '.. spec:%s:: %s %s' % ( r['objtype'], r['name'], r['args'],) )
    407407                s.append( '.. spec:%s:: %s' % ( r['objtype'], r['name'],) )
    408408            elif r['objtype'] in ('function def', 'function rdef',):
    409                 # FIXME:  not getting here, such as for kohzuE_cmd()
     409                # TODO: apply rules to suppress reporting under certain circumstances
    410410                functions.append(r)
    411411                s.append( '' )
     
    420420                s.append( '.. spec:%s:: %s(%s)' % ( r['objtype'], r['name'], r['args']) )
    421421            elif r['objtype'] in ('local', 'global', 'constant'):
     422                # TODO: apply rules to suppress reporting under certain circumstances
    422423                del r['text']
    423424                declarations.append(r)
    424425
    425         s += report_table('Variable Declarations', declarations, ('start_line', 'objtype', 'name', 'line',))
    426         s += report_table('Macro Declarations', macros, ('start_line', 'name', 'line',))
    427         s += report_table('Function Macro Declarations', functions)
     426        s += report_table('Variable Declarations (%s)' % self.filename, declarations, ('start_line', 'objtype', 'name', 'line',))
     427        s += report_table('Macro Declarations (%s)' % self.filename, macros, ('start_line', 'name', 'line',))
     428        s += report_table('Function Macro Declarations (%s)' % self.filename, functions)
    428429        #s += report_table('Findings from .mac File', self.findings, ('start_line', 'objtype', 'line',))
    429430
  • specdomain/trunk/src/specdomain/test/ccdscan_4.0.mac.rst

    r983 r994  
    11.. $Id$
    22
    3 =============================================================
    4 SPEC macro source file: ``../macros/ccdscan_4.0.mac``
    5 =============================================================
    6 
    73.. autospecmacro:: ../macros/ccdscan_4.0.mac
  • specdomain/trunk/src/specdomain/test/cdef-examples.mac.rst

    r983 r994  
    11.. $Id$
    22
    3 =============================================================
    4 SPEC macro source file: ``../macros/cdef-examples.mac``
    5 =============================================================
    6 
    73.. autospecmacro:: ../macros/cdef-examples.mac
  • specdomain/trunk/src/specdomain/test/shutter.mac.rst

    r983 r994  
    11.. $Id$
    2 
    3 ====================================================
    4 SPEC macro source file: ``../macros/shutter.mac``
    5 ====================================================
    62
    73.. caution:: This file is as-received. 
  • specdomain/trunk/src/specdomain/test/test-battery.mac.rst

    r983 r994  
    11.. $Id$
    22
    3 ========================================================
    4 SPEC macro source file: ``../macros/test-battery.mac``
    5 ========================================================
    6 
    73.. autospecmacro:: ../macros/test-battery.mac
  • specdomain/trunk/src/specdomain/test/test_doc.rst

    r989 r994  
    9696constant declaration: 
    9797
    98         .. spec:local:: TWO_PI
     98        .. spec:constant:: TWO_PI
    9999       
    100100           ``TWO_PI`` is the ratio of a circle's circumference to its diameter.
     
    150150
    151151   *.mac
     152   test_autospecdir
  • specdomain/trunk/src/specdomain/test/usaxs_load.mac.rst

    r985 r994  
    11.. $Id$
    22
    3 =============================================================
    4 SPEC macro source file: ``../macros/usaxs_load.mac``
    5 =============================================================
    6 
    73.. autospecmacro:: ../macros/usaxs_load.mac
  • specdomain/trunk/src/specdomain/test/usaxs_uascan.mac.rst

    r985 r994  
    11.. $Id$
    22
    3 =============================================================
    4 SPEC macro source file: ``../macros/usaxs_uascan.mac``
    5 =============================================================
    6 
    73.. autospecmacro:: ../macros/usaxs_uascan.mac
Note: See TracChangeset for help on using the changeset viewer.