From 72f064959cbf33540e1d11f2fabeea0fb197661a Mon Sep 17 00:00:00 2001
From: Mohammad Ahtasham ul Hassan <ahthassan74@gmail.com>
Date: Wed, 17 Nov 2021 15:43:16 +0500
Subject: [PATCH] build: standardize version number placement

---
 lti_consumer/__init__.py |  2 ++
 setup.py                 | 20 +++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lti_consumer/__init__.py b/lti_consumer/__init__.py
index fede433..8fc74ab 100644
--- a/lti_consumer/__init__.py
+++ b/lti_consumer/__init__.py
@@ -3,3 +3,5 @@ Runtime will load the XBlock class from here.
 """
 from .lti_xblock import LtiConsumerXBlock
 from .apps import LTIConsumerApp
+
+__version__ = '3.1.0'
diff --git a/setup.py b/setup.py
index 15fd1d4..f53d7e2 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,7 @@
 """Setup for lti_consumer XBlock."""
 
 import os
+import re
 
 from setuptools import setup, find_packages
 
@@ -47,9 +48,26 @@ def is_requirement(line):
 with open('README.rst') as _f:
     long_description = _f.read()
 
+
+def get_version(file_path):
+    """
+    Extract the version string from the file at the given relative path fragments.
+    """
+    filename = os.path.join(os.path.dirname(__file__), file_path)
+    with open(filename, encoding='utf-8') as opened_file:
+        version_file = opened_file.read()
+        version_match = re.search(r"(?m)^__version__ = ['\"]([^'\"]+)['\"]", version_file)
+    if version_match:
+        return version_match.group(1)
+    raise RuntimeError('Unable to find version string.')
+
+
+VERSION = get_version("lti_consumer/__init__.py")
+
+
 setup(
     name='lti-consumer-xblock',
-    version='3.1.0',
+    version=VERSION,
     author='Open edX project',
     author_email='oscm@edx.org',
     description='This XBlock implements the consumer side of the LTI specification.',
-- 
GitLab