From a15b8c3959f663aa1f9341a95223522c55265f1c Mon Sep 17 00:00:00 2001 From: Mohammad Ahtasham ul Hassan Date: Tue, 9 Nov 2021 15:30:51 +0500 Subject: [PATCH] build: standardize version number placement --- django_sites_extensions/__init__.py | 1 + setup.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/django_sites_extensions/__init__.py b/django_sites_extensions/__init__.py index c3bc936..eb48c4a 100644 --- a/django_sites_extensions/__init__.py +++ b/django_sites_extensions/__init__.py @@ -1,2 +1,3 @@ """ django_sites_extensions main module """ default_app_config = 'django_sites_extensions.apps.DjangoSitesExtensionsConfig' # pragma: no cover +__version__ = '3.1.0' diff --git a/setup.py b/setup.py index 7f65332..39db2d0 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,8 @@ Setup for edx-django-sites-extensions package """ import io +import os +import re from setuptools import setup @@ -32,9 +34,27 @@ def is_requirement(line): """ return line and not line.startswith(('-r', '#', '-e', 'git+', '-c')) + +def get_version(*file_paths): + """ + Extract the version string from the file at the given relative path fragments. + """ + filename = os.path.join(os.path.dirname(__file__), *file_paths) + with open(filename, encoding='utf-8') as opened_file: + version_file = opened_file.read() + 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.') + + +VERSION = get_version("django_sites_extensions", "__init__.py") + + setup( name='edx-django-sites-extensions', - version='3.1.0', + version=VERSION, description='Custom extensions for the Django sites framework', long_description=long_description, classifiers=[