[svn r38393] Made (displayed) paths to source files relative whenever possible.
--HG-- branch : trunk
This commit is contained in:
parent
e280dfe1f0
commit
d3cd1c5bcf
|
@ -153,6 +153,12 @@ def get_obj(dsa, pkg, dotted_name):
|
||||||
full_dotted_name))
|
full_dotted_name))
|
||||||
return ret
|
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
|
# the PageBuilder classes take care of producing the docs (using the stuff
|
||||||
# above)
|
# above)
|
||||||
class AbstractPageBuilder(object):
|
class AbstractPageBuilder(object):
|
||||||
|
@ -339,7 +345,8 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
sep = get_linesep(callable_source)
|
sep = get_linesep(callable_source)
|
||||||
org = callable_source.split(sep)
|
org = callable_source.split(sep)
|
||||||
colored = [enumerate_and_color(org, firstlineno, enc)]
|
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:
|
if is_in_pkg:
|
||||||
href = self.linker.get_lazyhref(sourcefile)
|
href = self.linker.get_lazyhref(sourcefile)
|
||||||
|
|
||||||
|
@ -606,8 +613,9 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
href = self.linker.get_lazyhref(id)
|
href = self.linker.get_lazyhref(id)
|
||||||
self.write_page('call site %s for %s' % (index, dotted_name),
|
self.write_page('call site %s for %s' % (index, dotted_name),
|
||||||
reltargetpath, tbtag, nav)
|
reltargetpath, tbtag, nav)
|
||||||
return H.CallStackLink(call_site[0].filename, call_site[0].lineno + 1,
|
sourcefile = call_site[0].filename
|
||||||
href)
|
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'([^>]*)<(.*)>')
|
_reg_source = py.std.re.compile(r'([^>]*)<(.*)>')
|
||||||
def gen_traceback(self, dotted_name, call_site):
|
def gen_traceback(self, dotted_name, call_site):
|
||||||
|
@ -629,7 +637,9 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
l = ' %s' % (sline,)
|
l = ' %s' % (sline,)
|
||||||
mangled.append(l)
|
mangled.append(l)
|
||||||
if sourcefile:
|
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
|
# skip py.code.Source objects and source files outside of the
|
||||||
# package
|
# package
|
||||||
is_code_source = self._reg_source.match(sourcefile)
|
is_code_source = self._reg_source.match(sourcefile)
|
||||||
|
|
|
@ -144,8 +144,10 @@ class TestApiPageBuilder(AbstractBuilderTest):
|
||||||
assert pos5 > pos4 and pos5 > pos3
|
assert pos5 > pos4 and pos5 > pos3
|
||||||
pos6 = html.find('<None>', pos5)
|
pos6 = html.find('<None>', pos5)
|
||||||
assert pos6 > pos5
|
assert pos6 > pos5
|
||||||
pos7 = html.find('source: %s' % (self.fs_root.join('pkg/func.py'),),
|
sourcefile = self.fs_root.join('pkg/func.py')
|
||||||
pos6)
|
pos7 = html.find('source: %s' % (get_rel_sourcepath(apb.projpath,
|
||||||
|
sourcefile),),
|
||||||
|
pos6)
|
||||||
assert pos7 > pos6
|
assert pos7 > pos6
|
||||||
_checkhtmlsnippet(html)
|
_checkhtmlsnippet(html)
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@ def assert_eq_string(string1, string2):
|
||||||
start, end, string2[start:end],
|
start, end, string2[start:end],
|
||||||
string1, string2
|
string1, string2
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
def test_create_namespace_tree():
|
def test_create_namespace_tree():
|
||||||
tree = htmlgen.create_namespace_tree(['foo.bar.baz'])
|
tree = htmlgen.create_namespace_tree(['foo.bar.baz'])
|
||||||
assert tree == {'': ['foo'],
|
assert tree == {'': ['foo'],
|
||||||
|
@ -127,3 +126,12 @@ def test_show_property():
|
||||||
assert not htmlgen.show_property('__name__')
|
assert not htmlgen.show_property('__name__')
|
||||||
assert not htmlgen.show_property('__class__')
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue