| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,10 +2,11 @@ dist: xenial | |||
| 2 | 2 | sudo: false | |
| 3 | 3 | language: python | |
| 4 | 4 | python: | |
| 5 | - - 2.7 | ||
| 6 | - - 3.5 | ||
| 7 | - - 3.6 | ||
| 5 | + - 3.8 | ||
| 8 | 6 | - 3.7 | |
| 7 | + - 3.6 | ||
| 8 | + - 3.5 | ||
| 9 | + - 2.7 | ||
| 9 | 10 | ||
| 10 | 11 | env: | |
| 11 | 12 | matrix: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 17 | 17 | - Added PythonException.Format method to format exceptions the same as traceback.format_exception | |
| 18 | 18 | - Added Runtime.None to be able to pass None as parameter into Python from .NET | |
| 19 | 19 | - Added PyObject.IsNone() to check if a Python object is None in .NET. | |
| 20 | + - Support for Python 3.8 | ||
| 20 | 21 | ||
| 21 | 22 | ### Changed | |
| 22 | 23 | ||
@@ -29,6 +30,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 29 | 30 | - Added support for kwarg parameters when calling .NET methods from Python | |
| 30 | 31 | - Changed method for finding MSBuild using vswhere | |
| 31 | 32 | - Reworked `Finalizer`. Now objects drop into its queue upon finalization, which is periodically drained when new objects are created. | |
| 33 | + - Marked `Runtime.OperatingSystemName` and `Runtime.MachineName` as `Obsolete`, should never have been `public` in the first place. They also don't necessarily return a result that matches the `platform` module's. | ||
| 32 | 34 | ||
| 33 | 35 | ### Fixed | |
| 34 | 36 | ||
@@ -37,6 +39,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 37 | 39 | - Fixes bug where delegates get casts (dotnetcore) | |
| 38 | 40 | - Determine size of interpreter longs at runtime | |
| 39 | 41 | - Handling exceptions ocurred in ModuleObject's getattribute | |
| 42 | + - Fill `__classcell__` correctly for Python subclasses of .NET types | ||
| 40 | 43 | ||
| 41 | 44 | ## [2.4.0][] | |
| 42 | 45 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,24 +15,21 @@ environment: | |||
| 15 | 15 | CODECOV_ENV: PYTHON_VERSION, PLATFORM | |
| 16 | 16 | ||
| 17 | 17 | matrix: | |
| 18 | - - PYTHON_VERSION: 2.7 | ||
| 18 | + - PYTHON_VERSION: 3.8 | ||
| 19 | 19 | BUILD_OPTS: --xplat | |
| 20 | - - PYTHON_VERSION: 3.5 | ||
| 20 | + - PYTHON_VERSION: 3.7 | ||
| 21 | 21 | BUILD_OPTS: --xplat | |
| 22 | 22 | - PYTHON_VERSION: 3.6 | |
| 23 | 23 | BUILD_OPTS: --xplat | |
| 24 | - - PYTHON_VERSION: 3.7 | ||
| 25 | - BUILD_OPTS: --xplat | ||
| 26 | - - PYTHON_VERSION: 2.7 | ||
| 27 | 24 | - PYTHON_VERSION: 3.5 | |
| 28 | - - PYTHON_VERSION: 3.6 | ||
| 25 | + BUILD_OPTS: --xplat | ||
| 26 | + - PYTHON_VERSION: 2.7 | ||
| 27 | + BUILD_OPTS: --xplat | ||
| 28 | + - PYTHON_VERSION: 3.8 | ||
| 29 | 29 | - PYTHON_VERSION: 3.7 | |
| 30 | - | ||
| 31 | - matrix: | ||
| 32 | - allow_failures: | ||
| 33 | - - PYTHON_VERSION: 3.4 | ||
| 34 | - BUILD_OPTS: --xplat | ||
| 35 | - - PYTHON_VERSION: 3.4 | ||
| 30 | + - PYTHON_VERSION: 3.6 | ||
| 31 | + - PYTHON_VERSION: 3.5 | ||
| 32 | + - PYTHON_VERSION: 2.7 | ||
| 36 | 33 | ||
| 37 | 34 | init: | |
| 38 | 35 | # Update Environment Variables based on matrix/platform | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,10 +29,7 @@ public static void PlatformCache() | |||
| 29 | 29 | Runtime.Runtime.Initialize(); | |
| 30 | 30 | ||
| 31 | 31 | Assert.That(Runtime.Runtime.Machine, Is.Not.EqualTo(MachineType.Other)); | |
| 32 | - Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.MachineName)); | ||
| 33 | - | ||
| 34 | 32 | Assert.That(Runtime.Runtime.OperatingSystem, Is.Not.EqualTo(OperatingSystemType.Other)); | |
| 35 | - Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.OperatingSystemName)); | ||
| 36 | 33 | ||
| 37 | 34 | // Don't shut down the runtime: if the python engine was initialized | |
| 38 | 35 | // but not shut down by another test, we'd end up in a bad state. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + using System.Reflection.Emit; | ||
| 1 | 2 | using System; | |
| 2 | 3 | using System.Diagnostics.Contracts; | |
| 3 | 4 | using System.Runtime.InteropServices; | |
@@ -118,16 +119,16 @@ public class Runtime | |||
| 118 | 119 | { "Linux", OperatingSystemType.Linux }, | |
| 119 | 120 | }; | |
| 120 | 121 | ||
| 121 | - /// <summary> | ||
| 122 | - /// Gets the operating system as reported by python's platform.system(). | ||
| 123 | - /// </summary> | ||
| 124 | - public static OperatingSystemType OperatingSystem { get; private set; } | ||
| 122 | + [Obsolete] | ||
| 123 | + public static string OperatingSystemName => OperatingSystem.ToString(); | ||
| 124 | + | ||
| 125 | + [Obsolete] | ||
| 126 | + public static string MachineName => Machine.ToString(); | ||
| 125 | 127 | ||
| 126 | 128 | /// <summary> | |
| 127 | 129 | /// Gets the operating system as reported by python's platform.system(). | |
| 128 | 130 | /// </summary> | |
| 129 | - public static string OperatingSystemName { get; private set; } | ||
| 130 | - | ||
| 131 | + public static OperatingSystemType OperatingSystem { get; private set; } | ||
| 131 | 132 | ||
| 132 | 133 | /// <summary> | |
| 133 | 134 | /// Map lower-case version of the python machine name to the processor | |
@@ -154,11 +155,6 @@ public class Runtime | |||
| 154 | 155 | /// </summary> | |
| 155 | 156 | public static MachineType Machine { get; private set; }/* set in Initialize using python's platform.machine */ | |
| 156 | 157 | ||
| 157 | - /// <summary> | ||
| 158 | - /// Gets the machine architecture as reported by python's platform.machine(). | ||
| 159 | - /// </summary> | ||
| 160 | - public static string MachineName { get; private set; } | ||
| 161 | - | ||
| 162 | 158 | internal static bool IsPython2 = pyversionnumber < 30; | |
| 163 | 159 | internal static bool IsPython3 = pyversionnumber >= 30; | |
| 164 | 160 | ||
@@ -356,20 +352,21 @@ internal static void Initialize(bool initSigs = false) | |||
| 356 | 352 | /// </summary> | |
| 357 | 353 | private static void InitializePlatformData() | |
| 358 | 354 | { | |
| 355 | + #if !NETSTANDARD | ||
| 359 | 356 | IntPtr op; | |
| 360 | 357 | IntPtr fn; | |
| 361 | 358 | IntPtr platformModule = PyImport_ImportModule("platform"); | |
| 362 | 359 | IntPtr emptyTuple = PyTuple_New(0); | |
| 363 | 360 | ||
| 364 | 361 | fn = PyObject_GetAttrString(platformModule, "system"); | |
| 365 | 362 | op = PyObject_Call(fn, emptyTuple, IntPtr.Zero); | |
| 366 | - OperatingSystemName = GetManagedString(op); | ||
| 363 | + string operatingSystemName = GetManagedString(op); | ||
| 367 | 364 | XDecref(op); | |
| 368 | 365 | XDecref(fn); | |
| 369 | 366 | ||
| 370 | 367 | fn = PyObject_GetAttrString(platformModule, "machine"); | |
| 371 | 368 | op = PyObject_Call(fn, emptyTuple, IntPtr.Zero); | |
| 372 | - MachineName = GetManagedString(op); | ||
| 369 | + string machineName = GetManagedString(op); | ||
| 373 | 370 | XDecref(op); | |
| 374 | 371 | XDecref(fn); | |
| 375 | 372 | ||
@@ -379,18 +376,47 @@ private static void InitializePlatformData() | |||
| 379 | 376 | // Now convert the strings into enum values so we can do switch | |
| 380 | 377 | // statements rather than constant parsing. | |
| 381 | 378 | OperatingSystemType OSType; | |
| 382 | - if (!OperatingSystemTypeMapping.TryGetValue(OperatingSystemName, out OSType)) | ||
| 379 | + if (!OperatingSystemTypeMapping.TryGetValue(operatingSystemName, out OSType)) | ||
| 383 | 380 | { | |
| 384 | 381 | OSType = OperatingSystemType.Other; | |
| 385 | 382 | } | |
| 386 | 383 | OperatingSystem = OSType; | |
| 387 | 384 | ||
| 388 | 385 | MachineType MType; | |
| 389 | - if (!MachineTypeMapping.TryGetValue(MachineName.ToLower(), out MType)) | ||
| 386 | + if (!MachineTypeMapping.TryGetValue(machineName.ToLower(), out MType)) | ||
| 390 | 387 | { | |
| 391 | 388 | MType = MachineType.Other; | |
| 392 | 389 | } | |
| 393 | 390 | Machine = MType; | |
| 391 | + #else | ||
| 392 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
| 393 | + OperatingSystem = OperatingSystemType.Linux; | ||
| 394 | + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| 395 | + OperatingSystem = OperatingSystemType.Darwin; | ||
| 396 | + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| 397 | + OperatingSystem = OperatingSystemType.Windows; | ||
| 398 | + else | ||
| 399 | + OperatingSystem = OperatingSystemType.Other; | ||
| 400 | + | ||
| 401 | + switch (RuntimeInformation.ProcessArchitecture) | ||
| 402 | + { | ||
| 403 | + case Architecture.X86: | ||
| 404 | + Machine = MachineType.i386; | ||
| 405 | + break; | ||
| 406 | + case Architecture.X64: | ||
| 407 | + Machine = MachineType.x86_64; | ||
| 408 | + break; | ||
| 409 | + case Architecture.Arm: | ||
| 410 | + Machine = MachineType.armv7l; | ||
| 411 | + break; | ||
| 412 | + case Architecture.Arm64: | ||
| 413 | + Machine = MachineType.aarch64; | ||
| 414 | + break; | ||
| 415 | + default: | ||
| 416 | + Machine = MachineType.Other; | ||
| 417 | + break; | ||
| 418 | + } | ||
| 419 | + #endif | ||
| 394 | 420 | } | |
| 395 | 421 | ||
| 396 | 422 | internal static void Shutdown() | |
@@ -1966,6 +1992,15 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size) | |||
| 1966 | 1992 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 1967 | 1993 | internal static extern void PyErr_Print(); | |
| 1968 | 1994 | ||
| 1995 | + //==================================================================== | ||
| 1996 | + // Cell API | ||
| 1997 | + //==================================================================== | ||
| 1998 | + | ||
| 1999 | + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | ||
| 2000 | + internal static extern NewReference PyCell_Get(BorrowedReference cell); | ||
| 2001 | + | ||
| 2002 | + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | ||
| 2003 | + internal static extern int PyCell_Set(BorrowedReference cell, IntPtr value); | ||
| 1969 | 2004 | ||
| 1970 | 2005 | //==================================================================== | |
| 1971 | 2006 | // Miscellaneous | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -280,6 +280,14 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr | |||
| 280 | 280 | IntPtr cls_dict = Marshal.ReadIntPtr(py_type, TypeOffset.tp_dict); | |
| 281 | 281 | Runtime.PyDict_Update(cls_dict, py_dict); | |
| 282 | 282 | ||
| 283 | + // Update the __classcell__ if it exists | ||
| 284 | + var cell = new BorrowedReference(Runtime.PyDict_GetItemString(cls_dict, "__classcell__")); | ||
| 285 | + if (!cell.IsNull) | ||
| 286 | + { | ||
| 287 | + Runtime.PyCell_Set(cell, py_type); | ||
| 288 | + Runtime.PyDict_DelItemString(cls_dict, "__classcell__"); | ||
| 289 | + } | ||
| 290 | + | ||
| 283 | 291 | return py_type; | |
| 284 | 292 | } | |
| 285 | 293 | catch (Exception e) | |
@@ -617,7 +625,9 @@ int MAP_ANONYMOUS | |||
| 617 | 625 | case OperatingSystemType.Linux: | |
| 618 | 626 | return 0x20; | |
| 619 | 627 | default: | |
| 620 | - throw new NotImplementedException($"mmap is not supported on {Runtime.OperatingSystemName}"); | ||
| 628 | + throw new NotImplementedException( | ||
| 629 | + $"mmap is not supported on {Runtime.OperatingSystem}" | ||
| 630 | + ); | ||
| 621 | 631 | } | |
| 622 | 632 | } | |
| 623 | 633 | } | |
@@ -651,7 +661,9 @@ internal static IMemoryMapper CreateMemoryMapper() | |||
| 651 | 661 | case OperatingSystemType.Windows: | |
| 652 | 662 | return new WindowsMemoryMapper(); | |
| 653 | 663 | default: | |
| 654 | - throw new NotImplementedException($"No support for {Runtime.OperatingSystemName}"); | ||
| 664 | + throw new NotImplementedException( | ||
| 665 | + $"No support for {Runtime.OperatingSystem}" | ||
| 666 | + ); | ||
| 655 | 667 | } | |
| 656 | 668 | } | |
| 657 | 669 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments