setup_py.py
Go to the documentation of this file.
00001 import os
00002 import re
00003 
00004 VAR_PATTERN = re.compile('\*\*([\w_]+)\)')
00005 EQ_PATTERN = re.compile('([\w_]+)\s*=([^,]+)')
00006 
00007 EXEC_TEMPLATE = """
00008     scripts=%s,"""
00009 
00010 TEMPLATE = """#!/usr/bin/env python
00011 
00012 from distutils.core import setup
00013 from catkin_pkg.python_setup import generate_distutils_setup
00014 
00015 %(var)s = generate_distutils_setup(
00016     packages=['%(name)s'],%(exec)s
00017     package_dir={'': 'src'}
00018 )
00019 
00020 setup(**%(var)s)
00021 """
00022 
00023 
00024 class SetupPy:
00025     def __init__(self, pkg_name, file_path):
00026         self.pkg_name = pkg_name
00027         self.file_path = file_path
00028         self.var = 'package_info'
00029         self.execs = []
00030 
00031         if os.path.exists(self.file_path):
00032             self.changed = False
00033             original = open(self.file_path, 'r').read()
00034 
00035             # Determine variable name
00036             m = VAR_PATTERN.search(original)
00037             if m:
00038                 self.var = m.group(1)
00039 
00040             # Parse generate_distutils_setup
00041             key_s = 'generate_distutils_setup'
00042             if key_s not in original:
00043                 return
00044             i = original.index(key_s) + len(key_s)
00045             p_i = original.index('(', i)
00046             ep_i = original.index(')', p_i)
00047             body = original[p_i + 1:ep_i]
00048             for var_name, value in EQ_PATTERN.findall(body):
00049                 if var_name == 'scripts':
00050                     self.execs = eval(value)
00051         else:
00052             self.changed = True
00053 
00054     def write(self):
00055         if not self.changed:
00056             return
00057         with open(self.file_path, 'w') as f:
00058             f.write(str(self))
00059 
00060     def __repr__(self):
00061         if len(self.execs) > 0:
00062             execs = EXEC_TEMPLATE % repr(self.execs)
00063         else:
00064             execs = ''
00065         return TEMPLATE % {'name': self.pkg_name, 'var': self.var, 'exec': execs}


ros_introspection
Author(s):
autogenerated on Wed Jun 19 2019 19:21:34