Changeset 1007
- Timestamp:
- Jul 12, 2012 5:56:32 PM (11 years ago)
- Location:
- specdomain/trunk/src/specdomain
- Files:
-
- 13 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
specdomain/trunk/src/specdomain/CHANGES
r998 r1007 3 3 This file describes user-visible changes between the extension versions. 4 4 5 Version 1.0 (2012-07- 01)5 Version 1.0 (2012-07-13) 6 6 ------------------------ 7 7 8 * Initial version.8 * Initial release. -
specdomain/trunk/src/specdomain/doc/index.rst
r995 r1007 10 10 .. include:: ../README 11 11 12 Contents: 12 Contents 13 ================== 14 15 .. toctree:: 16 :maxdepth: 2 17 18 howto 19 conventions 20 spec 21 example 22 bpm 23 aalength 24 25 Other matters 26 ================== 13 27 14 28 .. toctree:: … … 16 30 17 31 objectives 18 spec 19 20 Other matters: 21 22 .. toctree:: 23 :maxdepth: 2 24 32 todo 33 bugs 25 34 changes 26 35 license -
specdomain/trunk/src/specdomain/doc/spec.rst
r995 r1007 263 263 264 264 265 Common Conventions266 ====================267 268 There are several conventions to help provide consistency.269 These are not requirements.270 271 extended comments272 -----------------273 274 Only the first extended comment in a "section" should be documented.275 (This setting could be changed with an optional switch.)276 277 A "section" might be the global scope of a .mac file or a macro definition block.278 279 As much as possible, use the python documentation style (that is,280 first comment is module documentation, first comment inside281 macro definition is the macro documentation).282 283 hidden objects284 ----------------285 286 *Hidden* objects begin with at least one underline character,287 such as ``_hidden``. This includes macros and variables.288 These should be optional in the documentation.289 290 *Anonymous* objects begin with at least two underline characters,291 such as ``___anon``. This includes macros and variables.292 These should not be documented unless specifically requested and293 only then if hidden objects are documented.294 295 undeclared variables296 ---------------------297 298 Undeclared variables (those with no formal global, local, constant,299 or array declaration) will not be documented. At least for now.300 301 parameter descriptions302 ----------------------------303 304 Use the same syntax as parameter declarations for Python modules.305 Here is an example SPEC macro with reST markup::306 307 def my_comment '{308 '''309 Make a comment310 311 usage: ``my_comment "AR aligned to 15.14063 degrees"``312 313 :param str text: message to be printed314 '''315 qcomment "%s" $1316 }'317 318 which documentation looks like this:319 320 .. spec:def:: my_comment text321 322 Make a comment323 324 usage: ``my_comment "AR aligned to 15.14063 degrees"``325 326 :param str text: message to be printed327 265 328 266 ------------ -
specdomain/trunk/src/specdomain/doc/starter.py
r995 r1007 7 7 (and provides a way to use the source-code debugger for the process) 8 8 ''' 9 10 import os11 import sphinx12 import sys13 9 14 10 import os -
specdomain/trunk/src/specdomain/sphinxcontrib/specdomain.py
r994 r1007 19 19 import os 20 20 import re 21 import string #@UnusedImport 22 import sys #@UnusedImport 23 24 from docutils import nodes #@UnusedImport 25 from docutils.parsers.rst import directives #@UnusedImport 21 22 from docutils import nodes 26 23 27 24 from sphinx import addnodes 28 25 from sphinx.roles import XRefRole 29 from sphinx.locale import l_, _ #@UnusedImport26 from sphinx.locale import l_, _ 30 27 from sphinx.directives import ObjectDescription 31 from sphinx.domains import Domain, ObjType, Index #@UnusedImport 32 from sphinx.util.compat import Directive #@UnusedImport 33 from sphinx.util.nodes import make_refnode, nested_parse_with_titles #@UnusedImport 28 from sphinx.domains import Domain, ObjType 29 from sphinx.util.nodes import make_refnode 34 30 from sphinx.util.docfields import Field, TypedField 35 from sphinx.util.docstrings import prepare_docstring #@UnusedImport 36 37 #from docutils.statemachine import ViewList, string2lines 38 #import sphinx.util.nodes 31 from sphinx.util.docstrings import prepare_docstring 32 39 33 from sphinx.ext.autodoc import Documenter, bool_option 40 #from sphinx.util.inspect import getargspec, isdescriptor, safe_getmembers, \41 # safe_getattr, safe_repr42 #from sphinx.util.pycompat import base_exception, class_types43 34 from specmacrofileparser import SpecMacrofileParser 44 from docutils.statemachine import ViewList #@UnusedImport45 35 46 36 … … 81 71 Items will be documented in the order in 82 72 which they appear in the ``.mac`` file. 73 (Default) 83 74 84 75 **alphabetical** or **alpha** 85 76 Items will be documented in alphabetical order. 77 (Not implemented at present.) 86 78 87 79 .. tip:: … … 174 166 175 167 class SpecDirDocumenter(Documenter): 168 """ 169 Document a directory containing SPEC macro source code files. 170 171 This code responds to the ReST file directive:: 172 173 .. autospecdir:: partial/path/name 174 """ 176 175 objtype = 'specdir' 177 176 member_order = 50 … … 189 188 def generate(self, *args, **kw): 190 189 """ 191 Look at the named directory and 192 Generate reST for the object given by *self.name*, and possibly for 193 its members. 190 Look at the named directory and generate reST for the 191 object given by *self.name*, and possibly for its members. 194 192 """ 195 193 # now, parse the .mac files in the SPEC directory -
specdomain/trunk/src/specdomain/sphinxcontrib/specmacrofileparser.py
r1004 r1007 21 21 import os 22 22 import re 23 from pprint import pprint 23 from pprint import pprint #@UnusedImport 24 24 25 25 # http://www.txt2re.com/index-python.php3 … … 173 173 Figure out what can be documented in the file's contents (in self.buf) 174 174 175 each of the list_ ...() methods returns a175 each of the list_something() methods returns a 176 176 list of dictionaries where each dictionary 177 177 has the keys: objtype, start_line, end_line, and others … … 192 192 193 193 # then, the analysis of what was found 194 # proceed line-by-line in order 195 # TODO: could override this rule with an option 194 196 self.findings = [] 195 197 description = '' … … 217 219 # TODO: could override this rule with an option 218 220 self.findings.append(item) 221 item['summary'] = self._extract_summary(item.get('description', '')) 219 222 220 223 if item['objtype'] == 'extended comment': … … 233 236 if len(description)>0: 234 237 item['description'] = description 238 item['summary'] = self._extract_summary(description) 235 239 clear_description = True 236 240 if not item['name'].startswith('_'): … … 240 244 if clear_description: 241 245 description, clear_description = '', False 246 247 def _extract_summary(self, description): 248 """ 249 return the short summary line from the item description text 250 251 The summary line is the first line in the docstring, 252 such as the line above. 253 254 For our purposes now, we return the first paragraph, 255 if it is not a parameter block such as ``:param var: ...``. 256 """ 257 if len(description) == 0: 258 return '' 259 text = [] 260 for line in description.strip().splitlines(): 261 if len(line.strip()) == 0: 262 break 263 if not line.strip().startswith(':'): 264 text.append(line) 265 return ' '.join(text) 242 266 243 267 def list_extended_comments(self): … … 311 335 if content.find('[') >= 0: 312 336 content = re.sub('\s*?\[', '[', content) # remove blank space before [ 313 for var in variable_name_re.finditer(content): 314 name = var.group(1) 315 if len(name) > 0: 316 items.append({ 317 'start_line': start, 318 'end_line': end, 319 'objtype': objtype, 320 'name': name, 321 'parent': None, 322 }) 337 if objtype in ('constant'): 338 name = content.strip().split()[0] 339 items.append({ 340 'start_line': start, 341 'end_line': end, 342 'objtype': objtype, 343 'name': name, 344 'parent': None, 345 }) 346 else: 347 for var in variable_name_re.finditer(content): 348 name = var.group(1) 349 if len(name) > 0: 350 items.append({ 351 'start_line': start, 352 'end_line': end, 353 'objtype': objtype, 354 'name': name, 355 'parent': None, 356 }) 323 357 return items 324 358 … … 427 461 s.append( '' ) 428 462 s.append(r['text']) 463 s.append( '' ) 429 464 elif r['objtype'] in ('def', 'rdef', 'cdef', ): 430 465 # TODO: apply rules to suppress reporting under certain circumstances … … 437 472 r['end_line']) ) 438 473 s.append( '.. spec:%s:: %s' % ( r['objtype'], r['name'],) ) 474 s.append('') 475 s.append(' '*4 + '*' + r['objtype'] + ' macro declaration*') 439 476 desc = r.get('description', '') 440 477 if len(desc) > 0: … … 442 479 for line in desc.splitlines(): 443 480 s.append(' '*4 + line) 481 s.append( '' ) 444 482 elif r['objtype'] in ('function def', 'function rdef',): 445 483 # TODO: apply rules to suppress reporting under certain circumstances … … 453 491 r['end_line']) ) 454 492 s.append( '.. spec:%s:: %s(%s)' % ( objtype, r['name'], r['args']) ) 493 s.append('') 494 s.append(' '*4 + '*' + r['objtype'].split()[1] + '() macro function declaration*') 455 495 desc = r.get('description', '') 456 496 if len(desc) > 0: … … 458 498 for line in desc.splitlines(): 459 499 s.append(' '*4 + line) 460 elif r['objtype'] in ('local', 'global', 'constant'): 500 s.append( '' ) 501 502 # Why document local variables in a global scope? 503 elif r['objtype'] in ('global', 'constant'): 461 504 # TODO: apply rules to suppress reporting under certain circumstances 462 505 declarations.append(r) 463 s.append( '.. spec:%s:: %s' % ( r['objtype'], r['name']) ) 464 desc = r.get('description', '') 465 if len(desc) > 0: 506 if r.get('parent') is None: 507 s.append( '.. spec:%s:: %s' % ( r['objtype'], r['name']) ) 466 508 s.append('') 467 for line in desc.splitlines(): 468 s.append(' '*4 + line) 509 if r['objtype'] in ('constant'): 510 s.append(' '*4 + '*constant declaration*') 511 else: 512 s.append(' '*4 + '*' + r['objtype'] + ' variable declaration*') 513 desc = r.get('description', '') 514 if len(desc) > 0: 515 s.append('') 516 for line in desc.splitlines(): 517 s.append(' '*4 + line) 518 s.append( '' ) 469 519 470 520 s += _report_table('Variable Declarations (%s)' % self.filename, declarations, 471 ('objtype', 'name', 'start_line', ))521 ('objtype', 'name', 'start_line', 'summary', )) 472 522 s += _report_table('Macro Declarations (%s)' % self.filename, macros, 473 ('objtype', 'name', 'start_line', 'end_line' ))523 ('objtype', 'name', 'start_line', 'end_line', 'summary', )) 474 524 s += _report_table('Function Macro Declarations (%s)' % self.filename, functions, 475 ('objtype', 'name', 'start_line', 'end_line', 'args' ))476 #s += _report_table('Findings from .mac File', self.findings, ('start_line', 'objtype', 'line', ))525 ('objtype', 'name', 'start_line', 'end_line', 'args', 'summary', )) 526 #s += _report_table('Findings from .mac File', self.findings, ('start_line', 'objtype', 'line', 'summary', )) 477 527 478 528 return '\n'.join(s) … … 494 544 for d in itemlist: 495 545 if d['start_line'] != last_line: 496 rows.append( tuple([str(d[key]).strip() for key in col_keys]) ) 546 rowdata = [str(d.get(key,'')).strip() for key in col_keys] 547 rows.append( tuple(rowdata) ) 497 548 last_line = d['start_line'] 498 549 return make_rest_table(title, col_keys, rows, '=') … … 508 559 :param str titlechar: character to use when underlining title as reST section heading 509 560 :returns [str]: each list item is reST 510 511 Example::512 513 title = 'This is a reST table'514 labels = ('name', 'phone', 'email')515 rows = [516 ['Snoopy', '12345', 'dog@house'],517 ['Red Baron', '65432', 'fokker@triplane'],518 ['Charlie Brown', '12345', 'main@house'],519 ]520 print '\n'.join(make_rest_table(title, labels, rows))521 522 This results in this reST::523 524 This is a reST table525 ====================526 527 ============= ===== ===============528 name phone email529 ============= ===== ===============530 Snoopy 12345 dog@house531 Red Baron 65432 fokker@triplane532 Charlie Brown 12345 main@house533 ============= ===== ===============534 561 """ 562 # this is commented out since it causes a warning when building: 563 # specmacrofileparser.py:docstring of sphinxcontrib.specmacrofileparser.make_rest_table:14: WARNING: Block quote ends without a blank line; unexpected unindent. 564 # ----- 565 # """ 566 # build a reST table 567 # 568 # :param str title: placed in a section heading above the table 569 # :param [str] labels: columns labels 570 # :param [[str]] rows: 2-D grid of data, len(labels) == len(data[i]) for all i 571 # :param str titlechar: character to use when underlining title as reST section heading 572 # :returns [str]: each list item is reST 573 # 574 # Example:: 575 # 576 # title = 'This is a reST table' 577 # labels = ('name', 'phone', 'email') 578 # rows = [ 579 # ['Snoopy', '12345', 'dog@house'], 580 # ['Red Baron', '65432', 'fokker@triplane'], 581 # ['Charlie Brown', '12345', 'main@house'], 582 # ] 583 # print '\n'.join(make_rest_table(title, labels, rows, titlechar='~')) 584 # 585 # This results in this reST:: 586 # 587 # This is a reST table 588 # ~~~~~~~~~~~~~~~~~~~~ 589 # 590 # ============= ===== =============== 591 # name phone email 592 # ============= ===== =============== 593 # Snoopy 12345 dog@house 594 # Red Baron 65432 fokker@triplane 595 # Charlie Brown 12345 main@house 596 # ============= ===== =============== 597 # 598 # """ 535 599 s = [] 536 600 if len(rows) == 0: -
specdomain/trunk/src/specdomain/test/test_autospecdir.rst
r994 r1007 2 2 3 3 .. autospecdir:: ../macros/ 4 5 .. end
Note: See TracChangeset
for help on using the changeset viewer.