Skip to content
Snippets Groups Projects
parse_setup.py 1.05 KiB
Newer Older
import setuptools

def get_data(field, data):
    """
    Get data from field if it exists.
    :return: None if not found. Datum of field if found.
    """
    datum = None
    try:
        datum = data[field]
    except KeyError as e:
        pass
    return datum

data = {}
def my_setup(*args, **kwargs):
    """
    A replacement for setuptools.setup().
    """
    fields = [
        'name',
        'version',
        'description',
        'license',
        'install_requires',
        'tests_require',
        'entry_points'
    ]

    for field in fields:
        data[field] = get_data(field, kwargs)

def main():
    # Author of these shenanigans: Daniel Lyons (but you already knew that)
    # Monkey-patch over the setuptools setup() function to do our function instead
    setuptools.setup = my_setup
    # Load the setup.py file
    import setup
    # Instead of exiting, we now have populated our global variable, without doing any parsing
    for field, datum in data.items():
        print('{}: {}'.format(field, datum))

if __name__ == "__main__":
    main()