diff --git a/docs/conf.py b/docs/conf.py index d234b3f..0d47d51 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,7 +10,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +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 @@ -44,20 +45,13 @@ copyright = '2015, Carl Meyer' parent_dir = os.path.dirname(os.path.dirname(__file__)) -def get_version(): - with open(os.path.join(parent_dir, 'model_utils', '__init__.py')) as f: - for line in f: - if line.startswith('__version__ ='): - return line.split('=')[1].strip().strip('"\'') - # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # -# The full version, including alpha/beta/rc tags. -release = get_version() -# The short X.Y version. -version = release +release = get_distribution('django-model-utils').version +# for example take major/minor +version = '.'.join(release.split('.')[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/model_utils/__init__.py b/model_utils/__init__.py index 0275e64..ff00ad6 100644 --- a/model_utils/__init__.py +++ b/model_utils/__init__.py @@ -1,4 +1,10 @@ +from pkg_resources import get_distribution, DistributionNotFound + from .choices import Choices # noqa:F401 from .tracker import FieldTracker, ModelTracker # noqa:F401 -__version__ = '4.0.1' +try: + __version__ = get_distribution("django-model-utils").version +except DistributionNotFound: + # package is not installed + pass diff --git a/setup.py b/setup.py index 313a33c..8ecaa16 100644 --- a/setup.py +++ b/setup.py @@ -15,23 +15,18 @@ HERE = os.path.abspath(os.path.dirname(__file__)) long_description = "\n\n".join(long_desc(HERE)) -def get_version(root_path): - with open(os.path.join(root_path, 'model_utils', '__init__.py')) as f: - for line in f: - if line.startswith('__version__ ='): - return line.split('=')[1].strip().strip('"\'') - - setup( name='django-model-utils', - version=get_version(HERE), + use_scm_version={"version_scheme": "post-release"}, + setup_requires=["setuptools_scm"], license="BSD", description='Django model mixins and utilities', long_description=long_description, + long_description_content_type='text/x-rst', author='Carl Meyer', author_email='carl@oddbird.net', maintainer='JazzBand', - url='https://github.com/jazzband/django-model-utils/', + url='https://github.com/jazzband/django-model-utils', packages=find_packages(exclude=['tests*']), install_requires=['Django>=2.0.1'], classifiers=[