1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 """
38 Python path loader for python scripts and applications. Paths are
39 derived from dependency structure declared in ROS manifest files.
40 """
41
42 import sys
43 import os
44
45 import roslib.manifest
46 import roslib.packages
47
49 """
50 @return: name of package to get manifest for
51 @rtype: str
52 @raise InvalidROSPkgException: if required is True and package cannot be located
53 """
54 return roslib.manifest.manifest_file(package_name, required=True)
55
56
57 _bootstrapped = []
58
60 """
61 Update the Python sys.path with package's dependencies
62 @param package_name: name of the package that load_manifest() is being called from.
63 @type package_name: str
64 @param bootstrap_version: (keyword argument) do not use. Soon to be deprecated
65 @type bootstrap_version: str
66 """
67 if package_name in _bootstrapped:
68 return
69 sys.path = _generate_python_path(package_name, [], os.environ) + sys.path
70
72 """
73 Added paths for package to paths
74 @param manifest_: package manifest
75 @type manifest_: Manifest
76 @param pkg_dir: package's filesystem directory path
77 @type pkg_dir: str
78 @param paths: list of paths
79 @type paths: [str]
80 """
81 exports = manifest_.get_export('python','path')
82 if exports:
83 for export in exports:
84 if ':' in export:
85 export = export.split(':')
86 else:
87 export = [export]
88 for e in export:
89 paths.append(e.replace('${prefix}', pkg_dir))
90 else:
91 dirs = [os.path.join(pkg_dir, d) for d in ['src', 'lib']]
92 paths.extend(filter(os.path.isdir, dirs))
93
95 """
96 Recursive subroutine for building dependency list and python path
97 @param manifest_file: manifest to parse for additional dependencies
98 @param depends: current dependency set. Will be modified
99 @return: list of directory paths to add to python path in order to include
100 package and dependencies described in manifest file.
101 @raise InvalidROSPkgException: if an error occurs while attempting to load package or dependencies
102 """
103 if pkg in _bootstrapped:
104 return []
105 manifest_file = roslib.manifest.manifest_file(pkg, True, env)
106 if not manifest_file:
107 raise roslib.packages.InvalidROSPkgException("cannot locate package [%s]"%pkg)
108 _bootstrapped.append(pkg)
109
110 pkg_dir = os.path.dirname(os.path.abspath(manifest_file))
111 depends.append(pkg)
112 m = roslib.manifest.parse_file(manifest_file)
113
114 paths = []
115 _append_package_paths(m, paths, pkg_dir)
116
117 try:
118 for d in m.depends:
119 if d.package in depends:
120 continue
121 try:
122 paths.extend(_generate_python_path(d.package, depends, env))
123 except roslib.packages.InvalidROSPkgException, e:
124
125 raise roslib.packages.InvalidROSPkgException("While loading package '%s': %s"%(d.package, str(e)))
126 except:
127 import traceback
128 raise roslib.packages.InvalidROSPkgException("While loading package '%s': cannot load dependency '%s'\nLower level error was %s"%(pkg, d.package, traceback.format_exc()))
129 except:
130 if pkg in _bootstrapped:
131 _bootstrapped.remove(pkg)
132 raise
133 return paths
134