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

Commit916e85e

Browse files
committed
Merge remote-tracking branch 'remotes/upstream/master' into pyobject-finalizer
2 parents5254c65 +d3ca2e8 commit916e85e

35 files changed

+432
-64
lines changed

‎AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- Sam Winstanley ([@swinstanley](https://github.com/swinstanley))
4343
- Sean Freitag ([@cowboygneox](https://github.com/cowboygneox))
4444
- Serge Weinstock ([@sweinst](https://github.com/sweinst))
45+
- Simon Mourier ([@smourier](https://github.com/smourier))
4546
- Viktoria Kovescses ([@vkovec](https://github.com/vkovec))
4647
- Ville M. Vainio ([@vivainio](https://github.com/vivainio))
4748
- Virgil Dupras ([@hsoft](https://github.com/hsoft))

‎CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
88
##[unreleased][]
99

1010
###Added
11+
1112
- Added support for embedding python into dotnet core 2.0 (NetStandard 2.0)
1213
- Added new build system (pythonnet.15.sln) based on dotnetcore-sdk/xplat(crossplatform msbuild).
1314
Currently there two side-by-side build systems that produces the same output (net40) from the same sources.
1415
After a some transition time, current (mono/ msbuild 14.0) build system will be removed.
1516
- NUnit upgraded to 3.7 (eliminates travis-ci random bug)
17+
- Added C#`PythonEngine.AddShutdownHandler` to help client code clean up on shutdown.
1618
- Added`clr.GetClrType` ([#432][i432])([#433][p433])
1719
- Allowed passing`None` for nullable args ([#460][p460])
1820
- Added keyword arguments based on C# syntax for calling CPython methods ([#461][p461])
@@ -26,8 +28,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2628
###Changed
2729
- PythonException included C# call stack
2830

31+
- Reattach python exception traceback information (#545)
32+
- PythonEngine.Intialize will now call`Py_InitializeEx` with a default value of 0, so signals will not be configured by default on embedding. This is different from the previous behaviour, where`Py_Initialize` was called instead, which sets initSigs to 1. ([#449][i449])
33+
2934
###Fixed
3035

36+
- Fixed secondary PythonEngine.Initialize call, all sensitive static variables now reseted.
37+
This is a hidden bug. Once python cleaning up enough memory, objects from previous engine run becomes corrupted. ([#534][p534])
3138
- Fixed Visual Studio 2017 compat ([#434][i434]) for setup.py
3239
- Fixed crashes when integrating pythonnet in Unity3d ([#714][i714]),
3340
related to unloading the Application Domain
@@ -43,6 +50,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
4350
- Fixed errors breaking .NET Remoting on method invoke ([#276][i276])
4451
- Fixed PyObject.GetHashCode ([#676][i676])
4552
- Fix memory leaks due to spurious handle incrementation ([#691][i691])
53+
- Fix spurious assembly loading exceptions from private types ([#703][i703])
54+
- Fix inheritance of non-abstract base methods ([#755][i755])
4655

4756

4857
##[2.3.0][] - 2017-03-11
@@ -600,6 +609,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
600609

601610
[1.0.0]:https://github.com/pythonnet/pythonnet/releases/tag/1.0
602611

612+
[i714]:https://github.com/pythonnet/pythonnet/issues/714
603613
[i608]:https://github.com/pythonnet/pythonnet/issues/608
604614
[i443]:https://github.com/pythonnet/pythonnet/issues/443
605615
[p690]:https://github.com/pythonnet/pythonnet/pull/690
@@ -693,3 +703,6 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
693703
[p625]:https://github.com/pythonnet/pythonnet/pull/625
694704
[i131]:https://github.com/pythonnet/pythonnet/issues/131
695705
[p531]:https://github.com/pythonnet/pythonnet/pull/531
706+
[i755]:https://github.com/pythonnet/pythonnet/pull/755
707+
[p534]:https://github.com/pythonnet/pythonnet/pull/534
708+
[i449]:https://github.com/pythonnet/pythonnet/issues/449

‎NuGet.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<packageSources>
44
<addkey="dot-net MyGet Feed"value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json"protocolVersion="3"/>

‎setup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,16 @@ def _install_packages(self):
329329
self.debug_print("Updating NuGet: {0}".format(cmd))
330330
subprocess.check_call(cmd,shell=use_shell)
331331

332-
cmd="{0} restore pythonnet.sln -MSBuildVersion 14 -o packages".format(nuget)
333-
self.debug_print("Installing packages: {0}".format(cmd))
334-
subprocess.check_call(cmd,shell=use_shell)
332+
try:
333+
# msbuild=14 is mainly for Mono issues
334+
cmd="{0} restore pythonnet.sln -MSBuildVersion 14 -o packages".format(nuget)
335+
self.debug_print("Installing packages: {0}".format(cmd))
336+
subprocess.check_call(cmd,shell=use_shell)
337+
except:
338+
# when only VS 2017 is installed do not specify msbuild version
339+
cmd="{0} restore pythonnet.sln -o packages".format(nuget)
340+
self.debug_print("Installing packages: {0}".format(cmd))
341+
subprocess.check_call(cmd,shell=use_shell)
335342

336343
def_find_msbuild_tool(self,tool="msbuild.exe",use_windows_sdk=False):
337344
"""Return full path to one of the Microsoft build tools"""

‎src/embed_tests/GlobalTestsSetup.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
usingNUnit.Framework;
2+
usingPython.Runtime;
3+
4+
namespacePython.EmbeddingTest
5+
{
6+
7+
// As the SetUpFixture, the OneTimeTearDown of this class is executed after
8+
// all tests have run.
9+
[SetUpFixture]
10+
publicclassGlobalTestsSetup
11+
{
12+
[OneTimeTearDown]
13+
publicvoidFinalCleanup()
14+
{
15+
if(PythonEngine.IsInitialized)
16+
{
17+
PythonEngine.Shutdown();
18+
}
19+
}
20+
}
21+
}

‎src/embed_tests/Python.EmbeddingTest.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
33
<PropertyGroup>
44
<ConfigurationCondition=" '$(Configuration)' == ''">Debug</Configuration>
@@ -106,6 +106,7 @@
106106
<CompileInclude="TestRuntime.cs" />
107107
<CompileInclude="TestPyScope.cs" />
108108
<CompileInclude="TestTypeManager.cs" />
109+
<CompileInclude="GlobalTestsSetup.cs" />
109110
</ItemGroup>
110111
<ItemGroup>
111112
<ProjectReferenceInclude="..\runtime\Python.Runtime.csproj">

‎src/embed_tests/TestConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usingNUnit.Framework;
1+
usingNUnit.Framework;
22
usingPython.Runtime;
33

44
namespacePython.EmbeddingTest

‎src/embed_tests/TestNamedArguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usingSystem;
1+
usingSystem;
22
usingNUnit.Framework;
33
usingPython.Runtime;
44

‎src/embed_tests/TestPyObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usingSystem;
1+
usingSystem;
22
usingSystem.Collections.Generic;
33
usingSystem.Linq;
44
usingNUnit.Framework;

‎src/embed_tests/TestPyWith.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usingSystem;
1+
usingSystem;
22
usingNUnit.Framework;
33
usingPython.Runtime;
44

‎src/embed_tests/TestPythonEngineProperties.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,41 @@ public static void GetPythonHomeDefault()
109109
[Test]
110110
publicvoidSetPythonHome()
111111
{
112+
// We needs to ensure that engine was started and shutdown at least once before setting dummy home.
113+
// Otherwise engine will not run with dummy path with random problem.
114+
if(!PythonEngine.IsInitialized)
115+
{
116+
PythonEngine.Initialize();
117+
}
118+
119+
PythonEngine.Shutdown();
120+
121+
varpythonHomeBackup=PythonEngine.PythonHome;
122+
112123
varpythonHome="/dummypath/";
113124

114125
PythonEngine.PythonHome=pythonHome;
115126
PythonEngine.Initialize();
116127

117-
Assert.AreEqual(pythonHome,PythonEngine.PythonHome);
118128
PythonEngine.Shutdown();
129+
130+
// Restoring valid pythonhome.
131+
PythonEngine.PythonHome=pythonHomeBackup;
119132
}
120133

121134
[Test]
122135
publicvoidSetPythonHomeTwice()
123136
{
137+
// We needs to ensure that engine was started and shutdown at least once before setting dummy home.
138+
// Otherwise engine will not run with dummy path with random problem.
139+
if(!PythonEngine.IsInitialized)
140+
{
141+
PythonEngine.Initialize();
142+
}
143+
PythonEngine.Shutdown();
144+
145+
varpythonHomeBackup=PythonEngine.PythonHome;
146+
124147
varpythonHome="/dummypath/";
125148

126149
PythonEngine.PythonHome="/dummypath2/";
@@ -129,18 +152,29 @@ public void SetPythonHomeTwice()
129152

130153
Assert.AreEqual(pythonHome,PythonEngine.PythonHome);
131154
PythonEngine.Shutdown();
155+
156+
PythonEngine.PythonHome=pythonHomeBackup;
132157
}
133158

134159
[Test]
135160
publicvoidSetProgramName()
136161
{
162+
if(PythonEngine.IsInitialized)
163+
{
164+
PythonEngine.Shutdown();
165+
}
166+
167+
varprogramNameBackup=PythonEngine.ProgramName;
168+
137169
varprogramName="FooBar";
138170

139171
PythonEngine.ProgramName=programName;
140172
PythonEngine.Initialize();
141173

142174
Assert.AreEqual(programName,PythonEngine.ProgramName);
143175
PythonEngine.Shutdown();
176+
177+
PythonEngine.ProgramName=programNameBackup;
144178
}
145179

146180
[Test]
@@ -156,7 +190,7 @@ public void SetPythonPath()
156190
stringpath=PythonEngine.PythonPath;
157191
PythonEngine.Shutdown();
158192

159-
PythonEngine.ProgramName=path;
193+
PythonEngine.PythonPath=path;
160194
PythonEngine.Initialize();
161195

162196
Assert.AreEqual(path,PythonEngine.PythonPath);
@@ -171,7 +205,6 @@ public void SetPythonPathExceptionOn27()
171205
Assert.Pass();
172206
}
173207

174-
// Get previous path to avoid crashing Python
175208
PythonEngine.Initialize();
176209
stringpath=PythonEngine.PythonPath;
177210
PythonEngine.Shutdown();

‎src/embed_tests/TestRuntime.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
usingSystem;
1+
usingSystem;
22
usingNUnit.Framework;
33
usingPython.Runtime;
44

55
namespacePython.EmbeddingTest
66
{
77
publicclassTestRuntime
88
{
9+
[OneTimeSetUp]
10+
publicvoidSetUp()
11+
{
12+
// We needs to ensure that no any engines are running.
13+
if(PythonEngine.IsInitialized)
14+
{
15+
PythonEngine.Shutdown();
16+
}
17+
}
18+
919
/// <summary>
1020
/// Test the cache of the information from the platform module.
1121
///
@@ -24,12 +34,12 @@ public static void PlatformCache()
2434

2535
// Don't shut down the runtime: if the python engine was initialized
2636
// but not shut down by another test, we'd end up in a bad state.
27-
}
37+
}
2838

2939
[Test]
3040
publicstaticvoidPy_IsInitializedValue()
3141
{
32-
Runtime.Runtime.Py_Finalize();// In case another test left it on.
42+
Runtime.Runtime.Py_Finalize();
3343
Assert.AreEqual(0,Runtime.Runtime.Py_IsInitialized());
3444
Runtime.Runtime.Py_Initialize();
3545
Assert.AreEqual(1,Runtime.Runtime.Py_IsInitialized());

‎src/embed_tests/dynamic.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ public void PassPyObjectInNet()
128128
sys.testattr2=sys.testattr1;
129129

130130
// Compare in Python
131-
PyObjectres=PythonEngine.RunString(
131+
PythonEngine.RunSimpleString(
132132
"import sys\n"+
133133
"sys.testattr3 = sys.testattr1 is sys.testattr2\n"
134134
);
135+
135136
Assert.AreEqual(sys.testattr3.ToString(),"True");
136137

137138
// Compare in .NET

‎src/embed_tests/pyinitialize.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,65 @@ public void ReInitialize()
7474
}
7575
PythonEngine.Shutdown();
7676
}
77+
78+
[Test]
79+
publicvoidTestScopeIsShutdown()
80+
{
81+
PythonEngine.Initialize();
82+
varscope=PyScopeManager.Global.Create("test");
83+
PythonEngine.Shutdown();
84+
Assert.That(PyScopeManager.Global.Contains("test"),Is.False);
85+
}
86+
87+
/// <summary>
88+
/// Helper for testing the shutdown handlers.
89+
/// </summary>
90+
intshutdown_count=0;
91+
voidOnShutdownIncrement()
92+
{
93+
shutdown_count++;
94+
}
95+
voidOnShutdownDouble()
96+
{
97+
shutdown_count*=2;
98+
}
99+
100+
/// <summary>
101+
/// Test the shutdown handlers.
102+
/// </summary>
103+
[Test]
104+
publicvoidShutdownHandlers()
105+
{
106+
// Test we can run one shutdown handler.
107+
shutdown_count=0;
108+
PythonEngine.Initialize();
109+
PythonEngine.AddShutdownHandler(OnShutdownIncrement);
110+
PythonEngine.Shutdown();
111+
Assert.That(shutdown_count,Is.EqualTo(1));
112+
113+
// Test we can run multiple shutdown handlers in the right order.
114+
shutdown_count=4;
115+
PythonEngine.Initialize();
116+
PythonEngine.AddShutdownHandler(OnShutdownIncrement);
117+
PythonEngine.AddShutdownHandler(OnShutdownDouble);
118+
PythonEngine.Shutdown();
119+
// Correct: 4 * 2 + 1 = 9
120+
// Wrong: (4 + 1) * 2 = 10
121+
Assert.That(shutdown_count,Is.EqualTo(9));
122+
123+
// Test we can remove shutdown handlers, handling duplicates.
124+
shutdown_count=4;
125+
PythonEngine.Initialize();
126+
PythonEngine.AddShutdownHandler(OnShutdownIncrement);
127+
PythonEngine.AddShutdownHandler(OnShutdownIncrement);
128+
PythonEngine.AddShutdownHandler(OnShutdownDouble);
129+
PythonEngine.AddShutdownHandler(OnShutdownIncrement);
130+
PythonEngine.AddShutdownHandler(OnShutdownDouble);
131+
PythonEngine.RemoveShutdownHandler(OnShutdownDouble);
132+
PythonEngine.Shutdown();
133+
// Correct: (4 + 1) * 2 + 1 + 1 = 12
134+
// Wrong: (4 * 2) + 1 + 1 + 1 = 11
135+
Assert.That(shutdown_count,Is.EqualTo(12));
136+
}
77137
}
78138
}

‎src/runtime/Python.Runtime.15.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131

132132
<TargetName="BeforeBuild"Condition="'$(TargetFramework)'=='net40' AND $(Configuration.Contains('Mono')) AND '$(OS)' != 'Windows_NT'">
133133
<!--Endless war!-->
134-
<ExecCommand="cp $(NuGetPackageRoot)/microsoft.targetingpack.netframework.v4.5/1.0.1/lib/net45/System.XML.dll $(NuGetPackageRoot)/microsoft.targetingpack.netframework.v4.5/1.0.1/lib/net45/System.Xml.dll" />
134+
<ExecCommand="[[ -e $(NuGetPackageRoot)/microsoft.targetingpack.netframework.v4.5/1.0.1/lib/net45/System.Xml.dll ]] ||cp $(NuGetPackageRoot)/microsoft.targetingpack.netframework.v4.5/1.0.1/lib/net45/System.XML.dll $(NuGetPackageRoot)/microsoft.targetingpack.netframework.v4.5/1.0.1/lib/net45/System.Xml.dll" />
135135
</Target>
136136
<TargetName="AfterBuild">
137137
<CopyCondition="'$(TargetFramework)'=='net40'"SourceFiles="$(TargetAssembly)"DestinationFolder="$(PythonBuildDir)" />

‎src/runtime/Python.Runtime.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
33
<PropertyGroup>
44
<ConfigurationCondition=" '$(Configuration)' == ''">Debug</Configuration>
@@ -149,6 +149,7 @@
149149
<CompileInclude="interop34.cs" />
150150
<CompileInclude="interop35.cs" />
151151
<CompileInclude="interop36.cs" />
152+
<CompileInclude="interop37.cs" />
152153
</ItemGroup>
153154
<ItemGroup>
154155
<NoneInclude="..\pythonnet.snk" />

‎src/runtime/Util.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usingSystem;
1+
usingSystem;
22
usingSystem.Runtime.InteropServices;
33

44
namespacePython.Runtime

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp