From d42db02de0519fade43406cf887cc16d37a1032b Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Mon, 7 Jul 2014 14:06:45 -0400 Subject: Parse version string without importing source code It's probably better to execute as little code as possible from setup.py, so this approach seems cleaner to me. --- setup.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 6845d9e..bde020f 100755 --- a/setup.py +++ b/setup.py @@ -1,16 +1,14 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +import re +import ast +from setuptools import setup -import os -import sys -try: - from setuptools import setup -except ImportError: - from distutils.core import setup +_version_re = re.compile(r'__version__\s+=\s+(.*)') -from dotfiles.core import __version__ +with open('dotfiles/core.py', 'rb') as f: + version = str(ast.literal_eval(_version_re.search( + f.read().decode('utf-8')).group(1))) setup(name='dotfiles', version=__version__, -- cgit v1.2.3