Skip to content

Commit

Permalink
Fixing issues and debug improvements:
Browse files Browse the repository at this point in the history
- only try to download dependencies from <build_depend> tags
- Fix #1. `package.xml` file was malformed. Now the verb will fix it, but will
  show a warning to a user.
- add one more test
  • Loading branch information
niosus committed Nov 22, 2016
1 parent 2276e07 commit dd101d2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
27 changes: 25 additions & 2 deletions catkin_tools_fetch/fetcher/dependency_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Parser(object):
"""

XML_FILE_NAME = "package.xml"
TAGS = ["buildtool_depend", "build_depend"]
TAGS = ["build_depend"]
URL_TAGS = ["git_url"]

def __init__(self, download_mask, pkg_name):
Expand Down Expand Up @@ -70,13 +70,36 @@ def __get_all_dependencies(self, path_to_xml):
xmldoc = minidom.parse(path_to_xml)
all_deps = []
for tag in Parser.TAGS:
all_deps += Parser.__node_to_list(xmldoc, tag)
deps = Parser.__node_to_list(xmldoc, tag)
deps = Parser.__fix_dependencies(deps, self.pkg_name)
all_deps += deps
log.info(" %-21s: Found %s dependencies.",
Tools.decorate(self.pkg_name),
len(all_deps))
log.debug(" Dependencies: %s", all_deps)
deps_with_urls = self.__init_dep_dict(all_deps)
return Parser.__specify_explicit_urls(xmldoc, deps_with_urls)

@staticmethod
def __fix_dependencies(deps, pkg_name):
"""Fix dependencies if they are malformed.
Args:
deps (str[]): List of dependencies.
pkg_name (str): Current package name.
Returns:
str[]: Fixed dependencies.
"""
fixed_deps = list(deps)
for i, dep in enumerate(deps):
fixed_deps[i] = dep.strip()
if fixed_deps[i] != dep:
log.warning(
" [%s]: Fix dependency in `package.xml`: [%s] to [%s]",
pkg_name, dep, fixed_deps[i])
return fixed_deps

@staticmethod
def __specify_explicit_urls(xmldoc, intial_dep_dict):
"""Specify explicit urls instead of default ones.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run(self):
os.chmod(file, mode)


version_str = '0.0.5'
version_str = '0.0.6'
github_url = 'https://github.com/niosus/catkin_tools_fetch'

setup(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ def test_download_dependencies_simple(self):
'README.md')
self.assertTrue(path.exists(expected_path))

def test_download_dependencies_again(self):
temp_dir = tempfile.mkdtemp("_ws", "temp_")
downloader = Downloader(temp_dir, [], [])
dep_dict = {"fetch": "https://github.com/niosus/catkin_tools_fetch"}
downloader.download_dependencies(dep_dict)
downloader.download_dependencies(dep_dict)
expected_path = path.join(temp_dir,
'fetch',
'README.md')
self.assertTrue(path.exists(expected_path))

def test_no_download_for_ros_deps(self):
temp_dir = tempfile.mkdtemp("_ws", "no_ros_")
downloader = Downloader(temp_dir, [], [])
Expand Down

0 comments on commit dd101d2

Please sign in to comment.