refactor python source gen