[svn r38393] Made (displayed) paths to source files relative whenever possible.

--HG--
branch : trunk
This commit is contained in:
guido 2007-02-10 16:19:17 +01:00
parent e280dfe1f0
commit d3cd1c5bcf
3 changed files with 28 additions and 8 deletions

View File

@ -153,6 +153,12 @@ def get_obj(dsa, pkg, dotted_name):
full_dotted_name))
return ret
def get_rel_sourcepath(projpath, filename, default=None):
relpath = py.path.local(filename).relto(projpath)
if not relpath:
return default
return relpath
# the PageBuilder classes take care of producing the docs (using the stuff
# above)
class AbstractPageBuilder(object):
@ -339,7 +345,8 @@ class ApiPageBuilder(AbstractPageBuilder):
sep = get_linesep(callable_source)
org = callable_source.split(sep)
colored = [enumerate_and_color(org, firstlineno, enc)]
text = 'source: %s' % (sourcefile,)
relpath = get_rel_sourcepath(self.projroot, sourcefile, sourcefile)
text = 'source: %s' % (relpath,)
if is_in_pkg:
href = self.linker.get_lazyhref(sourcefile)
@ -606,8 +613,9 @@ class ApiPageBuilder(AbstractPageBuilder):
href = self.linker.get_lazyhref(id)
self.write_page('call site %s for %s' % (index, dotted_name),
reltargetpath, tbtag, nav)
return H.CallStackLink(call_site[0].filename, call_site[0].lineno + 1,
href)
sourcefile = call_site[0].filename
sourcepath = get_rel_sourcepath(self.projpath, sourcefile, sourcefile)
return H.CallStackLink(sourcepath, call_site[0].lineno + 1, href)
_reg_source = py.std.re.compile(r'([^>]*)<(.*)>')
def gen_traceback(self, dotted_name, call_site):
@ -629,7 +637,9 @@ class ApiPageBuilder(AbstractPageBuilder):
l = ' %s' % (sline,)
mangled.append(l)
if sourcefile:
linktext = '%s - line %s' % (sourcefile, frame.lineno + 1)
relpath = get_rel_sourcepath(self.projpath, sourcefile,
sourcefile)
linktext = '%s - line %s' % (relpath, frame.lineno + 1)
# skip py.code.Source objects and source files outside of the
# package
is_code_source = self._reg_source.match(sourcefile)

View File

@ -144,8 +144,10 @@ class TestApiPageBuilder(AbstractBuilderTest):
assert pos5 > pos4 and pos5 > pos3
pos6 = html.find('&lt;None&gt;', pos5)
assert pos6 > pos5
pos7 = html.find('source: %s' % (self.fs_root.join('pkg/func.py'),),
pos6)
sourcefile = self.fs_root.join('pkg/func.py')
pos7 = html.find('source: %s' % (get_rel_sourcepath(apb.projpath,
sourcefile),),
pos6)
assert pos7 > pos6
_checkhtmlsnippet(html)

View File

@ -20,8 +20,7 @@ def assert_eq_string(string1, string2):
start, end, string2[start:end],
string1, string2
))
def test_create_namespace_tree():
tree = htmlgen.create_namespace_tree(['foo.bar.baz'])
assert tree == {'': ['foo'],
@ -127,3 +126,12 @@ def test_show_property():
assert not htmlgen.show_property('__name__')
assert not htmlgen.show_property('__class__')
def test_get_rel_sourcepath():
projpath = py.path.local('/proj')
assert (htmlgen.get_rel_sourcepath(projpath, py.path.local('/proj/foo')) ==
'foo')
assert (htmlgen.get_rel_sourcepath(projpath, py.path.local('/foo')) is
None)
assert (htmlgen.get_rel_sourcepath(projpath, py.path.local('<string>')) is
None)