From 0e3eeab29c7ba3afc4ec77233dd7d4ab1c6705fa Mon Sep 17 00:00:00 2001 From: Maik Hoepfel Date: Fri, 24 Jan 2014 13:08:46 +0000 Subject: [PATCH] Fix for extracting version number in Python 3 setuptools chokes when installing a tarball of django-compressor's HEAD of develop under Python 3. The flaw lies with extracting the version number. As suggested by @jezdez, this commit merely ports the version extracting code from django-configurations. --- setup.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index b8e7d66..bb768e1 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,20 @@ from __future__ import print_function +import ast import os -import re import sys import codecs from fnmatch import fnmatchcase from distutils.util import convert_path from setuptools import setup, find_packages +class VersionFinder(ast.NodeVisitor): + def __init__(self): + self.version = None + + def visit_Assign(self, node): + if node.targets[0].id == '__version__': + self.version = node.value.s + def read(*parts): filename = os.path.join(os.path.dirname(__file__), *parts) @@ -14,13 +22,10 @@ def read(*parts): return fp.read() -def find_version(*file_paths): - version_file = read(*file_paths) - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", - version_file, re.M) - if version_match: - return version_match.group(1) - raise RuntimeError("Unable to find version string.") +def find_version(*parts): + finder = VersionFinder() + finder.visit(ast.parse(read(*parts))) + return finder.version # Provided as an attribute, so you can append to these instead