I need to write a python script that reads and parses a python file for customization. settings contain some variables and function calls.
Example:
setup.py x = 5 mylist [ 1, 2, 3] myfunc(4) myfunc(5) myfunc(30) main.py . parse_setup('setup.py') .
I would like to analyze the installation file and “see” which variables were defined and which function calls. since the installation file is written in python, I thought that the easiest way would be to dynamically import the installation file (dynamically, because the path to the installation file is the input for the main one).
the problem is that the import fails because myfucn() called in setup.py is not defined.
is there any way to intercept myfunc() calls in setup.py and execute my own function defined in main.py ?
What if the function I want to execute is a member function?
can anyone think of a better way to extract the data in the installation file, I really do not want to read it in turn.
Thanks!
source share