Update of /cvsroot/happydoc/HappyDoc/happydoclib
In directory usw-pr-cvs1:/tmp/cvs-serv10733/happydoclib
Modified Files:
Tag: dos_path_bug
happydocset.py happydom.py path.py
Log Message:
Initial pass at a fix for the Win32 path problems, including simplifying the definition of the path to the output file for an objects documentation.
Index: happydocset.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/happydocset.py,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -C2 -d -r1.8 -r1.8.2.1
*** happydocset.py 10 Feb 2002 13:25:49 -0000 1.8
--- happydocset.py 13 May 2002 01:14:44 -0000 1.8.2.1
***************
*** 342,345 ****
--- 342,353 ----
fully_qualified_name = formatter.getOutputNameForObject(self)
happydoclib.TRACE.writeVar(fully_qualified_name=fully_qualified_name)
+
+ extension = '.%s' % formatter.getFilenameExtension()
+ len_extension = len(extension)
+ if fully_qualified_name[-len_extension:] == extension:
+ happydoclib.TRACE.write('fully qualified name has extension')
+ fully_qualified_name = fully_qualified_name[:-len_extension]
+ happydoclib.TRACE.writeVar(fully_qualified_name=fully_qualified_name)
+
root_node_name = formatter.getRootNodeName()
my_root_node = happydoclib.path.join(fully_qualified_name, root_node_name)
***************
*** 557,560 ****
--- 565,569 ----
'statusMessageFunc':self._status_message_func,
'useRecursion':self._use_recursion,
+ 'parent':self,
}
#
***************
*** 578,586 ****
def getFileInfo(self, fileName):
"Parse the file and return the parseinfo instance for it."
self.statusMessage('Getting info for %s' % fileName)
! return self._parser_func( fileName,
! self._include_comments,
! self._default_parser_config_values,
! )
def lookForPrewrittenFiles(self, dirName):
--- 587,599 ----
def getFileInfo(self, fileName):
"Parse the file and return the parseinfo instance for it."
+ happydoclib.TRACE.into('DocSet', 'getFileInfo', fileName=fileName)
self.statusMessage('Getting info for %s' % fileName)
! module_info = self._parser_func( self,
! fileName,
! self._include_comments,
! self._default_parser_config_values,
! )
! happydoclib.TRACE.outof(module_info)
! return module_info
def lookForPrewrittenFiles(self, dirName):
***************
*** 832,854 ****
class DocsetUnitTest(happydoclib.StreamFlushTest.StreamFlushTest):
!
! def testPackageSummaries(self):
! filename = 'TestCases/test_package_summaries'
!
! basic_expected_package_info = {
! 'FromInit':'Summary from __init__.py',
! 'FromReadme':'Summary from README',
! 'FromReadmeTxt':'Summary from README.txt',
! 'FromTitle':'HappyDoc Generated Documentation (use -t to specify a new title): Nested.FromTitle',
! }
! basic_expected_package_names = basic_expected_package_info.keys()
!
! parent_expected_package_info = {}
! parent_expected_package_info.update(basic_expected_package_info)
! parent_expected_package_info['Nested'] = 'Nested Modules'
! parent_expected_package_info['FromTitle'] = 'HappyDoc Generated Documentation (use -t to specify a new title): FromTitle'
! parent_expected_package_names = parent_expected_package_info.keys()
!
! #module = getDocs(None, filename)
import happydoclib.formatter.formatter_Null
docset = DocSet( formatterFactory=happydoclib.formatter.formatter_Null.NullFormatter,
--- 845,852 ----
class DocsetUnitTest(happydoclib.StreamFlushTest.StreamFlushTest):
!
! def testOutputDirectory(self):
! filename = 'TestCases/test.py'
! test_output_dir = 'c:\\happydoc\\HappyDocTestOut'
import happydoclib.formatter.formatter_Null
docset = DocSet( formatterFactory=happydoclib.formatter.formatter_Null.NullFormatter,
***************
*** 856,892 ****
defaultParserConfigValues={'docStringFormat':'StructuredText'},
inputModuleNames=[ filename ],
! outputBaseDirectory=self.output_dir,
statusMessageFunc=self.status_message_func,
)
! for m in docset.data:
! name = m.getName()
! assert name in parent_expected_package_names, \
! 'Unexpected module %s found in docset.' % name
!
! expected_summary = parent_expected_package_info[name]
!
! actual_summary, format = m.getSummaryAndFormat()
! assert actual_summary == expected_summary, \
! 'Summary values do not match for %s (expected "%s", got "%s")' \
! % (name, expected_summary, actual_summary)
!
! if name == 'Nested':
! for cm in m.data:
! cname = cm.getName()
! if cname == '__init__':
! continue
! assert cname in basic_expected_package_names, \
! 'Unexpected child module %s found in child docset.' % cname
!
! cexpected_summary = basic_expected_package_info[cname]
! cactual_summary, format = cm.getSummaryAndFormat()
! assert cactual_summary == cexpected_summary, \
! 'Summary values do not match for child module %s (expected "%s", got "%s")' \
! % (cname, cexpected_summary, cactual_summary)
!
!
! return
def _privateNameTest(self, includePrivateNames):
--- 854,925 ----
defaultParserConfigValues={'docStringFormat':'StructuredText'},
inputModuleNames=[ filename ],
! outputBaseDirectory=test_output_dir,
statusMessageFunc=self.status_message_func,
)
! docset_base_dir = docset.getDocsetBaseDirectory()
! assert docset_base_dir == test_output_dir, 'Docset directory %s does not match %s' % \
! (docset_base_dir, test_output_dir)
! output_base_dir = docset.getOutputBaseDirectory()
! assert docset_base_dir == test_output_dir, 'Output directory %s does not match %s' % \
! (docset_base_dir, test_output_dir)
! docset_file_name = docset.getFilename()
! assert docset_file_name == test_output_dir, 'File name %s does not match expected %s' % \
! (docset_file_name, test_output_dir)
! return
! if os.name != 'nt':
! def testPackageSummaries(self):
! filename = 'TestCases/test_package_summaries'
!
! basic_expected_package_info = {
! 'FromInit':'Summary from __init__.py',
! 'FromReadme':'Summary from README',
! 'FromReadmeTxt':'Summary from README.txt',
! 'FromTitle':'HappyDoc Generated Documentation (use -t to specify a new title): Nested.FromTitle',
! }
! basic_expected_package_names = basic_expected_package_info.keys()
! parent_expected_package_info = {}
! parent_expected_package_info.update(basic_expected_package_info)
! parent_expected_package_info['Nested'] = 'Nested Modules'
! parent_expected_package_info['FromTitle'] = 'HappyDoc Generated Documentation (use -t to specify a new title): FromTitle'
! parent_expected_package_names = parent_expected_package_info.keys()
!
! #module = getDocs(None, filename)
! import happydoclib.formatter.formatter_Null
! docset = DocSet( formatterFactory=happydoclib.formatter.formatter_Null.NullFormatter,
! parserFunc=happydoclib.parseinfo.getDocs,
! defaultParserConfigValues={'docStringFormat':'StructuredText'},
! inputModuleNames=[ filename ],
! outputBaseDirectory=self.output_dir,
! statusMessageFunc=self.status_message_func,
! )
! for m in docset.data:
! name = m.getName()
! assert name in parent_expected_package_names, \
! 'Unexpected module %s found in docset.' % name
!
! expected_summary = parent_expected_package_info[name]
!
! actual_summary, format = m.getSummaryAndFormat()
! assert actual_summary == expected_summary, \
! 'Summary values do not match for %s (expected "%s", got "%s")' \
! % (name, expected_summary, actual_summary)
!
! if name == 'Nested':
! for cm in m.data:
! cname = cm.getName()
! if cname == '__init__':
! continue
! assert cname in basic_expected_package_names, \
! 'Unexpected child module %s found in child docset.' % cname
!
! cexpected_summary = basic_expected_package_info[cname]
!
! cactual_summary, format = cm.getSummaryAndFormat()
! assert cactual_summary == cexpected_summary, \
! 'Summary values do not match for child module %s (expected "%s", got "%s")' \
! % (cname, cexpected_summary, cactual_summary)
! return
def _privateNameTest(self, includePrivateNames):
Index: happydom.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/happydom.py,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -C2 -d -r1.4 -r1.4.2.1
*** happydom.py 11 Nov 2001 18:46:19 -0000 1.4
--- happydom.py 13 May 2002 01:14:44 -0000 1.4.2.1
***************
*** 115,118 ****
--- 115,129 ----
return self._parent
+ def getPath(self):
+ "Returns a sequence of node names leading to this node."
+ parent = self.getParent()
+ if parent:
+ path = parent.getPath()
+ else:
+ path = []
+ if self.getName():
+ path.append( self.getName() )
+ return path
+
def getFilename(self):
"Return the filename from which the object came."
***************
*** 134,138 ****
happydoclib.TRACE.writeVar(parent_base=parent_base)
happydoclib.TRACE.writeVar(parent_ext=parent_ext)
! name = '%s_%s%s' % ( parent_base, self.getName(), parent_ext )
happydoclib.TRACE.outof(name)
return name
--- 145,154 ----
happydoclib.TRACE.writeVar(parent_base=parent_base)
happydoclib.TRACE.writeVar(parent_ext=parent_ext)
! #if parent_ext:
! # my_file = '%s.%s' % (self.getName(), parent_ext)
! #else:
! # my_file = self.getName()
! my_file = self.getFilename()
! name = happydoclib.path.join(parent_base, my_file)
happydoclib.TRACE.outof(name)
return name
Index: path.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc/happydoclib/path.py,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -C2 -d -r1.8 -r1.8.2.1
*** path.py 17 Feb 2002 13:49:49 -0000 1.8
--- path.py 13 May 2002 01:14:44 -0000 1.8.2.1
***************
*** 67,71 ****
# Import Local modules
#
! from happydoclib.StreamFlushTest import StreamFlushTest
#
--- 67,74 ----
# Import Local modules
#
! from StreamFlushTest import StreamFlushTest
! from trace import trace as TRACE
!
! #TRACE.setVerbosity(3)
#
***************
*** 97,102 ****
def applyPrefixToPath(path, prefix):
"Add the prefix value to every part of a given path."
parts = string.split( path, os.sep )
! #print 'PARTS:', parts
prefix_len = len(prefix)
real_parts = []
--- 100,107 ----
def applyPrefixToPath(path, prefix):
"Add the prefix value to every part of a given path."
+ TRACE.into('PATH', 'applyPrefixToPath', path=path, prefix=prefix)
+ drive, path = os.path.splitdrive(path)
parts = string.split( path, os.sep )
! TRACE.writeVar(parts=parts)
prefix_len = len(prefix)
real_parts = []
***************
*** 105,129 ****
pass
elif p not in ( '.', '..' ) and (p[:prefix_len] != prefix):
! #print 'modifying "%s"' % p
p = '%s%s' % (prefix, p)
real_parts.append(p)
! #print 'REAL PARTS:', real_parts
name = apply(os.path.join, real_parts)
! if path and path[0] == os.sep:
name = os.sep + name
return name
def removePrefix(path, prefix):
"Remove prefix from the beginning of path, if present."
one_up = os.path.dirname(path)
common_prefix = commonPrefix(one_up, prefix)
! #print 'PATH: removePrefix( %s, %s )' % (path, prefix)
! #print 'PATH: common_prefix', common_prefix
if common_prefix == prefix:
path = path[len(common_prefix):]
while path and (path[0] == os.sep):
path = path[1:]
! #print 'PATH: result', path
return path
--- 110,152 ----
pass
elif p not in ( '.', '..' ) and (p[:prefix_len] != prefix):
! TRACE.write('modifying "%s"' % p)
p = '%s%s' % (prefix, p)
real_parts.append(p)
! TRACE.writeVar(real_parts=real_parts)
name = apply(os.path.join, real_parts)
! if drive:
! name = os.sep.join((drive, name))
! elif path and path[0] == os.sep:
name = os.sep + name
+ TRACE.outof(name)
return name
def removePrefix(path, prefix):
"Remove prefix from the beginning of path, if present."
+ TRACE.into('PATH', 'removePrefix', path=path, prefix=prefix)
+
+ path=os.path.normcase(path)
+ prefix=os.path.normcase(prefix)
+ TRACE.writeVar(path_after_norm_case=path)
+ TRACE.writeVar(prefix_after_norm_case=prefix)
+
one_up = os.path.dirname(path)
+ TRACE.writeVar(one_up=one_up)
+
common_prefix = commonPrefix(one_up, prefix)
! TRACE.writeVar(common_prefix=common_prefix)
!
if common_prefix == prefix:
path = path[len(common_prefix):]
+ else:
+ TRACE.write('common prefix (%s)' % common_prefix)
+ TRACE.write('does not match specified prefix (%s)' % prefix)
+
+ TRACE.writeVar(pathMinusPrefix=path)
while path and (path[0] == os.sep):
path = path[1:]
!
! TRACE.outof(path)
return path
***************
*** 144,162 ****
subdirectory name matches.
"""
! #print 'commonPrefix(%s, %s)' % (path1, path2)
if not path1 or not path2:
return ''
path1_parts = string.split(path1, os.sep)
path2_parts = string.split(path2, os.sep)
common = []
for p1, p2 in map(None, path1_parts, path2_parts):
! if p1 == p2:
common.append(p1)
else:
break
common = string.join(common, os.sep)
! if path1 and path1[0] == '/' and common and common[0] != '/':
! common = '/' + common
! #print '->"%s"' % common
return common
--- 167,204 ----
subdirectory name matches.
"""
! TRACE.into('PATH', 'commonPrefix', path1=path1, path2=path2)
if not path1 or not path2:
+ TRACE.outof('')
+ return ''
+
+ drive1, path1 = os.path.splitdrive(path1)
+ TRACE.writeVar(drive1=drive1)
+ drive2, path2 = os.path.splitdrive(path2)
+ TRACE.writeVar(drive2=drive2)
+ if drive1 != drive2:
+ TRACE.outof('')
return ''
+
path1_parts = string.split(path1, os.sep)
+ TRACE.writeVar(path1_parts=path1_parts)
path2_parts = string.split(path2, os.sep)
+ TRACE.writeVar(path2_parts=path2_parts)
+
common = []
for p1, p2 in map(None, path1_parts, path2_parts):
! if p1 and p1 == p2:
! TRACE.write('Found common part "%s"' % p1)
common.append(p1)
+ elif not p1:
+ pass
else:
break
common = string.join(common, os.sep)
! if drive1 and common:
! TRACE.write('have a drive spec')
! common = os.path.normcase('%s%s%s' % (drive1, os.sep, common))
! elif path1 and path1[0] == os.sep and common and common[0] != os.sep:
! common = os.sep + common
! TRACE.outof(common)
return common
***************
*** 186,194 ****
# Find the part of path1 which is *not* part of path1prefix
#
! #print 'joinWithCommonMiddle(%s, %s, %s)' % (path1prefix, path1, path2)
common_prefix = commonPrefix(path1prefix, path1)
! #print ' common prefix:', common_prefix
real_base = removePrefix(path1, common_prefix)
! #print ' real base:', real_base
#
# Remove the prefix common to the docset_real_base and
--- 228,237 ----
# Find the part of path1 which is *not* part of path1prefix
#
! TRACE.into('PATH', 'joinWithCommonMiddle', path1prefix=path1prefix,
! path1=path1, path2=path2)
common_prefix = commonPrefix(path1prefix, path1)
! TRACE.writeVar(common_prefix=common_prefix)
real_base = removePrefix(path1, common_prefix)
! TRACE.writeVar(real_base=real_base)
#
# Remove the prefix common to the docset_real_base and
***************
*** 196,205 ****
#
common_prefix = commonPrefix(real_base, path2)
! #print ' common prefix with real base and path2:', common_prefix
path2 = removePrefix(path2, common_prefix)
! #print ' fixed path2:', path2
name = join( path1, path2 )
! #print '->"%s"' % name
return name
--- 239,248 ----
#
common_prefix = commonPrefix(real_base, path2)
! TRACE.write('common prefix with real base and path2:', common_prefix)
path2 = removePrefix(path2, common_prefix)
! TRACE.write('fixed path2:', path2)
name = join( path1, path2 )
! TRACE.outof(name)
return name
***************
*** 222,230 ****
fromName will point directly to toName.
"""
! dbg=0
! if dbg: print '\nPATH: FROM: ', fromName
! if dbg: print 'PATH: TO : ', toName
! if dbg: print 'PATH: BASE: ', baseDirectory
!
#
# Normalize directory names
--- 265,273 ----
fromName will point directly to toName.
"""
! TRACE.into('PATH', 'computeRelativeHTMLLink',
! fromName=fromName,
! toName=toName,
! baseDirectory=baseDirectory,
! )
#
# Normalize directory names
***************
*** 232,237 ****
fromName = os.path.normpath(fromName)
toName = os.path.normpath(toName)
! if dbg: print 'PATH: FROM NORMALIZED : ', fromName
! if dbg: print 'PATH: TO NORMALIZED : ', toName
#
--- 275,280 ----
fromName = os.path.normpath(fromName)
toName = os.path.normpath(toName)
! TRACE.writeVar(fromNameNormalized=fromName)
! TRACE.writeVar(toNameNormalized=toName)
#
***************
*** 240,248 ****
fromName = removePrefix(fromName, baseDirectory)
toName = removePrefix(toName, baseDirectory)
! if dbg: print 'PATH: FROM - PREFIX : ', fromName
! if dbg: print 'PATH: TO - PREFIX : ', toName
if fromName == toName:
! if dbg: print '\tPATH: same name'
relative_link = os.path.basename(toName)
else:
--- 283,291 ----
fromName = removePrefix(fromName, baseDirectory)
toName = removePrefix(toName, baseDirectory)
! TRACE.writeVar(fromNameMinusPrefix=fromName)
! TRACE.writeVar(toNameMinusPrefix=toName)
if fromName == toName:
! TRACE.writeVar(toName=toName)
relative_link = os.path.basename(toName)
else:
***************
*** 251,260 ****
while from_name_no_prefix and (from_name_no_prefix[0] == os.sep):
from_name_no_prefix = from_name_no_prefix[1:]
! if dbg: print '\tPATH: from, no prefix:', from_name_no_prefix
! if dbg and from_name_no_prefix == 'z.html':
! raise 'debug'
subdir_path = os.path.dirname(from_name_no_prefix)
parts = string.split(subdir_path, os.sep)
! if dbg: print '\tPATH: parts:', parts
if parts and parts[0]:
levels = len(string.split(subdir_path, os.sep))
--- 294,301 ----
while from_name_no_prefix and (from_name_no_prefix[0] == os.sep):
from_name_no_prefix = from_name_no_prefix[1:]
! TRACE.writeVar(from_name_no_prefix=from_name_no_prefix)
subdir_path = os.path.dirname(from_name_no_prefix)
parts = string.split(subdir_path, os.sep)
! TRACE.writeVar(parts=parts)
if parts and parts[0]:
levels = len(string.split(subdir_path, os.sep))
***************
*** 266,270 ****
to_name_no_prefix = to_name_no_prefix[1:]
relative_link = "%s%s" % (up_levels, to_name_no_prefix)
! if dbg: print 'PATH: LINK: ', relative_link, '\n'
return relative_link
--- 307,311 ----
to_name_no_prefix = to_name_no_prefix[1:]
relative_link = "%s%s" % (up_levels, to_name_no_prefix)
! TRACE.outof(relative_link)
return relative_link
***************
*** 305,309 ****
def join( *args ):
"os.path.join"
! return apply(os.path.join, args)
def cwd():
--- 346,353 ----
def join( *args ):
"os.path.join"
! TRACE.into('PATH', 'join', args=args)
! result=apply(os.path.join, args)
! TRACE.outof(result)
! return result
def cwd():
***************
*** 349,352 ****
--- 393,405 ----
% (expected, actual)
return
+
+ if os.name == 'nt':
+ def testApplyPreifxToPathWin32(self):
+ expected = 'c:\\BLAH_tmp\\BLAH_foo'
+ actual = applyPrefixToPath('c:\\BLAH_tmp\\BLAH_foo', 'BLAH_')
+ assert actual == expected, \
+ 'Path modification failed.\n\tExpected "%s",\n\tgot "%s"' \
+ % (expected, actual)
+ return
def testApplyPrefixToPathEmpty(self):
***************
*** 373,376 ****
--- 426,438 ----
% (expected, actual)
return
+
+ if os.name == 'nt':
+ def testRemovePrefixWin32(self):
+ expected = 'foo'
+ actual = removePrefix('c:\\tmp\\foo', 'c:\\tmp')
+ assert actual == expected, \
+ 'Path modification failed.\n\tExpected "%s",\n\tgot "%s"' \
+ % (expected, actual)
+ return
def testRemovePrefixNotThere(self):
***************
*** 381,384 ****
--- 443,455 ----
% (expected, actual)
return
+
+ if os.name == 'nt':
+ def testRemovePrefixNotThereWin32(self):
+ expected = 'c:\\tmp\\foo'
+ actual = removePrefix('c:\\tmp\\foo', 'c:\\blah')
+ assert actual == expected, \
+ 'Path modification failed.\n\tExpected "%s",\n\tgot "%s"' \
+ % (expected, actual)
+ return
def testRemovePrefixEmptyPath(self):
***************
*** 407,410 ****
--- 478,491 ----
return
+ if os.name == 'nt':
+ def testCommonPrefixWin32(self):
+ expected = 'c:\\tmp'
+ actual = commonPrefix('c:\\tmp\\foo',
+ 'c:\\tmp\\blah')
+ assert actual == expected, \
+ 'Path modification failed.\n\tExpected "%s",\n\tgot "%s"' \
+ % (expected, actual)
+ return
+
def testCommonPrefixNone(self):
expected = ''
***************
*** 417,420 ****
--- 498,513 ----
return
+ if os.name == 'nt':
+ def testCommonPrefixNoneWin32(self):
+ expected = ''
+ actual = commonPrefix('c:\\var\\tmp\\foo',
+ 'c:\\tmp\\blah',
+ )
+ assert actual == expected, \
+ 'Path modification failed.\n\tExpected "%s",\n\tgot "%s"' \
+ % (expected, actual)
+ return
+
+
def testCommonPrefixEmptyPaths(self):
expected = ''
***************
*** 440,443 ****
--- 533,548 ----
% (expected, actual)
return
+
+ if os.name == 'nt':
+ def testJoinWithCommonMiddleWin32(self):
+ expected = 'c:\\root\\one\\two\\three\\filename.txt'
+ actual = joinWithCommonMiddle('c:\\root\\one',
+ 'c:\\root\\one\\two',
+ 'two\\three\\filename.txt'
+ )
+ assert actual == expected, \
+ 'Path modification failed.\n\tExpected "%s",\n\tgot "%s"' \
+ % (expected, actual)
+ return
def testJoinWithCommonMiddleNotCommon(self):
***************
*** 451,454 ****
--- 556,571 ----
% (expected, actual)
return
+
+ if os.name == 'nt':
+ def testJoinWithCommonMiddleNotCommonWin32(self):
+ expected = 'c:\\%s' % os.path.join('root', 'one', 'four', 'two', 'three', 'filename.txt')
+ actual = joinWithCommonMiddle('c:\\%s' % os.path.join('root', 'one', 'five'),
+ 'c:\\%s' % os.path.join('root', 'one', 'four'),
+ os.path.join('two', 'three', 'filename.txt')
+ )
+ assert actual == expected, \
+ 'Path modification failed.\n\tExpected "%s",\n\tgot "%s"' \
+ % (expected, actual)
+ return
def testJoinWithCommonMiddleEmptyPrefix(self):
***************
*** 462,465 ****
--- 579,594 ----
% (expected, actual)
return
+
+ if os.name == 'nt':
+ def testJoinWithCommonMiddleEmptyPrefixWin32(self):
+ expected = 'c:\\%s' % os.path.join('root', 'one', 'four', 'two', 'three', 'filename.txt')
+ actual = joinWithCommonMiddle('',
+ 'c:\\%s' % os.path.join('root', 'one', 'four'),
+ os.path.join('two', 'three', 'filename.txt')
+ )
+ assert actual == expected, \
+ 'Path modification failed.\n\tExpected "%s",\n\tgot "%s"' \
+ % (expected, actual)
+ return
def testJoinWithCommonMiddleEmptyPath1(self):
***************
*** 543,546 ****
if __name__ == '__main__':
! unittest.main()
!
--- 672,674 ----
if __name__ == '__main__':
! unittest.main()
|