I need to write a python script that read and parse setup python file. setup 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 parse the setup file and "see" what kind of variables were defined and what kind of function calls. since the setup file in written in python, I was thinking that the easiest thing would be to dynamically import the setup file (dynamically because setup file path is the input for main).
the problem is that import fails since myfucn()
, called in setup.py
, is not defined.
is there a way for me to intercept the 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 for extracting the data in the setup file, I really don't want to read it line by line.
Thanks!