| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1429b9f commit de6f4cc
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,11 +19,7 @@ Python for .NET Changes | |||
| 19 | 19 | - Fixed exception bugs for Python 2.5+. When compiled for Python 2.5+ all | |
| 20 | 20 | managed exceptions are based on Python's exceptions.Exception class. | |
| 21 | 21 | [tiran] | |
| 22 | - | ||
| 23 | - - Implemented a preload switch. Automatic preloading can be enabled by | ||
| 24 | - setting clr.preload to true. Preloading is automatically enabled for | ||
| 25 | - interactive Python shells and disabled in all other cases. [tiran] | ||
| 26 | - | ||
| 22 | + | ||
| 27 | 23 | - Added deprecation warnings for importing from CLR.* and the CLR module. | |
| 28 | 24 | [tiran] | |
| 29 | 25 | ||
@@ -34,8 +30,10 @@ Python for .NET Changes | |||
| 34 | 30 | fixing a some ref counter bugs and creating a new makefile.mono. | |
| 35 | 31 | [tiran] | |
| 36 | 32 | ||
| 37 | - - Added a standard python extension to load the clr environment | ||
| 38 | - (src/monoclr). XXX DOES NOT WORK | ||
| 33 | + - Added a standard python extension to load the clr environment. | ||
| 34 | + The src/monoclr/ directory contains additional sample code like a | ||
| 35 | + Python binary linked against libpython2.x.so and some example code | ||
| 36 | + how to embed Mono and PythonNet in a C application. | ||
| 39 | 37 | [tiran] | |
| 40 | 38 | ||
| 41 | 39 | - Added yet another python prompt. This time it's a C application that | |
@@ -46,11 +44,17 @@ Python for .NET Changes | |||
| 46 | 44 | The latter is required for module functions which invoke Python methods. | |
| 47 | 45 | [tiran] | |
| 48 | 46 | ||
| 49 | - - Added clr.AddReference("assembly name"), clr.FindAssembly("name") and | ||
| 50 | - clr.ListAssemblies(verbose). [tiran] | ||
| 47 | + - Added clr.setPreload(), clr.getPreload(), clr.AddReference("assembly name"), | ||
| 48 | + clr.FindAssembly("name") and clr.ListAssemblies(verbose). Automatic | ||
| 49 | + preloading can be enabled with clr.setPreload/True). Preloading is | ||
| 50 | + automatically enabled for interactive Python shells and disabled in all | ||
| 51 | + other cases. [tiran] | ||
| 51 | 52 | ||
| 52 | 53 | - New Makefile that works for Windows and Mono and autodetects the Python | |
| 53 | - version and UCS 2/4 setting. | ||
| 54 | + version and UCS 2/4 setting. [tiran] | ||
| 55 | + | ||
| 56 | + - Added code for Python 2.3. PythonNet can be build for Python 2.3 again | ||
| 57 | + but it is not fully supported. [tiran] | ||
| 54 | 58 | ||
| 55 | 59 | PythonNet 2.0 alpha 1 | |
| 56 | 60 | --------------------------------------------------------------------------- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,11 +5,13 @@ configuration file /etc/mono/config | |||
| 5 | 5 | --> | |
| 6 | 6 | ||
| 7 | 7 | <configuration> | |
| 8 | - <dllmap dll="python24" target="libpython2.4.so.1" os="!windows" /> | ||
| 9 | - <dllmap dll="python25" target="libpython2.5.so.1" os="!windows" /> | ||
| 10 | - <dllmap dll="python26" target="libpython2.6.so.1" os="!windows" /> | ||
| 11 | - <dllmap dll="python24.dll" target="libpython2.4.so.1" os="!windows" /> | ||
| 12 | - <dllmap dll="python25.dll" target="libpython2.5.so.1" os="!windows" /> | ||
| 13 | - <dllmap dll="python26.dll" target="libpython2.6.so.1" os="!windows" /> | ||
| 8 | + <dllmap dll="python23" target="libpython2.3.so" os="!windows" /> | ||
| 9 | + <dllmap dll="python24" target="libpython2.4.so" os="!windows" /> | ||
| 10 | + <dllmap dll="python25" target="libpython2.5.so" os="!windows" /> | ||
| 11 | + <dllmap dll="python26" target="libpython2.6.so" os="!windows" /> | ||
| 12 | + <dllmap dll="python23.dll" target="libpython2.3.so" os="!windows" /> | ||
| 13 | + <dllmap dll="python24.dll" target="libpython2.4.so" os="!windows" /> | ||
| 14 | + <dllmap dll="python25.dll" target="libpython2.5.so" os="!windows" /> | ||
| 15 | + <dllmap dll="python26.dll" target="libpython2.6.so" os="!windows" /> | ||
| 14 | 16 | </configuration> | |
| 15 | 17 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -197,9 +197,11 @@ <h2>Installation</h2> | |||
| 197 | 197 | <strong>Running on Linux/Mono:</strong> Preliminary testing shows that | |
| 198 | 198 | PythonNet runs under <a href="http://www.go-mono.com">Mono</a> without | |
| 199 | 199 | major issues, though the Mono runtime is not yet complete so there | |
| 200 | - still may be problems. The Python for .NET integration layer is 100% | ||
| 201 | - managed code, so there should be no long-term issues under Mono - it | ||
| 202 | - should work better and better as the Mono platform matures. | ||
| 200 | + still may be problems. The only known issues with Mono are related to | ||
| 201 | + generic methods. Some edge cases aren't working properly and the bugs | ||
| 202 | + are already been worked on. However the Python for .NET integration layer | ||
| 203 | + is 100% managed code, so there should be no long-term issues under Mono | ||
| 204 | + - it should work better and better as the Mono platform matures. | ||
| 203 | 205 | </p> | |
| 204 | 206 | ||
| 205 | 207 | <p> | |
@@ -236,22 +238,24 @@ <h2>Installation</h2> | |||
| 236 | 238 | when the interpreter is not build with --enable-shared (Debian, Ubuntu) | |
| 237 | 239 | or libpython2.?.so isn't available. You <strong>must</strong> use a | |
| 238 | 240 | Python binary that is linked dynamically against libpython2.?.so. | |
| 239 | - <pre>ldd /usr/bin/python2.?</pre> has to list libpython2.?.so. When your | ||
| 240 | - Python interpreter isn't linked against libpython2.?.so but the shared | ||
| 241 | - lib | ||
| 241 | + <code>ldd /usr/bin/python2.?</code> has to list <code>libpython2.?.so</code>. When your | ||
| 242 | + Python interpreter isn't linked against libpython2.?.so you can't load | ||
| 243 | + the clr.so module. The src/monoclr/ directory contains a dynamically linked | ||
| 244 | + Python binary and a clrpython2.x which automatically loads Mono and PythonNet | ||
| 245 | + on startup. | ||
| 242 | 246 | </p> | |
| 243 | 247 | ||
| 244 | 248 | <pre> | |
| 245 | - <dllmap dll="e;python25"e; target="e;libpython2.5.so"e; os="e;!wi | ||
| 246 | - ndows"e; /> | ||
| 249 | + <dllmap dll="python25" target="libpython2.5.so" os="!windows" /> | ||
| 247 | 250 | </pre> | |
| 248 | 251 | ||
| 249 | 252 | <a name="monoclr_libpython"><a/> | |
| 250 | 253 | <p> | |
| 251 | 254 | PythonNet uses compiler symbols in order to build PythonNet for different | |
| 252 | 255 | versions and flavors of Python. | |
| 253 | 256 | <table> | |
| 254 | - <th><td>symbol</td><td>explenetion</td></th> | ||
| 257 | + <tr><th>symbol</th><th>explenetion</th></tr> | ||
| 258 | + <tr><td>PYTHON23</td><td>build for Python 2.3</td></tr> | ||
| 255 | 259 | <tr><td>PYTHON24</td><td>build for Python 2.4</td></tr> | |
| 256 | 260 | <tr><td>PYTHON25</td><td>build for Python 2.5</td></tr> | |
| 257 | 261 | <tr><td>PYTHON26</td><td>build for Python 2.6</td></tr> | |
@@ -348,9 +352,19 @@ <h2>Importing Modules</h2> | |||
| 348 | 352 | Python for .NET uses the PYTHONPATH (sys.path) to look for assemblies | |
| 349 | 353 | to load, in addition to the usual application base and the GAC. To | |
| 350 | 354 | ensure that you can implicitly import an assembly, put the directory | |
| 351 | - containing the assembly in <code>sys.path</code>. | ||
| 355 | + containing the assembly in <code>sys.path</code>. However the | ||
| 356 | + <code>Python.Runtime.dll</code> is not loaded from <code>sys.path</code>. | ||
| 357 | + It must either live in the GAC or somewhere else were it can be loaded. | ||
| 352 | 358 | </p> | |
| 353 | 359 | ||
| 360 | + <p> | ||
| 361 | + The clr module contains some additional methods like <code>setPreload(bool)</code>, | ||
| 362 | + <code>getPreload()</code>, <code>ListAssemblies(verbosity)</code> and | ||
| 363 | + <code>FindAssembly(name)</code>. set/getPreload tune the preload flag. For performance | ||
| 364 | + reasons PythonNet only creates wrappers for classes that are imported. It nakes | ||
| 365 | + important a bit faster but makes introspection impossible. Interactive Python shells | ||
| 366 | + have a default of True. | ||
| 367 | + </p> | ||
| 354 | 368 | ||
| 355 | 369 | <a name="classes"></a> | |
| 356 | 370 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,10 @@ | |||
| 26 | 26 | [assembly: AssemblyFileVersionAttribute("2.0.0.2")] | |
| 27 | 27 | [assembly: NeutralResourcesLanguageAttribute("en")] | |
| 28 | 28 | ||
| 29 | + #if (PYTHON23) | ||
| 30 | + [assembly: AssemblyTitleAttribute("Python.Runtime for Python 2.3")] | ||
| 31 | + [assembly: AssemblyDescriptionAttribute("Python Runtime for Python 2.3")] | ||
| 32 | + #endif | ||
| 29 | 33 | #if (PYTHON24) | |
| 30 | 34 | [assembly: AssemblyTitleAttribute("Python.Runtime for Python 2.4")] | |
| 31 | 35 | [assembly: AssemblyDescriptionAttribute("Python Runtime for Python 2.4")] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -214,9 +214,10 @@ internal static void SetupExceptionHack() { | |||
| 214 | 214 | " _class = None\n" + | |
| 215 | 215 | " _inner = None\n" + | |
| 216 | 216 | " \n" + | |
| 217 | - " @property\n" + | ||
| 217 | + " #@property\n" + | ||
| 218 | 218 | " def message(self):\n" + | |
| 219 | 219 | " return self.Message\n" + | |
| 220 | + " message = property(message)\n" + | ||
| 220 | 221 | " \n" + | |
| 221 | 222 | " def __init__(self, *args, **kw):\n" + | |
| 222 | 223 | " inst = self.__class__._class(*args, **kw)\n" + | |
@@ -264,7 +265,9 @@ internal static void SetupExceptionHack() { | |||
| 264 | 265 | Runtime.PyDict_SetItemString(dict, "__doc__", Runtime.PyNone); | |
| 265 | 266 | ||
| 266 | 267 | IntPtr flag = Runtime.Py_file_input; | |
| 267 | - Runtime.PyRun_String(code, flag, dict, dict); | ||
| 268 | + IntPtr result = Runtime.PyRun_String(code, flag, dict, dict); | ||
| 269 | + Exceptions.ErrorCheck(result); | ||
| 270 | + Runtime.Decref(result); | ||
| 268 | 271 | ||
| 269 | 272 | os_exc = Runtime.PyDict_GetItemString(dict, "Exception"); | |
| 270 | 273 | Runtime.PyObject_SetAttrString(os_exc, "_class", ns_exc); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,7 +169,6 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { | |||
| 169 | 169 | ModuleObject head = (mod_name == realname) ? null : root; | |
| 170 | 170 | ModuleObject tail = root; | |
| 171 | 171 | root.InitializePreload(); | |
| 172 | - bool preload = root.preload; | ||
| 173 | 172 | ||
| 174 | 173 | for (int i = 0; i < names.Length; i++) { | |
| 175 | 174 | string name = names[i]; | |
@@ -183,7 +182,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { | |||
| 183 | 182 | head = (ModuleObject)mt; | |
| 184 | 183 | } | |
| 185 | 184 | tail = (ModuleObject) mt; | |
| 186 | - if (preload) { | ||
| 185 | + if (CLRModule.preload) { | ||
| 187 | 186 | tail.LoadNames(); | |
| 188 | 187 | } | |
| 189 | 188 | Runtime.PyDict_SetItemString(modules, tail.moduleName, | |
@@ -195,7 +194,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { | |||
| 195 | 194 | ||
| 196 | 195 | if (fromlist && Runtime.PySequence_Size(fromList) == 1) { | |
| 197 | 196 | IntPtr fp = Runtime.PySequence_GetItem(fromList, 0); | |
| 198 | - if ((!preload) && Runtime.GetManagedString(fp) == "*") { | ||
| 197 | + if ((!CLRModule.preload) && Runtime.GetManagedString(fp) == "*") { | ||
| 199 | 198 | mod.LoadNames(); | |
| 200 | 199 | } | |
| 201 | 200 | Runtime.Decref(fp); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -305,32 +305,7 @@ internal class CLRModule : ModuleObject | |||
| 305 | 305 | { | |
| 306 | 306 | protected static bool hacked = false; | |
| 307 | 307 | protected static bool interactive_preload = true; | |
| 308 | - | ||
| 309 | - public bool preload { | ||
| 310 | - get { | ||
| 311 | - IntPtr pybool = Runtime.PyDict_GetItemString(dict, "preload"); | ||
| 312 | - if (pybool == IntPtr.Zero) { | ||
| 313 | - Exceptions.Clear(); | ||
| 314 | - return false; | ||
| 315 | - } | ||
| 316 | - return (Runtime.PyObject_IsTrue(pybool) == 1); | ||
| 317 | - } | ||
| 318 | - set { | ||
| 319 | - IntPtr pybool; | ||
| 320 | - if (value) { | ||
| 321 | - pybool = Runtime.PyTrue; | ||
| 322 | - } else { | ||
| 323 | - pybool = Runtime.PyFalse; | ||
| 324 | - } | ||
| 325 | - IntPtr oldval = Runtime.PyDict_GetItemString(dict, "preload"); | ||
| 326 | - if (oldval != IntPtr.Zero) { | ||
| 327 | - Runtime.Decref(oldval); | ||
| 328 | - } | ||
| 329 | - Runtime.Incref(pybool); | ||
| 330 | - Runtime.PyDict_SetItemString(dict, "preload", pybool); | ||
| 331 | - } | ||
| 332 | - | ||
| 333 | - } | ||
| 308 | + internal static bool preload; | ||
| 334 | 309 | ||
| 335 | 310 | public CLRModule() : base("clr") { | |
| 336 | 311 | _namespace = String.Empty; | |
@@ -367,34 +342,15 @@ internal void InitializePreload() { | |||
| 367 | 342 | } | |
| 368 | 343 | } | |
| 369 | 344 | ||
| 370 | - //==================================================================== | ||
| 371 | - // Type __setattr__ implementation. | ||
| 372 | - //==================================================================== | ||
| 373 | - public static new int tp_setattro(IntPtr ob, IntPtr key, IntPtr val) | ||
| 374 | - { | ||
| 375 | - string name = Runtime.GetManagedString(key); | ||
| 376 | - if (name != "preload") { | ||
| 377 | - return ExtensionType.tp_setattro(ob, key, val); | ||
| 378 | - } else { | ||
| 379 | - IntPtr dict = Runtime.PyModule_GetDict(ob); | ||
| 380 | - Exceptions.ErrorCheck(dict); | ||
| 381 | - | ||
| 382 | - IntPtr oldval = Runtime.PyDict_GetItemString(dict, "preload"); | ||
| 383 | - Runtime.Decref(oldval); | ||
| 384 | - | ||
| 385 | - IntPtr newval; | ||
| 386 | - if ((val != IntPtr.Zero) && (Runtime.PyObject_IsTrue(val) == 1)) { | ||
| 387 | - newval = Runtime.PyTrue; | ||
| 388 | - } else { | ||
| 389 | - newval = Runtime.PyFalse; | ||
| 390 | - } | ||
| 391 | - Runtime.PyDict_SetItemString(dict, "preload", newval); | ||
| 392 | - return 0; | ||
| 393 | - } | ||
| 345 | + [ModuleFunctionAttribute()] | ||
| 346 | + public static bool getPreload() { | ||
| 347 | + return preload; | ||
| 394 | 348 | } | |
| 395 | 349 | ||
| 396 | - public static int AddAssembly(string name) { | ||
| 397 | - return 1; | ||
| 350 | + [ModuleFunctionAttribute()] | ||
| 351 | + public static void setPreload(bool preloadFlag) | ||
| 352 | + { | ||
| 353 | + preload = preloadFlag; | ||
| 398 | 354 | } | |
| 399 | 355 | ||
| 400 | 356 | [ModuleFunctionAttribute()] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,11 @@ public class Runtime { | |||
| 36 | 36 | #error You must define either UCS2 or UCS4! | |
| 37 | 37 | #endif | |
| 38 | 38 | ||
| 39 | + #if (PYTHON23) | ||
| 40 | + public const string dll = "python23"; | ||
| 41 | + public const string pyversion = "2.3"; | ||
| 42 | + public const int pyversionnumber = 23; | ||
| 43 | + #endif | ||
| 39 | 44 | #if (PYTHON24) | |
| 40 | 45 | public const string dll = "python24"; | |
| 41 | 46 | public const string pyversion = "2.4"; | |
@@ -51,8 +56,8 @@ public class Runtime { | |||
| 51 | 56 | public const string pyversion = "2.6"; | |
| 52 | 57 | public const int pyversionnumber = 26; | |
| 53 | 58 | #endif | |
| 54 | - #if ! (PYTHON24 || PYTHON25 || PYTHON26) | ||
| 55 | - #error You must define either PYTHON24, PYTHON25 or PYTHON26! | ||
| 59 | + #if ! (PYTHON23 || PYTHON24 || PYTHON25 || PYTHON26) | ||
| 60 | + #error You must define one of PYTHON23 to PYTHON26 | ||
| 56 | 61 | #endif | |
| 57 | 62 | internal static bool wrap_exceptions; | |
| 58 | 63 | internal static bool is32bit; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,7 +55,7 @@ def main(verbosity=1): | |||
| 55 | 55 | ||
| 56 | 56 | for name in test_modules: | |
| 57 | 57 | module = __import__(name) | |
| 58 | - suite.addTests(module.test_suite()) | ||
| 58 | + suite.addTests((module.test_suite(),)) | ||
| 59 | 59 | ||
| 60 | 60 | unittest.TextTestRunner(verbosity=verbosity).run(suite) | |
| 61 | 61 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments