manifest.py
Go to the documentation of this file.
1 from ros_introspection.package_xml import count_trailing_spaces, get_ordering_index, replace_package_set
2 
3 from .util import get_config, get_ignore_data, roscompile
4 
5 
6 @roscompile
8  build_depends = package.get_build_dependencies()
9  run_depends = package.get_run_dependencies()
10  test_depends = package.get_test_dependencies()
11  package.manifest.add_packages(build_depends, run_depends, test_depends)
12 
13  if package.generators:
14  md = package.get_dependencies_from_msgs()
15  package.manifest.add_packages(md, md)
16 
17  if package.manifest.format == 1:
18  pairs = [('build_depend', 'message_generation'),
19  ('run_depend', 'message_runtime')]
20  else:
21  pairs = [('build_depend', 'message_generation'),
22  ('build_export_depend', 'message_runtime'),
23  ('exec_depend', 'message_runtime')]
24  package.manifest.remove_dependencies('depend', ['message_generation', 'message_runtime'])
25  for tag, msg_pkg in pairs:
26  existing = package.manifest.get_packages_by_tag(tag)
27  if msg_pkg not in existing:
28  package.manifest.insert_new_packages(tag, [msg_pkg])
29 
30 
31 @roscompile
33  run_depends = package.source_code.get_external_python_dependencies()
34  package.manifest.add_packages(set(), run_depends, prefer_depend_tag=False)
35 
36 
38  for child in node.childNodes:
39  if child.nodeType == child.ELEMENT_NODE:
40  return True
41  return False
42 
43 
44 @roscompile
46  exports = package.manifest.root.getElementsByTagName('export')
47  if len(exports) == 0:
48  return False
49  for export in exports:
50  if not has_element_child(export):
51  package.manifest.remove_element(export)
52  return True
53 
54 
55 @roscompile
56 def greedy_depend_tag(package):
57  if package.manifest.format == 1:
58  return
59  replace_package_set(package.manifest, ['build_depend', 'build_export_depend', 'exec_depend'], 'depend')
60 
61 
62 def enforce_tabbing_helper(manifest, node, tabs=1):
63  ideal_length = manifest.std_tab * tabs
64  prev_was_node = True
65  insert_before_list = []
66  if not node:
67  return
68  changed = False
69  for c in node.childNodes:
70  if c.nodeType == c.TEXT_NODE:
71  prev_was_node = False
72  if c == node.childNodes[-1]:
73  continue
74  spaces = count_trailing_spaces(c.data)
75  if spaces > ideal_length:
76  c.data = c.data[: ideal_length - spaces]
77  changed = True
78  elif spaces < ideal_length:
79  c.data = c.data + ' ' * (ideal_length - spaces)
80  changed = True
81  if '\n' not in c.data:
82  c.data = '\n' + c.data
83  changed = True
84  elif prev_was_node:
85  changed = True
86  insert_before_list.append(c)
87  else:
88  prev_was_node = True
89 
90  for c in insert_before_list:
91  node.insertBefore(manifest.get_tab_element(tabs), c)
92 
93  manifest.changed = manifest.changed or changed
94 
95  if len(node.childNodes) == 0:
96  return
97  last = node.childNodes[-1]
98  if last.nodeType != last.TEXT_NODE:
99  node.appendChild(manifest.get_tab_element(tabs - 1))
100  manifest.changed = True
101 
102 
103 @roscompile
105  enforce_tabbing_helper(package.manifest, package.manifest.root)
106 
107 
108 def get_sort_key(node, alphabetize_depends=True):
109  if node:
110  name = node.nodeName
111  else:
112  name = None
113 
114  index = get_ordering_index(name)
115 
116  if not alphabetize_depends:
117  return index
118  if name and 'depend' in name:
119  return index, node.firstChild.data
120  else:
121  return index, None
122 
123 
124 def get_chunks(children):
125  """Given the children, group the elements into tuples.
126 
127  Tuple format: (an element node, [(some number of text nodes), that element node again])
128  """
129  chunks = []
130  current = []
131  for child_node in children:
132  current.append(child_node)
133  if child_node.nodeType == child_node.ELEMENT_NODE:
134  chunks.append((child_node, current))
135  current = []
136  if len(current) > 0:
137  chunks.append((None, current))
138  return chunks
139 
140 
141 @roscompile
142 def enforce_manifest_ordering(package, alphabetize=True):
143  root = package.manifest.root
144  chunks = get_chunks(root.childNodes)
145 
146  new_children = []
147 
148  for a, b in sorted(chunks, key=lambda d: get_sort_key(d[0], alphabetize)):
149  new_children += b
150 
151  if root.childNodes != new_children:
152  package.manifest.changed = True
153  root.childNodes = new_children
154 
155 
157  new_children = []
158  changed = False
159 
160  for child in node.childNodes:
161  if child.nodeType == child.TEXT_NODE and len(new_children) and new_children[-1].nodeType == child.TEXT_NODE:
162  changed = True
163  new_children[-1].data += child.data
164  elif child.nodeType == child.TEXT_NODE and child.data == '':
165  continue
166  else:
167  new_children.append(child)
168 
169  node.childNodes = new_children
170  return changed
171 
172 
173 def replace_text_node_contents(node, ignorables):
174  changed = False
175  removable = []
176  for i, c in enumerate(node.childNodes):
177  if c.nodeType == c.TEXT_NODE:
178  continue
179  elif c.nodeType == c.COMMENT_NODE:
180  short = c.data.strip()
181  if short in ignorables:
182  removable.append(i)
183  changed = True
184  continue
185  else:
186  changed = replace_text_node_contents(c, ignorables) or changed
187  for node_index in reversed(removable): # backwards not to affect earlier indices
188  if node_index > 0:
189  before = node.childNodes[node_index - 1]
190  if before.nodeType == c.TEXT_NODE:
191  trailing = count_trailing_spaces(before.data)
192  before.data = before.data[:-trailing]
193 
194  if node_index < len(node.childNodes) - 1:
195  after = node.childNodes[node_index + 1]
196  if after.nodeType == c.TEXT_NODE:
197  while len(after.data) and after.data[0] == ' ':
198  after.data = after.data[1:]
199  if len(after.data) and after.data[0] == '\n':
200  after.data = after.data[1:]
201 
202  node.childNodes.remove(node.childNodes[node_index])
203  changed = cleanup_text_elements(node) or changed
204  return changed
205 
206 
207 @roscompile
209  ignorables = get_ignore_data('package', {'package': package.name}, add_newline=False)
210  changed = replace_text_node_contents(package.manifest.root, ignorables)
211  if changed:
212  package.manifest.changed = changed
214 
215 
217  changed = False
218  for child in node.childNodes:
219  if child.nodeType == child.TEXT_NODE:
220  while '\n\n\n' in child.data:
221  child.data = child.data.replace('\n\n\n', '\n\n')
222  changed = True
223  else:
224  changed = remove_empty_lines_helper(child) or changed
225  return changed
226 
227 
228 @roscompile
230  if remove_empty_lines_helper(package.manifest.root):
231  package.manifest.changed = True
232 
233 
234 @roscompile
235 def update_people(package, config=None):
236  if config is None:
237  config = get_config()
238  for d in config.get('replace_rules', []):
239  package.manifest.update_people(d['to']['name'], d['to']['email'],
240  d['from'].get('name', None), d['from'].get('email', None))
241 
242 
243 @roscompile
244 def update_license(package, config=None):
245  if config is None:
246  config = get_config()
247  if 'default_license' not in config or package.manifest.get_license() != 'TODO':
248  return
249 
250  package.manifest.set_license(config['default_license'])
def update_people(package, config=None)
Definition: manifest.py:235
def enforce_manifest_tabbing(package)
Definition: manifest.py:104
def remove_empty_manifest_lines(package)
Definition: manifest.py:229
def get_ignore_data(name, variables=None, add_newline=True)
Definition: util.py:35
def enforce_manifest_ordering(package, alphabetize=True)
Definition: manifest.py:142
def cleanup_text_elements(node)
Definition: manifest.py:156
def check_python_dependencies(package)
Definition: manifest.py:32
def update_license(package, config=None)
Definition: manifest.py:244
def get_chunks(children)
Definition: manifest.py:124
def replace_text_node_contents(node, ignorables)
Definition: manifest.py:173
def enforce_tabbing_helper(manifest, node, tabs=1)
Definition: manifest.py:62
def remove_boilerplate_manifest_comments(package)
Definition: manifest.py:208
def has_element_child(node)
Definition: manifest.py:37
def remove_empty_export_tag(package)
Definition: manifest.py:45
def greedy_depend_tag(package)
Definition: manifest.py:56
def check_manifest_dependencies(package)
Definition: manifest.py:7
def remove_empty_lines_helper(node)
Definition: manifest.py:216
def get_sort_key(node, alphabetize_depends=True)
Definition: manifest.py:108
def get_config()
Definition: util.py:49


roscompile
Author(s):
autogenerated on Wed Mar 3 2021 03:56:01