Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcac82a6

Browse files
authored
ABI.Initialize gives a helpful message when the TypeOffset interop class is not configured correctly (#1340)
+ Added LoadNativeTypeOffsetClass test* Remove reference to PythonInteropFile
1 parent1f40564 commitcac82a6

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

‎src/embed_tests/Python.EmbeddingTest.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<NoneInclude="fixtures/**/*.py"CopyToOutputDirectory="PreserveNewest" />
1313
</ItemGroup>
1414

15+
<PropertyGroup>
16+
<DefineConstants>$(DefineConstants);$(ConfiguredConstants)</DefineConstants>
17+
</PropertyGroup>
18+
1519
<ItemGroup>
1620
<PackageReferenceInclude="NUnit"Version="3.*" />
1721
<PackageReferenceInclude="NUnit3TestAdapter"Version="3.*">
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
usingSystem;
2+
usingSystem.Collections.Generic;
3+
usingSystem.Linq;
4+
usingSystem.Reflection;
5+
usingSystem.Text;
6+
usingSystem.Threading.Tasks;
7+
8+
usingNUnit.Framework;
9+
10+
usingPython.Runtime;
11+
12+
namespacePython.EmbeddingPythonTest
13+
{
14+
publicclassTestNativeTypeOffset
15+
{
16+
privatePy.GILState_gs;
17+
18+
[SetUp]
19+
publicvoidSetUp()
20+
{
21+
_gs=Py.GIL();
22+
}
23+
24+
[TearDown]
25+
publicvoidDispose()
26+
{
27+
_gs.Dispose();
28+
}
29+
30+
/// <summary>
31+
/// Tests that installation has generated code for NativeTypeOffset and that it can be loaded.
32+
/// </summary>
33+
[Test]
34+
publicvoidLoadNativeTypeOffsetClass()
35+
{
36+
PyObjectsys=Py.Import("sys");
37+
stringattributeName="abiflags";
38+
if(sys.HasAttr(attributeName)&&!string.IsNullOrEmpty(sys.GetAttr(attributeName).ToString()))
39+
{
40+
stringtypeName="Python.Runtime.NativeTypeOffset, Python.Runtime";
41+
Assert.NotNull(Type.GetType(typeName),$"{typeName} does not exist and sys.{attributeName} is not empty");
42+
}
43+
}
44+
}
45+
}

‎src/runtime/Python.Runtime.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
<DefineConstants>$(DefineConstants);$(ConfiguredConstants)</DefineConstants>
2020
</PropertyGroup>
2121

22-
<ItemGroupCondition=" '$(PythonInteropFile)' != ''">
23-
<CompileRemove="interop*.cs" />
24-
<CompileInclude="interop.cs" />
25-
<CompileInclude="$(PythonInteropFile)" />
26-
</ItemGroup>
27-
2822
<ItemGroup>
2923
<NoneRemove="resources\clr.py" />
3024
<EmbeddedResourceInclude="resources\clr.py">

‎src/runtime/native/ABI.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ internal static void Initialize(Version version, BorrowedReference pyType)
2222
thisAssembly.GetType(nativeTypeOffsetClassName,throwOnError:false)
2323
??thisAssembly.GetType(className,throwOnError:false);
2424
if(typeOffsetsClassisnull)
25-
thrownewNotSupportedException($"Python ABI v{version} is not supported");
25+
{
26+
vartypes=thisAssembly.GetTypes().Select(type=>type.Name).Where(name=>name.StartsWith("TypeOffset"));
27+
stringmessage=$"Searching for{className}, found{string.Join(",",types)}. "+
28+
"If you are building Python.NET from source, make sure you have run 'python setup.py configure' to fill in configured.props";
29+
thrownewNotSupportedException($"Python ABI v{version} is not supported:{message}");
30+
}
2631
vartypeOffsets=(ITypeOffsets)Activator.CreateInstance(typeOffsetsClass);
2732
TypeOffset.Use(typeOffsets);
2833

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp