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.
This commit is contained in:
21
setup.py
21
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
|
||||
|
Reference in New Issue
Block a user