From c6f12cf91dc2bb2110e102ae468d2fb002790217 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 29 Aug 2023 17:23:31 +0200 Subject: [PATCH 01/15] Reset version to dev --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index b50214693..0f9d6b15d 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.0.2 +3.1.0-dev From 171cee4495f3498b1ff57f3d5290b16d52a95432 Mon Sep 17 00:00:00 2001 From: Omkar Borhade <91014820+OmkarBorhade98@users.noreply.github.com> Date: Sun, 3 Sep 2023 05:10:49 +0530 Subject: [PATCH 02/15] Change PyScope to PyModule in docs (#2231) PyScope data type not found. Py.CreateScope() returns the variable of type PyModule. --- doc/source/dotnet.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/dotnet.rst b/doc/source/dotnet.rst index 43b7659ac..ed2b741a7 100644 --- a/doc/source/dotnet.rst +++ b/doc/source/dotnet.rst @@ -110,7 +110,7 @@ Code executed from the scope will have access to the variable: using (Py.GIL()) { // create a Python scope - using (PyScope scope = Py.CreateScope()) + using (PyModule scope = Py.CreateScope()) { // convert the Person object to a PyObject PyObject pyPerson = person.ToPython(); From 22d07ddff8f449d295078ecfebe00fe0ff6e4c74 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Fri, 22 Sep 2023 15:19:16 -0500 Subject: [PATCH 03/15] custom repr for enum values (#2239) Examples: --------- Co-authored-by: Mohamed Koubaa --- CHANGELOG.md | 2 ++ src/runtime/Types/ClassObject.cs | 51 ++++++++++++++++++++++++++++++++ tests/test_enum.py | 10 +++++++ 3 files changed, 63 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba0b935c..fb13982e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. ### Added +- use enum name in repr + ### Changed ### Fixed diff --git a/src/runtime/Types/ClassObject.cs b/src/runtime/Types/ClassObject.cs index cc42039e8..f0585ffa6 100644 --- a/src/runtime/Types/ClassObject.cs +++ b/src/runtime/Types/ClassObject.cs @@ -1,7 +1,9 @@ using System; using System.Diagnostics; +using System.Globalization; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Runtime.Serialization; namespace Python.Runtime @@ -47,6 +49,55 @@ internal NewReference GetDocString() return Runtime.PyString_FromString(str); } + private static string ConvertFlags(Enum value) + { + Type primitiveType = value.GetType().GetEnumUnderlyingType(); + string format = "X" + (Marshal.SizeOf(primitiveType) * 2).ToString(CultureInfo.InvariantCulture); + var primitive = (IFormattable)Convert.ChangeType(value, primitiveType); + return "0x" + primitive.ToString(format, null); + + } + + private static string ConvertValue(Enum value) + { + Type primitiveType = value.GetType().GetEnumUnderlyingType(); + return Convert.ChangeType(value, primitiveType).ToString()!; + } + + /// + /// given an enum, write a __repr__ string formatted in the same + /// way as a python repr string. Something like: + /// '<Color.GREEN: 2>'; + /// with a binary value for [Flags] enums + /// + /// Instace of the enum object + /// + private static string GetEnumReprString(Enum inst) + { + var obType = inst.GetType(); + + string strValue2 = obType.IsFlagsEnum() ? ConvertFlags(inst) : ConvertValue(inst); + + var repr = $"<{obType.Name}.{inst}: {strValue2}>"; + return repr; + } + + /// + /// ClassObject __repr__ implementation. + /// + public new static NewReference tp_repr(BorrowedReference ob) + { + if (GetManagedObject(ob) is not CLRObject co) + { + return Exceptions.RaiseTypeError("invalid object"); + } + if (co.inst.GetType().IsEnum) + { + return Runtime.PyString_FromString(GetEnumReprString((Enum)co.inst)); + } + + return ClassBase.tp_repr(ob); + } /// /// Implements __new__ for reflected classes and value types. diff --git a/tests/test_enum.py b/tests/test_enum.py index f24f95b36..3d3edba10 100644 --- a/tests/test_enum.py +++ b/tests/test_enum.py @@ -143,6 +143,16 @@ def test_enum_undefined_value(): Test.FieldTest().EnumField = Test.ShortEnum(20, True) +def test_enum_repr(): + """Test enumeration repr.""" + from System import DayOfWeek + + assert repr(DayOfWeek.Monday) == "" + + assert repr(Test.FlagsEnum(7)) == "" + assert repr(Test.FlagsEnum(8)) == "" + + def test_enum_conversion(): """Test enumeration conversion.""" ob = Test.FieldTest() From a9e757f316e48f9e754fb2368cf9caaf1a9f9880 Mon Sep 17 00:00:00 2001 From: Victor Nova Date: Tue, 3 Oct 2023 22:50:02 -0700 Subject: [PATCH 04/15] fixed ARM CI --- .github/workflows/ARM.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ARM.yml b/.github/workflows/ARM.yml index 0492b7a3a..eef0e666d 100644 --- a/.github/workflows/ARM.yml +++ b/.github/workflows/ARM.yml @@ -27,25 +27,25 @@ jobs: - name: Install dependencies run: | - pip install -r requirements.txt - pip install pytest numpy # for tests + pip3.8 install -r requirements.txt + pip3.8 install pytest numpy # for tests - name: Build and Install run: | - pip install -v . + pip3.8 install -v . - name: Set Python DLL path (non Windows) run: | - echo PYTHONNET_PYDLL=$(python -m find_libpython) >> $GITHUB_ENV + echo PYTHONNET_PYDLL=$(python3.8 -m find_libpython) >> $GITHUB_ENV - name: Embedding tests run: dotnet test --logger "console;verbosity=detailed" src/embed_tests/ - name: Python Tests (Mono) - run: python -m pytest --runtime mono + run: python3.8 -m pytest --runtime mono - name: Python Tests (.NET Core) - run: python -m pytest --runtime coreclr + run: python3.8 -m pytest --runtime coreclr - name: Python tests run from .NET run: dotnet test src/python_tests_runner/ From 6aa92c19facfacc48703c4d7d4e871be048ea209 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 27 Sep 2023 12:57:00 +0200 Subject: [PATCH 05/15] Add type offsets for 3.12 and update interop generation --- src/runtime/Native/TypeOffset312.cs | 144 ++++++++++++++++++++++++++++ tools/geninterop/geninterop.py | 14 ++- 2 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 src/runtime/Native/TypeOffset312.cs diff --git a/src/runtime/Native/TypeOffset312.cs b/src/runtime/Native/TypeOffset312.cs new file mode 100644 index 000000000..8ba30e816 --- /dev/null +++ b/src/runtime/Native/TypeOffset312.cs @@ -0,0 +1,144 @@ + +// Auto-generated by geninterop.py. +// DO NOT MODIFY BY HAND. + +// Python 3.12: ABI flags: '' + +// ReSharper disable InconsistentNaming +// ReSharper disable IdentifierTypo + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +using Python.Runtime.Native; + +namespace Python.Runtime +{ + [SuppressMessage("Style", "IDE1006:Naming Styles", + Justification = "Following CPython", + Scope = "type")] + + [StructLayout(LayoutKind.Sequential)] + internal class TypeOffset312 : GeneratedTypeOffsets, ITypeOffsets + { + public TypeOffset312() { } + // Auto-generated from PyHeapTypeObject in Python.h + public int ob_refcnt { get; private set; } + public int ob_type { get; private set; } + public int ob_size { get; private set; } + public int tp_name { get; private set; } + public int tp_basicsize { get; private set; } + public int tp_itemsize { get; private set; } + public int tp_dealloc { get; private set; } + public int tp_vectorcall_offset { get; private set; } + public int tp_getattr { get; private set; } + public int tp_setattr { get; private set; } + public int tp_as_async { get; private set; } + public int tp_repr { get; private set; } + public int tp_as_number { get; private set; } + public int tp_as_sequence { get; private set; } + public int tp_as_mapping { get; private set; } + public int tp_hash { get; private set; } + public int tp_call { get; private set; } + public int tp_str { get; private set; } + public int tp_getattro { get; private set; } + public int tp_setattro { get; private set; } + public int tp_as_buffer { get; private set; } + public int tp_flags { get; private set; } + public int tp_doc { get; private set; } + public int tp_traverse { get; private set; } + public int tp_clear { get; private set; } + public int tp_richcompare { get; private set; } + public int tp_weaklistoffset { get; private set; } + public int tp_iter { get; private set; } + public int tp_iternext { get; private set; } + public int tp_methods { get; private set; } + public int tp_members { get; private set; } + public int tp_getset { get; private set; } + public int tp_base { get; private set; } + public int tp_dict { get; private set; } + public int tp_descr_get { get; private set; } + public int tp_descr_set { get; private set; } + public int tp_dictoffset { get; private set; } + public int tp_init { get; private set; } + public int tp_alloc { get; private set; } + public int tp_new { get; private set; } + public int tp_free { get; private set; } + public int tp_is_gc { get; private set; } + public int tp_bases { get; private set; } + public int tp_mro { get; private set; } + public int tp_cache { get; private set; } + public int tp_subclasses { get; private set; } + public int tp_weaklist { get; private set; } + public int tp_del { get; private set; } + public int tp_version_tag { get; private set; } + public int tp_finalize { get; private set; } + public int tp_vectorcall { get; private set; } + public int tp_watched { get; private set; } + public int am_await { get; private set; } + public int am_aiter { get; private set; } + public int am_anext { get; private set; } + public int am_send { get; private set; } + public int nb_add { get; private set; } + public int nb_subtract { get; private set; } + public int nb_multiply { get; private set; } + public int nb_remainder { get; private set; } + public int nb_divmod { get; private set; } + public int nb_power { get; private set; } + public int nb_negative { get; private set; } + public int nb_positive { get; private set; } + public int nb_absolute { get; private set; } + public int nb_bool { get; private set; } + public int nb_invert { get; private set; } + public int nb_lshift { get; private set; } + public int nb_rshift { get; private set; } + public int nb_and { get; private set; } + public int nb_xor { get; private set; } + public int nb_or { get; private set; } + public int nb_int { get; private set; } + public int nb_reserved { get; private set; } + public int nb_float { get; private set; } + public int nb_inplace_add { get; private set; } + public int nb_inplace_subtract { get; private set; } + public int nb_inplace_multiply { get; private set; } + public int nb_inplace_remainder { get; private set; } + public int nb_inplace_power { get; private set; } + public int nb_inplace_lshift { get; private set; } + public int nb_inplace_rshift { get; private set; } + public int nb_inplace_and { get; private set; } + public int nb_inplace_xor { get; private set; } + public int nb_inplace_or { get; private set; } + public int nb_floor_divide { get; private set; } + public int nb_true_divide { get; private set; } + public int nb_inplace_floor_divide { get; private set; } + public int nb_inplace_true_divide { get; private set; } + public int nb_index { get; private set; } + public int nb_matrix_multiply { get; private set; } + public int nb_inplace_matrix_multiply { get; private set; } + public int mp_length { get; private set; } + public int mp_subscript { get; private set; } + public int mp_ass_subscript { get; private set; } + public int sq_length { get; private set; } + public int sq_concat { get; private set; } + public int sq_repeat { get; private set; } + public int sq_item { get; private set; } + public int was_sq_slice { get; private set; } + public int sq_ass_item { get; private set; } + public int was_sq_ass_slice { get; private set; } + public int sq_contains { get; private set; } + public int sq_inplace_concat { get; private set; } + public int sq_inplace_repeat { get; private set; } + public int bf_getbuffer { get; private set; } + public int bf_releasebuffer { get; private set; } + public int name { get; private set; } + public int ht_slots { get; private set; } + public int qualname { get; private set; } + public int ht_cached_keys { get; private set; } + public int ht_module { get; private set; } + public int _ht_tpname { get; private set; } + public int spec_cache_getitem { get; private set; } + public int getitem_version { get; private set; } + } +} + diff --git a/tools/geninterop/geninterop.py b/tools/geninterop/geninterop.py index 78e4d45c2..6d80bcfa6 100755 --- a/tools/geninterop/geninterop.py +++ b/tools/geninterop/geninterop.py @@ -76,6 +76,8 @@ def visit(self, node): self.visit_ptrdecl(node) elif isinstance(node, c_ast.IdentifierType): self.visit_identifier(node) + elif isinstance(node, c_ast.Union): + self.visit_union(node) def visit_ast(self, ast): for _name, node in ast.children(): @@ -119,6 +121,16 @@ def visit_identifier(self, identifier): type_name = " ".join(identifier.names) self._add_struct_member(type_name) + def visit_union(self, union): + # Treat the field as if it was just the first declaration for now. This + # is not really correct, but handles the one case that is relevant for + # us right now (ob_refcnt being "split" in Python 3.12) + if self._struct_members_stack and union.decls: + decl = union.decls[0] + self._struct_members_stack.pop(0) + self._struct_members_stack.insert(0, decl.name) + self.visit(decl) + def _add_struct_member(self, type_name): if not (self._struct_stack and self._struct_members_stack): return @@ -245,7 +257,7 @@ def gen_interop_head(writer, version, abi_flags): // Auto-generated by {filename}. // DO NOT MODIFY BY HAND. -// Python {".".join(version[:2])}: ABI flags: '{abi_flags}' +// Python {".".join(map(str, version[:2]))}: ABI flags: '{abi_flags}' // ReSharper disable InconsistentNaming // ReSharper disable IdentifierTypo From 93d4119205a97d3631896e2163f145cd28b24c20 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 27 Sep 2023 12:57:18 +0200 Subject: [PATCH 06/15] Drop unused custom incref/decref --- src/runtime/Runtime.cs | 46 ------------------------------------------ 1 file changed, 46 deletions(-) diff --git a/src/runtime/Runtime.cs b/src/runtime/Runtime.cs index beb577e45..c7a954885 100644 --- a/src/runtime/Runtime.cs +++ b/src/runtime/Runtime.cs @@ -598,23 +598,8 @@ internal static void CheckExceptionOccurred() [Obsolete("Use NewReference or PyObject constructor instead")] internal static unsafe void XIncref(BorrowedReference op) { -#if !CUSTOM_INCDEC_REF Py_IncRef(op); return; -#else - var p = (void*)op; - if ((void*)0 != p) - { - if (Is32Bit) - { - (*(int*)p)++; - } - else - { - (*(long*)p)++; - } - } -#endif } internal static unsafe void XDecref(StolenReference op) @@ -623,40 +608,9 @@ internal static unsafe void XDecref(StolenReference op) Debug.Assert(op == null || Refcount(new BorrowedReference(op.Pointer)) > 0); Debug.Assert(_isInitialized || Py_IsInitialized() != 0 || _Py_IsFinalizing() != false); #endif -#if !CUSTOM_INCDEC_REF if (op == null) return; Py_DecRef(op.AnalyzerWorkaround()); return; -#else - var p = (void*)op; - if ((void*)0 != p) - { - if (Is32Bit) - { - --(*(int*)p); - } - else - { - --(*(long*)p); - } - if ((*(int*)p) == 0) - { - // PyObject_HEAD: struct _typeobject *ob_type - void* t = Is32Bit - ? (void*)(*((uint*)p + 1)) - : (void*)(*((ulong*)p + 1)); - // PyTypeObject: destructor tp_dealloc - void* f = Is32Bit - ? (void*)(*((uint*)t + 6)) - : (void*)(*((ulong*)t + 6)); - if ((void*)0 == f) - { - return; - } - NativeCall.Void_Call_1(new IntPtr(f), op); - } - } -#endif } [Pure] From 7a31d38755c71d0385bf28e758ab9cf96a2db481 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 27 Sep 2023 13:00:47 +0200 Subject: [PATCH 07/15] Add 3.12 to CI and metadata --- .github/workflows/main.yml | 2 +- pyproject.toml | 3 ++- src/runtime/PythonEngine.cs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 93963c70a..664dac9e6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: [windows, ubuntu, macos] - python: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12.0-rc.3"] platform: [x64, x86] exclude: - os: ubuntu diff --git a/pyproject.toml b/pyproject.toml index bf488bb92..4ece5f3a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ dependencies = [ "clr_loader>=0.2.6,<0.3.0" ] -requires-python = ">=3.7, <3.12" +requires-python = ">=3.7, <3.13" classifiers = [ "Development Status :: 5 - Production/Stable", @@ -26,6 +26,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Operating System :: MacOS :: MacOS X", diff --git a/src/runtime/PythonEngine.cs b/src/runtime/PythonEngine.cs index 4ed45b9e9..2c4c6c088 100644 --- a/src/runtime/PythonEngine.cs +++ b/src/runtime/PythonEngine.cs @@ -135,7 +135,7 @@ public static string PythonPath } public static Version MinSupportedVersion => new(3, 7); - public static Version MaxSupportedVersion => new(3, 11, int.MaxValue, int.MaxValue); + public static Version MaxSupportedVersion => new(3, 12, int.MaxValue, int.MaxValue); public static bool IsSupportedVersion(Version version) => version >= MinSupportedVersion && version <= MaxSupportedVersion; public static string Version From d057724e5167d7088a3dc77310a37c38473e318d Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 27 Sep 2023 13:01:59 +0200 Subject: [PATCH 08/15] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb13982e6..753d151c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. ### Added -- use enum name in repr +- Use enum name in `repr` +- Support for Python 3.12 ### Changed From 8dfe4080d642397a7efcb52b8d3aa69da1675713 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 27 Sep 2023 14:09:44 +0200 Subject: [PATCH 09/15] Remove deprecated function call --- src/runtime/Converter.cs | 6 ++---- src/runtime/Runtime.Delegates.cs | 4 ++-- src/runtime/Runtime.cs | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/runtime/Converter.cs b/src/runtime/Converter.cs index 73bbd4a3a..412f3b711 100644 --- a/src/runtime/Converter.cs +++ b/src/runtime/Converter.cs @@ -686,10 +686,8 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec { if (Runtime.PyUnicode_GetLength(value) == 1) { - IntPtr unicodePtr = Runtime.PyUnicode_AsUnicode(value); - Char[] buff = new Char[1]; - Marshal.Copy(unicodePtr, buff, 0, 1); - result = buff[0]; + int chr = Runtime.PyUnicode_ReadChar(value, 0); + result = (Char)chr; return true; } goto type_error; diff --git a/src/runtime/Runtime.Delegates.cs b/src/runtime/Runtime.Delegates.cs index 0b6b75872..6490c3fe5 100644 --- a/src/runtime/Runtime.Delegates.cs +++ b/src/runtime/Runtime.Delegates.cs @@ -164,8 +164,8 @@ static Delegates() PyUnicode_AsUTF8 = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUTF8), GetUnmanagedDll(_PythonDll)); PyUnicode_DecodeUTF16 = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_DecodeUTF16), GetUnmanagedDll(_PythonDll)); PyUnicode_GetLength = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_GetLength), GetUnmanagedDll(_PythonDll)); - PyUnicode_AsUnicode = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUnicode), GetUnmanagedDll(_PythonDll)); PyUnicode_AsUTF16String = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUTF16String), GetUnmanagedDll(_PythonDll)); + PyUnicode_ReadChar = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_ReadChar), GetUnmanagedDll(_PythonDll)); PyUnicode_FromOrdinal = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_FromOrdinal), GetUnmanagedDll(_PythonDll)); PyUnicode_InternFromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_InternFromString), GetUnmanagedDll(_PythonDll)); PyUnicode_Compare = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_Compare), GetUnmanagedDll(_PythonDll)); @@ -441,7 +441,7 @@ static Delegates() internal static delegate* unmanaged[Cdecl] PyUnicode_AsUTF8 { get; } internal static delegate* unmanaged[Cdecl] PyUnicode_DecodeUTF16 { get; } internal static delegate* unmanaged[Cdecl] PyUnicode_GetLength { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_AsUnicode { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_ReadChar { get; } internal static delegate* unmanaged[Cdecl] PyUnicode_AsUTF16String { get; } internal static delegate* unmanaged[Cdecl] PyUnicode_FromOrdinal { get; } internal static delegate* unmanaged[Cdecl] PyUnicode_InternFromString { get; } diff --git a/src/runtime/Runtime.cs b/src/runtime/Runtime.cs index c7a954885..eafe7f72c 100644 --- a/src/runtime/Runtime.cs +++ b/src/runtime/Runtime.cs @@ -1290,9 +1290,10 @@ internal static IntPtr PyBytes_AsString(BorrowedReference ob) internal static nint PyUnicode_GetLength(BorrowedReference ob) => Delegates.PyUnicode_GetLength(ob); - internal static IntPtr PyUnicode_AsUnicode(BorrowedReference ob) => Delegates.PyUnicode_AsUnicode(ob); internal static NewReference PyUnicode_AsUTF16String(BorrowedReference ob) => Delegates.PyUnicode_AsUTF16String(ob); + internal static int PyUnicode_ReadChar(BorrowedReference ob, nint index) => Delegates.PyUnicode_ReadChar(ob, index); + internal static NewReference PyUnicode_FromOrdinal(int c) => Delegates.PyUnicode_FromOrdinal(c); From 080d1bd59f2b231db2081474cf126e46aa039505 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 27 Sep 2023 16:26:39 +0200 Subject: [PATCH 10/15] For now skip over "new style" weakrefs in clear --- src/runtime/Runtime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/Runtime.cs b/src/runtime/Runtime.cs index eafe7f72c..4e1c6156a 100644 --- a/src/runtime/Runtime.cs +++ b/src/runtime/Runtime.cs @@ -939,7 +939,7 @@ internal static BorrowedReference PyObject_GetWeakRefList(BorrowedReference ob) Debug.Assert(ob != null); var type = PyObject_TYPE(ob); int offset = Util.ReadInt32(type, TypeOffset.tp_weaklistoffset); - if (offset == 0) return BorrowedReference.Null; + if (offset <= 0) return BorrowedReference.Null; Debug.Assert(offset > 0); return Util.ReadRef(ob, offset); } From fb494705652af998a4f346aeb88ebff836c72eb4 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Mon, 2 Oct 2023 21:06:16 +0000 Subject: [PATCH 11/15] Ignore test-case on Python 3.12 --- src/embed_tests/Codecs.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/embed_tests/Codecs.cs b/src/embed_tests/Codecs.cs index 9b764d43f..c8b8ecb6e 100644 --- a/src/embed_tests/Codecs.cs +++ b/src/embed_tests/Codecs.cs @@ -371,11 +371,23 @@ public void FloatDerivedDecoded() [Test] public void ExceptionDecodedNoInstance() { - PyObjectConversions.RegisterDecoder(new InstancelessExceptionDecoder()); - using var scope = Py.CreateScope(); - var error = Assert.Throws(() => PythonEngine.Exec( - $"[].__iter__().__next__()")); - Assert.AreEqual(TestExceptionMessage, error.Message); + if (Runtime.PyVersion < new Version(3, 12)) + { + PyObjectConversions.RegisterDecoder(new InstancelessExceptionDecoder()); + using var scope = Py.CreateScope(); + + var error = Assert.Throws(() => + PythonEngine.Exec($"[].__iter__().__next__()") + ); + Assert.AreEqual(TestExceptionMessage, error.Message); + } + else + { + Assert.Ignore( + "This test does not work for Python 3.12, see " + + "https://github.com/python/cpython/issues/101578" + ); + } } public static void AcceptsDateTime(DateTime v) {} From 293f8b1d810db1e63253b950a4b4844b35c38bab Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 3 Oct 2023 15:26:47 +0200 Subject: [PATCH 12/15] Python 3.12 has been released, use final version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 664dac9e6..c4af10c68 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: [windows, ubuntu, macos] - python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12.0-rc.3"] + python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] platform: [x64, x86] exclude: - os: ubuntu From 04670ea1c8a761944e19ac89acd18a43a82cc352 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 6 Oct 2023 03:57:00 -0700 Subject: [PATCH 13/15] only run docs CI/main CI for corresponding changes (#2257) --- .github/workflows/ARM.yml | 8 ++++++++ .github/workflows/docs.yml | 10 +++++++++- .github/workflows/main.yml | 8 ++++++++ pythonnet.sln | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ARM.yml b/.github/workflows/ARM.yml index eef0e666d..d4a5cb008 100644 --- a/.github/workflows/ARM.yml +++ b/.github/workflows/ARM.yml @@ -4,7 +4,15 @@ on: push: branches: - master + paths-ignore: + - .github/workflows/main.yml + - .github/workflows/nuget-preview.yml + - 'doc/**' pull_request: + paths-ignore: + - .github/workflows/main.yml + - .github/workflows/nuget-preview.yml + - 'doc/**' jobs: build-test-arm: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 5b782c8b4..65a6ef69c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,6 +1,14 @@ name: Documentation -on: [push, pull_request] +on: + push: + paths: + - 'doc/**' + - '.github/workflows/docs.yml' + pull_request: + paths: + - 'doc/**' + - '.github/workflows/docs.yml' jobs: build: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c4af10c68..17d7bb4b2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,15 @@ on: push: branches: - master + paths-ignore: + - .github/workflows/ARM.yml + - .github/workflows/nuget-preview.yml + - 'doc/**' pull_request: + paths-ignore: + - .github/workflows/ARM.yml + - .github/workflows/nuget-preview.yml + - 'doc/**' jobs: build-test: diff --git a/pythonnet.sln b/pythonnet.sln index d1a47892e..ce45270e3 100644 --- a/pythonnet.sln +++ b/pythonnet.sln @@ -27,6 +27,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{D301657F-5EAF-4534-B280-B858D651B2E5}" ProjectSection(SolutionItems) = preProject .github\workflows\ARM.yml = .github\workflows\ARM.yml + .github\workflows\docs.yml = .github\workflows\docs.yml .github\workflows\main.yml = .github\workflows\main.yml .github\workflows\nuget-preview.yml = .github\workflows\nuget-preview.yml EndProjectSection From 5a4a986f9e2b9f4f505db68809f45a63c39b1418 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Fri, 6 Oct 2023 12:59:57 +0200 Subject: [PATCH 14/15] Revert "only run docs CI/main CI for corresponding changes (#2257)" (#2260) This reverts commit 04670ea1c8a761944e19ac89acd18a43a82cc352. --- .github/workflows/ARM.yml | 8 -------- .github/workflows/docs.yml | 10 +--------- .github/workflows/main.yml | 8 -------- pythonnet.sln | 1 - 4 files changed, 1 insertion(+), 26 deletions(-) diff --git a/.github/workflows/ARM.yml b/.github/workflows/ARM.yml index d4a5cb008..eef0e666d 100644 --- a/.github/workflows/ARM.yml +++ b/.github/workflows/ARM.yml @@ -4,15 +4,7 @@ on: push: branches: - master - paths-ignore: - - .github/workflows/main.yml - - .github/workflows/nuget-preview.yml - - 'doc/**' pull_request: - paths-ignore: - - .github/workflows/main.yml - - .github/workflows/nuget-preview.yml - - 'doc/**' jobs: build-test-arm: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 65a6ef69c..5b782c8b4 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,14 +1,6 @@ name: Documentation -on: - push: - paths: - - 'doc/**' - - '.github/workflows/docs.yml' - pull_request: - paths: - - 'doc/**' - - '.github/workflows/docs.yml' +on: [push, pull_request] jobs: build: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 17d7bb4b2..c4af10c68 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,15 +4,7 @@ on: push: branches: - master - paths-ignore: - - .github/workflows/ARM.yml - - .github/workflows/nuget-preview.yml - - 'doc/**' pull_request: - paths-ignore: - - .github/workflows/ARM.yml - - .github/workflows/nuget-preview.yml - - 'doc/**' jobs: build-test: diff --git a/pythonnet.sln b/pythonnet.sln index ce45270e3..d1a47892e 100644 --- a/pythonnet.sln +++ b/pythonnet.sln @@ -27,7 +27,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{D301657F-5EAF-4534-B280-B858D651B2E5}" ProjectSection(SolutionItems) = preProject .github\workflows\ARM.yml = .github\workflows\ARM.yml - .github\workflows\docs.yml = .github\workflows\docs.yml .github\workflows\main.yml = .github\workflows\main.yml .github\workflows\nuget-preview.yml = .github\workflows\nuget-preview.yml EndProjectSection From 0a5a63ccc4ee1e104ab0aae75ede8aa3441a3481 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Wed, 11 Oct 2023 09:12:36 +0200 Subject: [PATCH 15/15] Release 3.0.3 --- CHANGELOG.md | 5 ++--- version.txt | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 753d151c9..411356775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,16 +5,15 @@ project adheres to [Semantic Versioning][]. This document follows the conventions laid out in [Keep a CHANGELOG][]. -## [Unreleased][] +## [3.0.3](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.3) - 2023-10-11 ### Added -- Use enum name in `repr` - Support for Python 3.12 ### Changed -### Fixed +- Use enum name in `repr` ## [3.0.2](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.2) - 2023-08-29 diff --git a/version.txt b/version.txt index 0f9d6b15d..75a22a26a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.1.0-dev +3.0.3