diff options
| author | Maik Hoepfel <m@maikhoepfel.de> | 2014-01-24 13:08:46 +0000 |
|---|---|---|
| committer | Maik Hoepfel <m@maikhoepfel.de> | 2014-01-24 13:08:46 +0000 |
| commit | 0e3eeab29c7ba3afc4ec77233dd7d4ab1c6705fa (patch) | |
| tree | cdbc17e9fd38561ff45c551cacc7e1b378827977 /setup.py | |
| parent | c961dadf6eaba93a9cdadc569c697828e9afe345 (diff) | |
| download | django-compressor-0e3eeab29c7ba3afc4ec77233dd7d4ab1c6705fa.tar.gz | |
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.
Diffstat (limited to 'setup.py')
| -rw-r--r-- | setup.py | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -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 |
