Refactor setup.py to remove duplication