diff --git a/src/embed_tests/Python.EmbeddingTest.csproj b/src/embed_tests/Python.EmbeddingTest.csproj index 8f2db8efe..1bb4fed11 100644 --- a/src/embed_tests/Python.EmbeddingTest.csproj +++ b/src/embed_tests/Python.EmbeddingTest.csproj @@ -12,6 +12,10 @@ + + $(DefineConstants);$(ConfiguredConstants) + + diff --git a/src/embed_tests/TestNativeTypeOffset.cs b/src/embed_tests/TestNativeTypeOffset.cs new file mode 100644 index 000000000..03812c6fe --- /dev/null +++ b/src/embed_tests/TestNativeTypeOffset.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +using NUnit.Framework; + +using Python.Runtime; + +namespace Python.EmbeddingPythonTest +{ + public class TestNativeTypeOffset + { + private Py.GILState _gs; + + [SetUp] + public void SetUp() + { + _gs = Py.GIL(); + } + + [TearDown] + public void Dispose() + { + _gs.Dispose(); + } + + /// + /// Tests that installation has generated code for NativeTypeOffset and that it can be loaded. + /// + [Test] + public void LoadNativeTypeOffsetClass() + { + PyObject sys = Py.Import("sys"); + string attributeName = "abiflags"; + if (sys.HasAttr(attributeName) && !string.IsNullOrEmpty(sys.GetAttr(attributeName).ToString())) + { + string typeName = "Python.Runtime.NativeTypeOffset, Python.Runtime"; + Assert.NotNull(Type.GetType(typeName), $"{typeName} does not exist and sys.{attributeName} is not empty"); + } + } + } +} diff --git a/src/runtime/Python.Runtime.csproj b/src/runtime/Python.Runtime.csproj index acb8efc4e..f18cf7a49 100644 --- a/src/runtime/Python.Runtime.csproj +++ b/src/runtime/Python.Runtime.csproj @@ -19,12 +19,6 @@ $(DefineConstants);$(ConfiguredConstants) - - - - - - diff --git a/src/runtime/native/ABI.cs b/src/runtime/native/ABI.cs index 76337c797..e95b259c5 100644 --- a/src/runtime/native/ABI.cs +++ b/src/runtime/native/ABI.cs @@ -22,7 +22,12 @@ internal static void Initialize(Version version, BorrowedReference pyType) thisAssembly.GetType(nativeTypeOffsetClassName, throwOnError: false) ?? thisAssembly.GetType(className, throwOnError: false); if (typeOffsetsClass is null) - throw new NotSupportedException($"Python ABI v{version} is not supported"); + { + var types = thisAssembly.GetTypes().Select(type => type.Name).Where(name => name.StartsWith("TypeOffset")); + string message = $"Searching for {className}, found {string.Join(",", types)}. " + + "If you are building Python.NET from source, make sure you have run 'python setup.py configure' to fill in configured.props"; + throw new NotSupportedException($"Python ABI v{version} is not supported: {message}"); + } var typeOffsets = (ITypeOffsets)Activator.CreateInstance(typeOffsetsClass); TypeOffset.Use(typeOffsets);