diff --git a/configurations/__init__.py b/configurations/__init__.py index 161f327..aa598da 100644 --- a/configurations/__init__.py +++ b/configurations/__init__.py @@ -2,7 +2,7 @@ from .base import Settings, Configuration from .decorators import pristinemethod -__version__ = '0.6' +__version__ = '0.7' __all__ = ['Configuration', 'pristinemethod', 'Settings'] diff --git a/docs/index.rst b/docs/index.rst index 7a1fc2c..3a85d8a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,7 +3,7 @@ Project templates ^^^^^^^^^^^^^^^^^ -Don't miss the Django :ref:`project templates pre-configured with +Don't miss the Django :ref:`project templates pre-configured with django-configurations` to simplify getting started with new Django projects. diff --git a/setup.py b/setup.py index e4e304f..909b3ae 100644 --- a/setup.py +++ b/setup.py @@ -1,23 +1,29 @@ from __future__ import print_function +import ast import os -import re import codecs from setuptools import setup +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) with codecs.open(filename, encoding='utf-8') as fp: 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 setup(