Skip to content

Commit 782eff8

Browse files
authored
Merge pull request #1138 from pythonnet/python38
2 parents d8f5ab0 + ed2b7e8 commit 782eff8

File tree

6 files changed

+80
-35
lines changed

6 files changed

+80
-35
lines changed

.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ dist: xenial
22
sudo: false
33
language: python
44
python:
5-
- 2.7
6-
- 3.5
7-
- 3.6
5+
- 3.8
86
- 3.7
7+
- 3.6
8+
- 3.5
9+
- 2.7
910

1011
env:
1112
matrix:

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1717
- Added PythonException.Format method to format exceptions the same as traceback.format_exception
1818
- Added Runtime.None to be able to pass None as parameter into Python from .NET
1919
- Added PyObject.IsNone() to check if a Python object is None in .NET.
20+
- Support for Python 3.8
2021

2122
### Changed
2223

@@ -29,6 +30,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2930
- Added support for kwarg parameters when calling .NET methods from Python
3031
- Changed method for finding MSBuild using vswhere
3132
- 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.
3234

3335
### Fixed
3436

@@ -37,6 +39,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
3739
- Fixes bug where delegates get casts (dotnetcore)
3840
- Determine size of interpreter longs at runtime
3941
- Handling exceptions ocurred in ModuleObject's getattribute
42+
- Fill `__classcell__` correctly for Python subclasses of .NET types
4043

4144
## [2.4.0][]
4245

appveyor.yml

+9-12
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,21 @@ environment:
1515
CODECOV_ENV: PYTHON_VERSION, PLATFORM
1616

1717
matrix:
18-
- PYTHON_VERSION: 2.7
18+
- PYTHON_VERSION: 3.8
1919
BUILD_OPTS: --xplat
20-
- PYTHON_VERSION: 3.5
20+
- PYTHON_VERSION: 3.7
2121
BUILD_OPTS: --xplat
2222
- PYTHON_VERSION: 3.6
2323
BUILD_OPTS: --xplat
24-
- PYTHON_VERSION: 3.7
25-
BUILD_OPTS: --xplat
26-
- PYTHON_VERSION: 2.7
2724
- 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
2929
- 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
3633

3734
init:
3835
# Update Environment Variables based on matrix/platform

src/embed_tests/TestRuntime.cs

-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public static void PlatformCache()
2929
Runtime.Runtime.Initialize();
3030

3131
Assert.That(Runtime.Runtime.Machine, Is.Not.EqualTo(MachineType.Other));
32-
Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.MachineName));
33-
3432
Assert.That(Runtime.Runtime.OperatingSystem, Is.Not.EqualTo(OperatingSystemType.Other));
35-
Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.OperatingSystemName));
3633

3734
// Don't shut down the runtime: if the python engine was initialized
3835
// but not shut down by another test, we'd end up in a bad state.

src/runtime/runtime.cs

+50-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Reflection.Emit;
12
using System;
23
using System.Diagnostics.Contracts;
34
using System.Runtime.InteropServices;
@@ -118,16 +119,16 @@ public class Runtime
118119
{ "Linux", OperatingSystemType.Linux },
119120
};
120121

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();
125127

126128
/// <summary>
127129
/// Gets the operating system as reported by python's platform.system().
128130
/// </summary>
129-
public static string OperatingSystemName { get; private set; }
130-
131+
public static OperatingSystemType OperatingSystem { get; private set; }
131132

132133
/// <summary>
133134
/// Map lower-case version of the python machine name to the processor
@@ -154,11 +155,6 @@ public class Runtime
154155
/// </summary>
155156
public static MachineType Machine { get; private set; }/* set in Initialize using python's platform.machine */
156157

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-
162158
internal static bool IsPython2 = pyversionnumber < 30;
163159
internal static bool IsPython3 = pyversionnumber >= 30;
164160

@@ -356,20 +352,21 @@ internal static void Initialize(bool initSigs = false)
356352
/// </summary>
357353
private static void InitializePlatformData()
358354
{
355+
#if !NETSTANDARD
359356
IntPtr op;
360357
IntPtr fn;
361358
IntPtr platformModule = PyImport_ImportModule("platform");
362359
IntPtr emptyTuple = PyTuple_New(0);
363360

364361
fn = PyObject_GetAttrString(platformModule, "system");
365362
op = PyObject_Call(fn, emptyTuple, IntPtr.Zero);
366-
OperatingSystemName = GetManagedString(op);
363+
string operatingSystemName = GetManagedString(op);
367364
XDecref(op);
368365
XDecref(fn);
369366

370367
fn = PyObject_GetAttrString(platformModule, "machine");
371368
op = PyObject_Call(fn, emptyTuple, IntPtr.Zero);
372-
MachineName = GetManagedString(op);
369+
string machineName = GetManagedString(op);
373370
XDecref(op);
374371
XDecref(fn);
375372

@@ -379,18 +376,47 @@ private static void InitializePlatformData()
379376
// Now convert the strings into enum values so we can do switch
380377
// statements rather than constant parsing.
381378
OperatingSystemType OSType;
382-
if (!OperatingSystemTypeMapping.TryGetValue(OperatingSystemName, out OSType))
379+
if (!OperatingSystemTypeMapping.TryGetValue(operatingSystemName, out OSType))
383380
{
384381
OSType = OperatingSystemType.Other;
385382
}
386383
OperatingSystem = OSType;
387384

388385
MachineType MType;
389-
if (!MachineTypeMapping.TryGetValue(MachineName.ToLower(), out MType))
386+
if (!MachineTypeMapping.TryGetValue(machineName.ToLower(), out MType))
390387
{
391388
MType = MachineType.Other;
392389
}
393390
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
394420
}
395421

396422
internal static void Shutdown()
@@ -1966,6 +1992,15 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
19661992
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
19671993
internal static extern void PyErr_Print();
19681994

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);
19692004

19702005
//====================================================================
19712006
// Miscellaneous

src/runtime/typemanager.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
280280
IntPtr cls_dict = Marshal.ReadIntPtr(py_type, TypeOffset.tp_dict);
281281
Runtime.PyDict_Update(cls_dict, py_dict);
282282

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+
283291
return py_type;
284292
}
285293
catch (Exception e)
@@ -617,7 +625,9 @@ int MAP_ANONYMOUS
617625
case OperatingSystemType.Linux:
618626
return 0x20;
619627
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+
);
621631
}
622632
}
623633
}
@@ -651,7 +661,9 @@ internal static IMemoryMapper CreateMemoryMapper()
651661
case OperatingSystemType.Windows:
652662
return new WindowsMemoryMapper();
653663
default:
654-
throw new NotImplementedException($"No support for {Runtime.OperatingSystemName}");
664+
throw new NotImplementedException(
665+
$"No support for {Runtime.OperatingSystem}"
666+
);
655667
}
656668
}
657669

0 commit comments

Comments
 (0)