From af469a5a55c3a2247c1b27639df24e05b6ca6349 Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Thu, 26 May 2016 18:25:46 -0700 Subject: [PATCH 1/2] Add Version to CLR module Ideally we would implement `__version__` as a property, but this requires `ModuleFunctionAttribute` to work. Since version is being implemented as a function, using `Version()` instead since __version__ is expected to be a property. --- src/runtime/moduleobject.cs | 6 ++++++ src/tests/test_module.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/runtime/moduleobject.cs b/src/runtime/moduleobject.cs index 87e3ed2f1..7e9c09aa5 100644 --- a/src/runtime/moduleobject.cs +++ b/src/runtime/moduleobject.cs @@ -446,5 +446,11 @@ public static int _AtExit() { return Runtime.AtExit(); } + + [ModuleFunctionAttribute()] + public static string Version() + { + return "2.2.0"; + } } } \ No newline at end of file diff --git a/src/tests/test_module.py b/src/tests/test_module.py index a23f37d90..9862bec99 100644 --- a/src/tests/test_module.py +++ b/src/tests/test_module.py @@ -41,6 +41,10 @@ def test000importClr(self): import clr self.assertTrue(self.isCLRRootModule(clr)) + def testVersionClr(self): + import clr + self.assertTrue(clr.Version() >= "2.2.0") + def testPreloadVar(self): import clr self.assertTrue(clr.getPreload() is False, clr.getPreload()) From f74898c598e57470c6ce94131cabecc7fd5683f1 Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Sat, 7 Jan 2017 14:46:03 -0700 Subject: [PATCH 2/2] Implement __version__ on clr module --- src/runtime/moduleobject.cs | 6 ------ src/runtime/pythonengine.cs | 2 +- src/runtime/resources/clr.py | 4 +++- src/tests/test_module.py | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/runtime/moduleobject.cs b/src/runtime/moduleobject.cs index 7e9c09aa5..87e3ed2f1 100644 --- a/src/runtime/moduleobject.cs +++ b/src/runtime/moduleobject.cs @@ -446,11 +446,5 @@ public static int _AtExit() { return Runtime.AtExit(); } - - [ModuleFunctionAttribute()] - public static string Version() - { - return "2.2.0"; - } } } \ No newline at end of file diff --git a/src/runtime/pythonengine.cs b/src/runtime/pythonengine.cs index 70a1c557b..6c2ec4cf5 100644 --- a/src/runtime/pythonengine.cs +++ b/src/runtime/pythonengine.cs @@ -165,7 +165,7 @@ public static void Initialize() Runtime.PyDict_SetItemString(clr_dict, "_extras", module); foreach (PyObject key in locals.Keys()) { - if (!key.ToString().StartsWith("_")) + if (!key.ToString().StartsWith("_") || key.ToString().Equals("__version__")) { PyObject value = locals[key]; Runtime.PyDict_SetItem(clr_dict, key.Handle, value.Handle); diff --git a/src/runtime/resources/clr.py b/src/runtime/resources/clr.py index 61d6e76f1..ad66b5ace 100644 --- a/src/runtime/resources/clr.py +++ b/src/runtime/resources/clr.py @@ -1,7 +1,9 @@ -""" +""" Code in this module gets loaded into the main clr module. """ +__version__ = "2.2.0" + class clrproperty(object): """ diff --git a/src/tests/test_module.py b/src/tests/test_module.py index 9862bec99..fff044f0c 100644 --- a/src/tests/test_module.py +++ b/src/tests/test_module.py @@ -43,7 +43,7 @@ def test000importClr(self): def testVersionClr(self): import clr - self.assertTrue(clr.Version() >= "2.2.0") + self.assertTrue(clr.__version__ >= "2.2.0") def testPreloadVar(self): import clr