File tree Expand file tree Collapse file tree 3 files changed +9
-20
lines changed
Expand file tree Collapse file tree 3 files changed +9
-20
lines changed Original file line number Diff line number Diff line change 1818from subprocess import check_call
1919
2020from django import setup as django_setup
21-
22-
23- def get_version (* file_paths ):
24- """
25- Extract the version string from the file.
26-
27- Input:
28- - file_paths: relative path fragments to file with
29- version string
30- """
31- filename = os .path .join (os .path .dirname (__file__ ), * file_paths )
32- version_file = open (filename , encoding = "utf8" ).read ()
33- version_match = re .search (r"^__version__ = ['\"]([^'\"]*)['\"]" , version_file , re .M )
34- if version_match :
35- return version_match .group (1 )
36- raise RuntimeError ('Unable to find version string.' )
21+ from importlib .metadata import version as get_version
3722
3823
3924REPO_ROOT = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
4025sys .path .append (REPO_ROOT )
4126
42- VERSION = get_version ('../sample_plugin' , '__init__.py ' )
27+ VERSION = get_version ('openedx-sample-plugin ' )
4328# Configure Django for autodoc usage
4429os .environ ['DJANGO_SETTINGS_MODULE' ] = 'test_settings'
4530django_setup ()
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ name = "openedx-sample-plugin"
77description = " A sample backend plugin for the Open edX Platform"
88requires-python = " >=3.11"
99license =" Apache-2.0"
10+ version = " 0.1.0"
1011authors = [
1112 {
name =
" Open edX Project" ,
email =
" [email protected] " },
1213]
@@ -24,7 +25,7 @@ keywords= [
2425 " edx" ,
2526]
2627
27- dynamic = [" version " , " readme" , " dependencies" ]
28+ dynamic = [" readme" , " dependencies" ]
2829
2930[project .entry-points ."lms .djangoapp" ]
3031sample_plugin = " sample_plugin.apps:SamplePluginConfig"
@@ -37,7 +38,6 @@ Homepage = "https://openedx.org/openedx/sample-plugin"
3738Repository = " https://openedx.org/openedx/sample-plugin"
3839
3940[tool .setuptools .dynamic ]
40- version = {attr = " sample_plugin.__version__" }
4141readme = {file = [" README.rst" , " CHANGELOG.rst" ]}
4242dependencies = {file = " requirements/base.in" }
4343
Original file line number Diff line number Diff line change 22A sample backend plugin for the Open edX Platform.
33"""
44
5- __version__ = "0.1.0"
5+ from importlib .metadata import version as get_version
6+
7+ # The name of the package is `openedx-sample-plugin` but __package__ is `sample_plugin` so we hardcode the name of the
8+ # package here so that the version fetching works correctly. A lot of examples will show using `__package__`.
9+ __version__ = get_version ('openedx-sample-plugin' )
You can’t perform that action at this time.
0 commit comments