setup_py.py
Go to the documentation of this file.
1 import os
2 import re
3 
4 VAR_PATTERN = re.compile('\*\*([\w_]+)\)')
5 EQ_PATTERN = re.compile('([\w_]+)\s*=([^,]+)')
6 
7 EXEC_TEMPLATE = """
8  scripts=%s,"""
9 
10 TEMPLATE = """#!/usr/bin/env python
11 
12 from distutils.core import setup
13 from catkin_pkg.python_setup import generate_distutils_setup
14 
15 %(var)s = generate_distutils_setup(
16  packages=['%(name)s'],%(exec)s
17  package_dir={'': 'src'}
18 )
19 
20 setup(**%(var)s)
21 """
22 
23 
24 class SetupPy:
25  def __init__(self, pkg_name, file_path):
26  self.pkg_name = pkg_name
27  self.file_path = file_path
28  self.var = 'package_info'
29  self.execs = []
30 
31  if os.path.exists(self.file_path):
32  self.changed = False
33  original = open(self.file_path, 'r').read()
34 
35  # Determine variable name
36  m = VAR_PATTERN.search(original)
37  if m:
38  self.var = m.group(1)
39 
40  # Parse generate_distutils_setup
41  key_s = 'generate_distutils_setup'
42  if key_s not in original:
43  return
44  i = original.index(key_s) + len(key_s)
45  p_i = original.index('(', i)
46  ep_i = original.index(')', p_i)
47  body = original[p_i + 1:ep_i]
48  for var_name, value in EQ_PATTERN.findall(body):
49  if var_name == 'scripts':
50  self.execs = eval(value)
51  else:
52  self.changed = True
53 
54  def write(self):
55  if not self.changed:
56  return
57  with open(self.file_path, 'w') as f:
58  f.write(str(self))
59 
60  def __repr__(self):
61  if len(self.execs) > 0:
62  execs = EXEC_TEMPLATE % repr(self.execs)
63  else:
64  execs = ''
65  return TEMPLATE % {'name': self.pkg_name, 'var': self.var, 'exec': execs}
def __init__(self, pkg_name, file_path)
Definition: setup_py.py:25


ros_introspection
Author(s):
autogenerated on Wed Jun 19 2019 19:56:52