Home | Trees | Indices | Help |
|
---|
|
1 #! /usr/bin/env python 2 # Software License Agreement (BSD License) 3 # 4 # Copyright (c) 2008, Willow Garage, Inc. 5 # All rights reserved. 6 # 7 # Redistribution and use in source and binary forms, with or without 8 # modification, are permitted provided that the following conditions 9 # are met: 10 # 11 # * Redistributions of source code must retain the above copyright 12 # notice, this list of conditions and the following disclaimer. 13 # * Redistributions in binary form must reproduce the above 14 # copyright notice, this list of conditions and the following 15 # disclaimer in the documentation and/or other materials provided 16 # with the distribution. 17 # * Neither the name of Willow Garage, Inc. nor the names of its 18 # contributors may be used to endorse or promote products derived 19 # from this software without specific prior written permission. 20 # 21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 # POSSIBILITY OF SUCH DAMAGE. 33 34 """ 35 Python path loader for python scripts and applications. Paths are 36 derived from dependency structure declared in ROS manifest files. 37 """ 38 39 import os 40 import sys 41 42 import rospkg 43 44 # bootstrapped keeps track of which packages we've loaded so we don't 45 # update the path multiple times 46 _bootstrapped = [] 47 # _rospack is our cache of ROS package data 48 _rospack = rospkg.RosPack() 49 5052 vals = rospack.get_depends(package, implicit=True) 53 return [v for v in vals if not rospack.get_manifest(v).is_catkin]54 5557 """ 58 Update the Python sys.path with package's dependencies 59 60 :param package_name: name of the package that load_manifest() is being called from, ``str`` 61 """ 62 if package_name in _bootstrapped: 63 return 64 sys.path = _generate_python_path(package_name, _rospack) + sys.path65 6668 """ 69 Added paths for package to paths 70 :param manifest_: package manifest, ``Manifest`` 71 :param pkg_dir: package's filesystem directory path, ``str`` 72 :param paths: list of paths, ``[str]`` 73 """ 74 exports = manifest_.get_export('python', 'path') 75 if exports: 76 for export in exports: 77 if ':' in export: 78 export = export.split(':') 79 else: 80 export = [export] 81 for e in export: 82 paths.append(e.replace('${prefix}', pkg_dir)) 83 else: 84 dirs = [os.path.join(pkg_dir, d) for d in ['src', 'lib']] 85 paths.extend([d for d in dirs if os.path.isdir(d)])86 8789 """ 90 Recursive subroutine for building dependency list and python path 91 :raises: :exc:`rospkg.ResourceNotFound` If an error occurs while attempting to load package or dependencies 92 """ 93 if pkg in _bootstrapped: 94 return [] 95 96 # short-circuit if this is a catkin-ized package 97 m = rospack.get_manifest(pkg) 98 if m.is_catkin: 99 _bootstrapped.append(pkg) 100 return [] 101 102 packages = get_depends(pkg, rospack) 103 packages.append(pkg) 104 105 paths = [] 106 try: 107 for p in packages: 108 m = rospack.get_manifest(p) 109 d = rospack.get_path(p) 110 _append_package_paths(m, paths, d) 111 _bootstrapped.append(p) 112 except Exception: 113 if pkg in _bootstrapped: 114 _bootstrapped.remove(pkg) 115 raise 116 return paths117
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Mar 1 07:28:11 2022 | http://epydoc.sourceforge.net |