[pygccxml-commit] SF.net SVN: pygccxml: [418] pydsc_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-08-17 05:07:24
|
Revision: 418 Author: roman_yakovenko Date: 2006-08-16 22:07:08 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=418&view=rev Log Message: ----------- Updating pydsc, docs and new test cases has been added Modified Paths: -------------- pydsc_dev/docs/pydsc.rest pydsc_dev/pydsc.py pydsc_dev/setup.py pydsc_dev/unittests/tester.py pydsc_dev/unittests/to_be_tested.py Added Paths: ----------- pydsc_dev/unittests/do_not_check/ pydsc_dev/unittests/do_not_check/__init__.py Modified: pydsc_dev/docs/pydsc.rest =================================================================== --- pydsc_dev/docs/pydsc.rest 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/docs/pydsc.rest 2006-08-17 05:07:08 UTC (rev 418) @@ -7,21 +7,21 @@ .. meta:: :description: Python documentation string spell checker :keywords: Python, docstring, documentation, spell, check - , документация, спеллер, орфографическая коррекция, - + , документация, спеллер, орфографическая коррекция, + -------------- What is pydsc? -------------- -.. include:: ./definition.rest +.. include:: ./definition.rest ---------------------- What it is useful for? ---------------------- Well, this project was born to solve real problem - I made a lot of mistakes, -when I write source code documentation for my projects. I needed some way to -check all the documentation strings. My goal was simplicity + easy customization. +when I write source code documentation for my projects. I needed some way to +check all the documentation strings. My goal was simplicity + easy customization. I achieved it. Here is example of usage of pydsc: | ``import pydsc`` @@ -33,8 +33,8 @@ Spell checking -------------- -I did not reinvent the wheel. I use external spell checking engine. I checked -around and found few spell check engines available from Python. I decided to use +I did not reinvent the wheel. I use external spell checking engine. I checked +around and found few spell check engines available from Python. I decided to use `PyEnchant`_. It is cross platform, has clean interface and responsive author. ------------- @@ -47,12 +47,12 @@ * exclude(include) files from(to) spell checking process by file location ( very useful option in multi-project environment ) -More complex example: +"More complex" example: | ``import pydsc`` -| ``pydsc.doc_checker.filter.append( "/home/roman/pygccxml" )`` -| ``pydsc.doc_checker.filter_type = pydsc.FILTER_TYPE.INCLUDE`` -| ``map( pydsc.doc_checker.speller.ignore_always, [ 'normcase', 'normpath' ] )`` +| #check for spell errors only in files under "/home/roman/pygccxml" directory +| ``pydsc.include( "/home/roman/pygccxml" )`` +| ``pydsc.ignore( [ 'normcase', 'normpath' ] )`` | ``import readline`` -------- Modified: pydsc_dev/pydsc.py =================================================================== --- pydsc_dev/pydsc.py 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/pydsc.py 2006-08-17 05:07:08 UTC (rev 418) @@ -62,10 +62,10 @@ """ -__version__ = '0.1' -__author__ = 'Roman Yakovenko <rom...@gm...>' -__url__ = 'http://sourceforge.net/projects/pygccxml/' -__license__ = 'Boost Software License <http://boost.org/more/license_info.html>' +__version__ = '0.2' #current version +__author__ = 'Roman Yakovenko <rom...@gm...>' #Don't you want to know who is guilty? +__url__ = 'http://www.language-binding.net' #project home +__license__ = 'Boost Software License <http://boost.org/more/license_info.html>' #license import os import sys @@ -84,12 +84,18 @@ return os.path.normcase( os.path.normpath( some_path ) ) class filter_by_path_t: + """The instance of this class will help user to define filter, that will + exclude modules from being checked""" class FILTER_TYPE: """defines few filter constants""" INCLUDE = 'include' EXCLUDE = 'exclude' def __init__( self, what, ftype ): + """ + what - list of paths, could contain file and directory names + ftype - FILTER_TYPE constant + """ self.what = what if None is self.what: self.what = [] @@ -116,19 +122,13 @@ return bool( filter( lambda dir: path.startswith( dir ), dirs ) ) def check( self, source_file ): + """returns True if source_file should be checked, False otherwise""" source_file = normalize_path( source_file ) if source_file in self.what or self.contains_parent_dir( source_file, self.what ): return self.ftype == self.FILTER_TYPE.INCLUDE else: return self.ftype == self.FILTER_TYPE.EXCLUDE -def exclude( what ): - return filter_by_path_t( what, filter_t.FILTER_TYPE.EXCLUDE ) - -def include( what ): - return filter_by_path_t( what, filter_t.FILTER_TYPE.INCLUDE ) - - class checker_t( object ): """ applies spell check process on every imported module @@ -181,10 +181,12 @@ if self.writer is None: self.writer = sys.stdout self.filter = filter - self.identifiers = set() + self.ignored_words = set() self.ignore_identifiers = ignore_identifiers def should_be_checked( self, obj, module=None ): + """returns True, if obj should be checked, False otherwise""" + if id(obj) in self.__checked: return False if inspect.isbuiltin( obj ): @@ -215,24 +217,22 @@ return False def import_( self, name, globals=None, locals=None, fromlist=None ): + """Hook to import functionality""" pymodule = self.__orig_import( name, globals, locals, fromlist ) if self.should_be_checked(pymodule): - #write = self.writer.write - #write( 'inspecting %s%s' % ( inspect.getsourcefile( pymodule ), os.linesep ) ) self.__already_imported.add( name ) - self.check( pymodule ) - #write( 'inspecting %s done%s' % ( inspect.getsourcefile( pymodule ), os.linesep ) ) + self.__check( pymodule ) return pymodule def __check_text_impl( self, obj, text, text_type ): if not text: return if self.ignore_identifiers and hasattr( obj, '__name__' ) and obj.__name__: - self.identifiers.add( obj.__name__ ) + self.ignored_words.add( obj.__name__ ) errors = {} self.speller.set_text( text ) for error in self.speller: - if error.word in self.identifiers: + if error.word in self.ignored_words: continue if not errors.has_key( error.word ): errors[ error.word ] = [] @@ -252,21 +252,50 @@ write( ' misspelled word: %s%s' % ( word, os.linesep ) ) write( ' suggestions : %s%s' % ( `suggestions`, os.linesep ) ) - def check_text( self, obj): + def __check_text( self, obj): self.__check_text_impl( obj, inspect.getdoc( obj ), 'documentation string' ) if inspect.getsourcefile( obj ): self.__check_text_impl( obj, inspect.getcomments( obj ), 'comment' ) - def check( self, module ): - self.check_text( module ) + def __check( self, module ): + self.__check_text( module ) to_be_checked = map( lambda x: x[1], inspect.getmembers( module ) ) while to_be_checked: member = to_be_checked.pop(0) if not self.should_be_checked( member, module ): continue - self.check_text( member ) + self.__check_text( member ) to_be_checked.extend( map( lambda x: x[1], inspect.getmembers( member ) ) ) self.__checked.add( id(member) ) """documentation spell checker instance""" doc_checker = checker_t( checker.SpellChecker( "en_US" ) ) + +def exclude( what ): + """ + Convenience function. It will exclude all modules, that their source file or + parent directory belongs to "what". + + what - list of paths, could contain file and directory names + """ + doc_checker.filter = filter_by_path_t( what, filter_by_path_t.FILTER_TYPE.EXCLUDE ) + +def include( what ): + """ + Convenience function. It will include only modules, that their source file + or parent directory belongs to "what". + + what - list of paths, could contain file and directory names + """ + doc_checker.filter = filter_by_path_t( what, filter_by_path_t.FILTER_TYPE.INCLUDE ) + +def ignore( what ): + """Adds word or list of words to the ignore list. + + what - word(string) or list of words(strings) to be ignored. + """ + if isinstance( what, str ): + doc_checker.ignored_words.add( what ) + else: + map( doc_checker.ignored_words.add, what ) + Modified: pydsc_dev/setup.py =================================================================== --- pydsc_dev/setup.py 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/setup.py 2006-08-17 05:07:08 UTC (rev 418) @@ -4,13 +4,59 @@ # http://www.boost.org/LICENSE_1_0.txt) import os -from distutils import sysconfig +import sys + from distutils.core import setup +from distutils.cmd import Command +def generate_doc(): + """Generate the epydoc reference manual. + """ + print "Generating epydoc files..." + + from epydoc.docbuilder import build_doc_index + from epydoc.docwriter.html import HTMLWriter + + docindex = build_doc_index(['pydsc']) + html_writer = HTMLWriter( docindex + , prj_name='pydsc' + , prj_url='http://www.language-binding.net' + , include_sourcecode=False #This will decrease the size of generated documentation + , show_private=False + , show_frames=False) + + html_writer.write( os.path.join('docs', 'apidocs') ) + +class doc_cmd(Command): + """This is a new distutils command 'doc' to build the epydoc manual. + """ + + description = 'build the API reference using epydoc' + user_options = [('no-doc', None, "don't run epydoc")] + boolean_options = ['no-doc'] + + def initialize_options (self): + self.no_doc = 0 + + def finalize_options (self): + pass + + def run(self): + if self.no_doc: + return + generate_doc() + + +# Generate the doc when a source distribution is created +if sys.argv[-1]=="sdist": + generate_doc() + setup( name="pydsc" + , version = "0.2" , description="Python documentation and comments spell checker" , author="Roman Yakovenko" , author_email="rom...@gm..." - , url='http://pygccxml.sourceforge.net' + , url='http://www.language-binding.net' , py_modules=[ 'pydsc' ] -) \ No newline at end of file + , cmdclass = {"doc" : doc_cmd} +) Added: pydsc_dev/unittests/do_not_check/__init__.py =================================================================== --- pydsc_dev/unittests/do_not_check/__init__.py (rev 0) +++ pydsc_dev/unittests/do_not_check/__init__.py 2006-08-17 05:07:08 UTC (rev 418) @@ -0,0 +1,11 @@ +# Copyright 2004 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import os +import types + +def test(): + "qwoeithawytrqwueryqweytrqweytrqweytroqweytrqoweytroqwueytrqowutroqweytroqw" + pass Modified: pydsc_dev/unittests/tester.py =================================================================== --- pydsc_dev/unittests/tester.py 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/unittests/tester.py 2006-08-17 05:07:08 UTC (rev 418) @@ -3,5 +3,14 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import os +import sys +sys.path.append( '..' ) + import pydsc -import to_be_tested \ No newline at end of file + +pydsc.exclude( os.path.abspath( os.path.join( os.curdir, 'do_not_check' ) ) ) +pydsc.ignore( 'abracadabra' ) + +import to_be_tested +import do_not_check Modified: pydsc_dev/unittests/to_be_tested.py =================================================================== --- pydsc_dev/unittests/to_be_tested.py 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/unittests/to_be_tested.py 2006-08-17 05:07:08 UTC (rev 418) @@ -8,8 +8,8 @@ class code_creator_t(object): """ - code_creator_t is the base class for all code creators. - This class defines interface that every code creator should implement. + code_creator_t is the base class for all code creators. + This class defines interface that every code creator should implement. Also it provides few convinience functions. """ PYPLUSPLUS_NS_NAME = 'pyplusplus' @@ -21,23 +21,23 @@ assert isinstance( parent, code_creator_t ) self._parent = parent self._target_configuration = None - + def _get_parent( self ): - return self._parent + return self._parent def _set_parent( self, new_parent ): if new_parent: assert isinstance( new_parent, code_creator_t ) self._parent = new_parent """parent - reference to parent code creator""" parent = property( _get_parent, _set_parent ) - + def _get_target_configuration( self ): return self._target_configuration def _set_target_configuration( self, config ): self._target_configuration = config """target_configuration - reference to target_configuration_t class instance""" target_configuration = property( _get_target_configuration, _set_target_configuration ) - + def _get_top_parent(self): parent = self.parent me = self @@ -52,15 +52,15 @@ def _create_impl(self): """ - function that all derived classes should implement. This function + function that all derived classes should implement. This function actually creates code and returns it. Return value of this function is string. """ raise NotImplementedError() - + def create(self): """ - this function should be used in order to get code that should be + this function should be used in order to get code that should be generated. """ code = self._create_impl() @@ -73,21 +73,21 @@ """ assert isinstance( code, types.StringTypes ) return code.strip() - + @staticmethod def indent( code, size=1 ): """ - function that implements code indent algorithm. + function that implements code indent algorithm. """ assert isinstance( code, types.StringTypes ) return code_creator_t.__INDENTATION * size\ + code.replace( os.linesep , os.linesep + code_creator_t.__INDENTATION * size ) - - @staticmethod + + @staticmethod def unindent( code ): """ - function that implements code unindent algorithm. + function that implements code unindent algorithm. """ assert isinstance( code, types.StringTypes ) if code.startswith(code_creator_t.__INDENTATION): @@ -95,7 +95,7 @@ return code.replace( os.linesep + code_creator_t.__INDENTATION , os.linesep ) - @staticmethod + @staticmethod def is_comment( line ): """ function that returns true if content of the line is comment, otherwise @@ -104,4 +104,10 @@ assert isinstance( line, types.StringTypes ) l = line.lstrip() #1q2w3e4r-------------- - return l.startswith( '//' ) or l.startswith( '/*' ) \ No newline at end of file + return l.startswith( '//' ) or l.startswith( '/*' ) + + + def do_nothing( self ): + """abracadabra""" + pass + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |