setup_py.py
Go to the documentation of this file.
1 import os
2 import re
3 
4 VAR_PATTERN = re.compile(r'\*\*([\w_]+)\)')
5 EQ_PATTERN = re.compile(r'([\w_]+)\s*=([^,]+)')
6 
7 EXEC_TEMPLATE = """
8  scripts=%s,"""
9 
10 TEMPLATE = """#!/usr/bin/env python
11 
12 from %(import_pkg)s 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 Setuptools or Distutils
36  self.noetic = 'distutils.core' not in original
37 
38  # Determine variable name
39  m = VAR_PATTERN.search(original)
40  if m:
41  self.var = m.group(1)
42 
43  # Parse generate_distutils_setup
44  key_s = 'generate_distutils_setup'
45  if key_s not in original:
46  return
47  i = original.index(key_s) + len(key_s)
48  p_i = original.index('(', i)
49  ep_i = original.index(')', p_i)
50  body = original[p_i + 1:ep_i]
51  for var_name, value in EQ_PATTERN.findall(body):
52  if var_name == 'scripts':
53  self.execs = eval(value)
54  else:
55  self.changed = True
56  self.noetic = False
57 
58  def write(self):
59  if not self.changed:
60  return
61  with open(self.file_path, 'w') as f:
62  f.write(str(self))
63 
64  def __repr__(self):
65  if len(self.execs) > 0:
66  execs = EXEC_TEMPLATE % repr(self.execs)
67  else:
68  execs = ''
69 
70  params = {'name': self.pkg_name, 'var': self.var, 'exec': execs}
71  if self.noetic:
72  params['import_pkg'] = 'setuptools'
73  else:
74  params['import_pkg'] = 'distutils.core'
75  return TEMPLATE % params
def __init__(self, pkg_name, file_path)
Definition: setup_py.py:25


ros_introspection
Author(s):
autogenerated on Wed Mar 3 2021 03:56:00