From dd101d21c856854723717b7bab051b6e1ac60759 Mon Sep 17 00:00:00 2001 From: Igor Bogoslavskyi Date: Tue, 22 Nov 2016 12:16:55 +0100 Subject: [PATCH] Fixing issues and debug improvements: - only try to download dependencies from 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 --- .../fetcher/dependency_parser.py | 27 +++++++++++++++++-- setup.py | 2 +- tests/test_downloader.py | 11 ++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/catkin_tools_fetch/fetcher/dependency_parser.py b/catkin_tools_fetch/fetcher/dependency_parser.py index 3d1739a..eb0dca7 100644 --- a/catkin_tools_fetch/fetcher/dependency_parser.py +++ b/catkin_tools_fetch/fetcher/dependency_parser.py @@ -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): @@ -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. diff --git a/setup.py b/setup.py index 40dc266..32a80ca 100644 --- a/setup.py +++ b/setup.py @@ -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( diff --git a/tests/test_downloader.py b/tests/test_downloader.py index bf03fcd..79f08e0 100644 --- a/tests/test_downloader.py +++ b/tests/test_downloader.py @@ -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, [], [])