diff --git a/.gitignore b/.gitignore index 283c869..8c950b9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ htmlcov/ *.pyc dist/ tests/docs/_build/ +.eggs/ diff --git a/configurations/__init__.py b/configurations/__init__.py index 069756e..bd06566 100644 --- a/configurations/__init__.py +++ b/configurations/__init__.py @@ -1,8 +1,8 @@ -# flake8: noqa -from .base import Configuration -from .decorators import pristinemethod +from .base import Configuration # noqa +from .decorators import pristinemethod # noqa +from .version import __version__ # noqa + -__version__ = '2.1' __all__ = ['Configuration', 'pristinemethod'] diff --git a/configurations/importer.py b/configurations/importer.py index 38bddbf..4997380 100644 --- a/configurations/importer.py +++ b/configurations/importer.py @@ -128,8 +128,8 @@ class ConfigurationImporter(object): and os.environ.get('RUN_MAIN') == 'true'): message = ("django-configurations version {0}, using " - "configuration '{1}'".format(__version__, - self.name)) + "configuration {1}".format(__version__ or "", + self.name)) self.logger.debug(stylize(message)) def find_module(self, fullname, path=None): diff --git a/configurations/version.py b/configurations/version.py new file mode 100644 index 0000000..10f8675 --- /dev/null +++ b/configurations/version.py @@ -0,0 +1,7 @@ +from pkg_resources import get_distribution, DistributionNotFound + +try: + __version__ = get_distribution(__name__).version +except DistributionNotFound: + # package is not installed + __version__ = None diff --git a/docs/changes.rst b/docs/changes.rst index 0a0ca8e..2c983e3 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -18,7 +18,8 @@ v2.2 (2019-12-03) - Replace ``django.utils.six`` with ``six`` to support Django >= 3. -- Start using tox-travis for simplified test harness management. +- Start using tox-travis and setuptools-scm for simplified test harness + and release management. v2.1 (2018-08-16) ^^^^^^^^^^^^^^^^^ diff --git a/docs/conf.py b/docs/conf.py index 03bebca..5e7bd64 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,6 +14,8 @@ import sys import os +from pkg_resources import get_distribution + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -48,14 +50,10 @@ copyright = u'2012-2014, Jannis Leidel and other contributors' # |version| and |release|, also used in various other places throughout the # built documents. # -try: - from configurations import __version__ - # The short X.Y version. - version = '.'.join(__version__.split('.')[:2]) - # The full version, including alpha/beta/rc tags. - release = __version__ -except ImportError: - version = release = 'dev' +# The full version, including alpha/beta/rc tags. +release = get_distribution("django-configurations").version +# The short X.Y version. +version = ".".join(release.split(".")[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.cfg b/setup.cfg index 28c24e9..51a5b97 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,5 +9,5 @@ parallel = 1 include = configurations/*,tests/* [flake8] -exclude = .tox,docs/* +exclude = .tox,docs/*,.eggs ignore = E501,E127,E128,E124,W503 diff --git a/setup.py b/setup.py index 515d5fc..aba91f2 100644 --- a/setup.py +++ b/setup.py @@ -1,34 +1,19 @@ from __future__ import print_function -import ast import os 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(*parts): - finder = VersionFinder() - finder.visit(ast.parse(read(*parts))) - return finder.version - - setup( name="django-configurations", - version=find_version("configurations", "__init__.py"), + use_scm_version={"version_scheme": "post-release", "local_scheme": "dirty-tag"}, + setup_requires=["setuptools_scm"], url='https://django-configurations.readthedocs.io/', license='BSD', description="A helper for organizing Django settings.",