summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorMaik Hoepfel <m@maikhoepfel.de>2014-01-24 13:08:46 +0000
committerMaik Hoepfel <m@maikhoepfel.de>2014-01-24 13:08:46 +0000
commit0e3eeab29c7ba3afc4ec77233dd7d4ab1c6705fa (patch)
treecdbc17e9fd38561ff45c551cacc7e1b378827977 /setup.py
parentc961dadf6eaba93a9cdadc569c697828e9afe345 (diff)
downloaddjango-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.py21
1 files 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