#!/usr/bin/python

# TODO FIXME
# WIP

import os
import setuptools
# Nullify "setup()" method so I can load seup.py file without loading it
setuptools.setup = lambda *a, **k: 0

def get_upstream_root_path():
    file_abs_folder = os.path.abspath(os.path.dirname(__file__))
    return os.path.abspath(os.path.join(file_abs_folder, os.pardir, 'src'))

def find_setup_py_files(path):
    matches = []
    for root, dirnames, filenames in os.walk(path):
        if 'setup.py' in filenames:
            matches.append(os.path.join(root, 'setup.py'))
    return matches

def read_setup_py(path):
    print('#################')
    print(path)
    with open(path) as fh:
        content = fh.read()
        ns = {}
        exec(compile(content, '__string__', 'exec'), {}, ns)
        print(ns)


if __name__ == '__main__':
    src_root = get_upstream_root_path()
    setup_py_files = find_setup_py_files(src_root)

    for setup_py in setup_py_files:
        read_setup_py(setup_py)
