Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ catkin_package()
install(FILES DESTINATION ${CATKIN_PROJECT_SHARE_DESTINATION}/cmake)

catkin_python_setup()
catkin_add_nosetests(test/test_doxygenator.py)
23 changes: 15 additions & 8 deletions src/rosdoc_lite/doxygenator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,34 @@ def prepare_tagfiles(tagfile_spec, tagfile_dir, output_subfolder):
tagfile = open(tagfile_path, 'w')
tagfile.write(ret.read())
tagfile.close()
tagfile_string += "%s=%s " % (tagfile_path, get_relative_doc_path(output_subfolder, tag_pair))
tagfile_string += "%s=%s " % (tagfile_path, get_doc_path(output_subfolder, tag_pair))
except (urllib2.URLError, urllib2.HTTPError) as e:
print("Could not fetch the tagfile from %s, skipping" % tag_pair['location'], file=sys.stderr)
continue
elif tag_pair['location'].find("file://") == 0:
tagfile_path = tag_pair['location'][7:]
tagfile_string += "%s=%s " % (tagfile_path, get_relative_doc_path(output_subfolder, tag_pair))
tagfile_string += "%s=%s " % (tagfile_path, get_doc_path(output_subfolder, tag_pair))
else:
print("Tagfile location only supports http// and file:// prefixes, but you specify %s, skipping" % tag_pair['location'],
file=sys.stderr)
return tagfile_string


def get_relative_doc_path(output_subfolder, tag_pair):
def get_doc_path(output_subfolder, tag_pair):
"""Gets path from output_subfolder to url of tag_pair

If the url is a relative path from the root of documentation, the resulting
path will be relative to the output_subfolder, otherwise the absolute url
will be returned.
"""
path = tag_pair['docs_url']
# prefix the path with as many .. as the output_subfolder is deep
if output_subfolder != '.':
output_subfolder_level = len(output_subfolder.split('/'))
reverse_output_subfolder = output_subfolder_level * ['..']
reverse_output_subfolder = os.path.join(*reverse_output_subfolder)
path = os.path.join(reverse_output_subfolder, path)
if not path.startswith('http://') and not path.startswith('https://'):
if output_subfolder != '.':
output_subfolder_level = len(output_subfolder.split('/'))
reverse_output_subfolder = output_subfolder_level * ['..']
reverse_output_subfolder = os.path.join(*reverse_output_subfolder)
path = os.path.join(reverse_output_subfolder, path)
# append generator specific output folder
if 'doxygen_output_folder' in tag_pair:
path = os.path.join(path, tag_pair['doxygen_output_folder'])
Expand Down
23 changes: 23 additions & 0 deletions test/test_doxygenator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest
from rosdoc_lite import doxygenator as doxy

class TestGetDocPath(unittest.TestCase):

def test_relative_doc_path(self):
tag_pair = {'docs_url':"relative/path"}
output = doxy.get_doc_path("sub/folders", tag_pair)
self.assertEqual("../../relative/path", output)

tag_pair = {'docs_url':"relative/path",'doxygen_output_folder':"doxygen_output_folder"}
output = doxy.get_doc_path("sub/folders", tag_pair)
self.assertEqual("../../relative/path/doxygen_output_folder", output)

def test_absolute_doc_path(self):
tag_pair = {'docs_url': "https://absolu.te/path"}
output = doxy.get_doc_path("sub/folders", tag_pair)
self.assertEqual("https://absolu.te/path", output)

tag_pair = {'docs_url': "https://absolu.te/path",'doxygen_output_folder':"doxygen_output_folder"}
output = doxy.get_doc_path("sub/folders", tag_pair)
self.assertEqual("https://absolu.te/path/doxygen_output_folder", output)