Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44d65d9

Browse files
committed
merge latest master
2 parents a3591b6 + b7e8fdc commit 44d65d9

33 files changed

+399
-316
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131

3232
- name: Setup .NET
3333
uses: actions/setup-dotnet@v1
34+
with:
35+
dotnet-version: '6.0.x'
3436

3537
- name: Set up Python ${{ matrix.python }}
3638
uses: actions/setup-python@v2

.github/workflows/nuget-preview.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525

2626
- name: Setup .NET
2727
uses: actions/setup-dotnet@v1
28+
with:
29+
dotnet-version: '6.0.x'
2830

2931
- name: Set up Python 3.8
3032
uses: actions/setup-python@v2

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
12-
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.0.0-5.final">
12+
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.0.1">
1313
<PrivateAssets>all</PrivateAssets>
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1515
</PackageReference>

README.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pythonnet - Python.NET
33

44
|Join the chat at https://gitter.im/pythonnet/pythonnet| |stackexchange shield|
55

6-
|gh shield| |appveyor shield|
6+
|gh shield|
77

88
|license shield|
99

@@ -49,7 +49,7 @@ Embedding Python in .NET
4949
starting with version 3.0, otherwise you will receive ``BadPythonDllException``
5050
(internal, derived from ``MissingMethodException``) upon calling ``Initialize``.
5151
Typical values are ``python38.dll`` (Windows), ``libpython3.8.dylib`` (Mac),
52-
``libpython3.8.so`` (most other *nix).
52+
``libpython3.8.so`` (most other Unix-like operating systems).
5353
- All calls to python should be inside a
5454
``using (Py.GIL()) {/* Your code here */}`` block.
5555
- Import python modules using ``dynamic mod = Py.Import("mod")``, then
@@ -123,12 +123,6 @@ This project is supported by the `.NET Foundation <https://dotnetfoundation.org>
123123

124124
.. |Join the chat at https://gitter.im/pythonnet/pythonnet| image:: https://badges.gitter.im/pythonnet/pythonnet.svg
125125
:target: https://gitter.im/pythonnet/pythonnet?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
126-
.. |appveyor shield| image:: https://img.shields.io/appveyor/ci/pythonnet/pythonnet/master.svg?label=AppVeyor
127-
:target: https://ci.appveyor.com/project/pythonnet/pythonnet/branch/master
128-
.. |travis shield| image:: https://img.shields.io/travis/pythonnet/pythonnet/master.svg?label=Travis
129-
:target: https://travis-ci.org/pythonnet/pythonnet
130-
.. |codecov shield| image:: https://img.shields.io/codecov/c/github/pythonnet/pythonnet/master.svg?label=Codecov
131-
:target: https://codecov.io/github/pythonnet/pythonnet
132126
.. |license shield| image:: https://img.shields.io/badge/license-MIT-blue.svg?maxAge=3600
133127
:target: ./LICENSE
134128
.. |pypi package version| image:: https://img.shields.io/pypi/v/pythonnet.svg

pythonnet.sln

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 16
3-
VisualStudioVersion = 16.0.30717.126
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.0.31912.275
44
MinimumVisualStudioVersion = 15.0.26124.0
55
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime", "src\runtime\Python.Runtime.csproj", "{4E8C8FE2-0FB8-4517-B2D9-5FB2D5FC849B}"
66
EndProject
@@ -25,9 +25,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Repo", "Repo", "{441A0123-F
2525
EndProject
2626
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{D301657F-5EAF-4534-B280-B858D651B2E5}"
2727
ProjectSection(SolutionItems) = preProject
28-
appveyor.yml = appveyor.yml
29-
ci\appveyor_build_recipe.ps1 = ci\appveyor_build_recipe.ps1
30-
ci\appveyor_run_tests.ps1 = ci\appveyor_run_tests.ps1
3128
.github\workflows\main.yml = .github\workflows\main.yml
3229
.github\workflows\nuget-preview.yml = .github\workflows\nuget-preview.yml
3330
EndProjectSection
@@ -37,13 +34,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
3734
setup.py = setup.py
3835
EndProjectSection
3936
EndProject
40-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "conda.recipe", "conda.recipe", "{7FD2404D-0CE8-4645-8DFB-766470E2150E}"
41-
ProjectSection(SolutionItems) = preProject
42-
conda.recipe\bld.bat = conda.recipe\bld.bat
43-
conda.recipe\meta.yaml = conda.recipe\meta.yaml
44-
conda.recipe\README.md = conda.recipe\README.md
45-
EndProjectSection
46-
EndProject
4737
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{BC426F42-8494-4AA5-82C9-5109ACD97BD1}"
4838
ProjectSection(SolutionItems) = preProject
4939
tools\geninterop\geninterop.py = tools\geninterop\geninterop.py
@@ -90,18 +80,6 @@ Global
9080
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Release|x64.Build.0 = Release|x64
9181
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Release|x86.ActiveCfg = Release|x86
9282
{E6B01706-00BA-4144-9029-186AC42FBE9A}.Release|x86.Build.0 = Release|x86
93-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
94-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
95-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Debug|x64.ActiveCfg = Debug|Any CPU
96-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Debug|x64.Build.0 = Debug|Any CPU
97-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Debug|x86.ActiveCfg = Debug|Any CPU
98-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Debug|x86.Build.0 = Debug|Any CPU
99-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
100-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Release|Any CPU.Build.0 = Release|Any CPU
101-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Release|x64.ActiveCfg = Release|Any CPU
102-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Release|x64.Build.0 = Release|Any CPU
103-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Release|x86.ActiveCfg = Release|Any CPU
104-
{F9F5FA13-BC52-4C0B-BC1C-FE3C0B8FCCDD}.Release|x86.Build.0 = Release|Any CPU
10583
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10684
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Debug|Any CPU.Build.0 = Debug|Any CPU
10785
{819E089B-4770-400E-93C6-4F7A35F0EA12}.Debug|x64.ActiveCfg = Debug|Any CPU

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
PY_MAJOR = sys.version_info[0]
1212
PY_MINOR = sys.version_info[1]
1313

14+
# Disable SourceLink during the build until it can read repo-format v1, #1613
15+
os.environ["EnableSourceControlManagerQueries"] = "false"
1416

1517
class DotnetLib:
1618
def __init__(self, name, path, **kwargs):
@@ -154,6 +156,7 @@ def finalize_options(self):
154156
packages=["pythonnet", "pythonnet.find_libpython"],
155157
install_requires=["clr_loader"],
156158
long_description=long_description,
159+
long_description_content_type="text/x-rst",
157160
py_modules=["clr"],
158161
dotnet_libs=dotnet_libs,
159162
classifiers=[

src/console/Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
3+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
44
<Platforms>x64;x86</Platforms>
55
<OutputType>Exe</OutputType>
66
<AssemblyName>nPython</AssemblyName>

src/embed_tests/Codecs.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,18 @@ public PyObject TryEncode(object value)
421421
}
422422
}
423423

424-
class InstancelessExceptionDecoder : IPyObjectDecoder
424+
class InstancelessExceptionDecoder : IPyObjectDecoder, IDisposable
425425
{
426426
readonly PyObject PyErr = Py.Import("clr.interop").GetAttr("PyErr");
427427

428428
public bool CanDecode(PyType objectType, Type targetType)
429429
=> PythonReferenceComparer.Instance.Equals(PyErr, objectType);
430430

431+
public void Dispose()
432+
{
433+
PyErr.Dispose();
434+
}
435+
431436
public bool TryDecode<T>(PyObject pyObj, out T value)
432437
{
433438
if (pyObj.HasAttr("value"))

src/embed_tests/GlobalTestsSetup.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ namespace Python.EmbeddingTest
99
[SetUpFixture]
1010
public partial class GlobalTestsSetup
1111
{
12+
[OneTimeSetUp]
13+
public void GlobalSetup()
14+
{
15+
Finalizer.Instance.ErrorHandler += FinalizerErrorHandler;
16+
}
17+
18+
private void FinalizerErrorHandler(object sender, Finalizer.ErrorArgs e)
19+
{
20+
if (e.Error is RuntimeShutdownException)
21+
{
22+
// allow objects to leak after the python runtime run
23+
// they were created in is gone
24+
e.Handled = true;
25+
}
26+
}
27+
1228
[OneTimeTearDown]
1329
public void FinalCleanup()
1430
{

src/embed_tests/Inheritance.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void SetUp()
2424
[OneTimeTearDown]
2525
public void Dispose()
2626
{
27+
ExtraBaseTypeProvider.ExtraBase.Dispose();
2728
PythonEngine.Shutdown();
2829
}
2930

src/embed_tests/Python.EmbeddingTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
66
<SignAssembly>true</SignAssembly>
77
</PropertyGroup>

src/embed_tests/TestDomainReload.cs

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -179,116 +179,6 @@ public static void CrossDomainObject()
179179

180180
#endregion
181181

182-
#region Tempary tests
183-
184-
// https://github.com/pythonnet/pythonnet/pull/1074#issuecomment-596139665
185-
[Test]
186-
public void CrossReleaseBuiltinType()
187-
{
188-
void ExecTest()
189-
{
190-
try
191-
{
192-
PythonEngine.Initialize();
193-
var numRef = CreateNumReference();
194-
Assert.True(numRef.IsAlive);
195-
PythonEngine.Shutdown(); // <- "run" 1 ends
196-
PythonEngine.Initialize(); // <- "run" 2 starts
197-
198-
GC.Collect();
199-
GC.WaitForPendingFinalizers(); // <- this will put former `num` into Finalizer queue
200-
Finalizer.Instance.Collect();
201-
// ^- this will call PyObject.Dispose, which will call XDecref on `num.Handle`,
202-
// but Python interpreter from "run" 1 is long gone, so it will corrupt memory instead.
203-
Assert.False(numRef.IsAlive);
204-
}
205-
finally
206-
{
207-
PythonEngine.Shutdown();
208-
}
209-
}
210-
211-
var errorArgs = new List<Finalizer.ErrorArgs>();
212-
void ErrorHandler(object sender, Finalizer.ErrorArgs e)
213-
{
214-
errorArgs.Add(e);
215-
}
216-
Finalizer.Instance.ErrorHandler += ErrorHandler;
217-
try
218-
{
219-
for (int i = 0; i < 10; i++)
220-
{
221-
ExecTest();
222-
}
223-
}
224-
finally
225-
{
226-
Finalizer.Instance.ErrorHandler -= ErrorHandler;
227-
}
228-
Assert.AreEqual(errorArgs.Count, 0);
229-
}
230-
231-
[Test]
232-
public void CrossReleaseCustomType()
233-
{
234-
void ExecTest()
235-
{
236-
try
237-
{
238-
PythonEngine.Initialize();
239-
var objRef = CreateConcreateObject();
240-
Assert.True(objRef.IsAlive);
241-
PythonEngine.Shutdown(); // <- "run" 1 ends
242-
PythonEngine.Initialize(); // <- "run" 2 starts
243-
GC.Collect();
244-
GC.WaitForPendingFinalizers();
245-
Finalizer.Instance.Collect();
246-
Assert.False(objRef.IsAlive);
247-
}
248-
finally
249-
{
250-
PythonEngine.Shutdown();
251-
}
252-
}
253-
254-
var errorArgs = new List<Finalizer.ErrorArgs>();
255-
void ErrorHandler(object sender, Finalizer.ErrorArgs e)
256-
{
257-
errorArgs.Add(e);
258-
}
259-
Finalizer.Instance.ErrorHandler += ErrorHandler;
260-
try
261-
{
262-
for (int i = 0; i < 10; i++)
263-
{
264-
ExecTest();
265-
}
266-
}
267-
finally
268-
{
269-
Finalizer.Instance.ErrorHandler -= ErrorHandler;
270-
}
271-
Assert.AreEqual(errorArgs.Count, 0);
272-
}
273-
274-
private static WeakReference CreateNumReference()
275-
{
276-
var num = 3216757418.ToPython();
277-
Assert.AreEqual(num.Refcount, 1);
278-
WeakReference numRef = new WeakReference(num, false);
279-
return numRef;
280-
}
281-
282-
private static WeakReference CreateConcreateObject()
283-
{
284-
var obj = new Domain.MyClass().ToPython();
285-
Assert.AreEqual(obj.Refcount, 1);
286-
WeakReference numRef = new WeakReference(obj, false);
287-
return numRef;
288-
}
289-
290-
#endregion Tempary tests
291-
292182
/// <summary>
293183
/// This is a magic incantation required to run code in an application
294184
/// domain other than the current one.

src/embed_tests/pyimport.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,14 @@ import clr
111111
}
112112
}
113113
}
114+
115+
// regression for https://github.com/pythonnet/pythonnet/issues/1601
116+
// initialize fails if a class derived from IEnumerable is in global namespace
117+
public class PublicEnumerator : System.Collections.IEnumerable
118+
{
119+
public System.Collections.IEnumerator GetEnumerator()
120+
{
121+
return null;
122+
}
123+
}
124+

src/embed_tests/pyinitialize.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ public static void LoadSpecificArgs()
4040
{
4141
using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv")))
4242
{
43-
Assert.AreEqual(args[0], argv[0].ToString());
44-
Assert.AreEqual(args[1], argv[1].ToString());
43+
using var v0 = argv[0];
44+
using var v1 = argv[1];
45+
Assert.AreEqual(args[0], v0.ToString());
46+
Assert.AreEqual(args[1], v1.ToString());
4547
}
4648
}
4749
}
@@ -54,12 +56,16 @@ public void ImportClassShutdownRefcount()
5456

5557
PyObject ns = Py.Import(typeof(ImportClassShutdownRefcountClass).Namespace);
5658
PyObject cls = ns.GetAttr(nameof(ImportClassShutdownRefcountClass));
59+
BorrowedReference clsRef = cls.Reference;
60+
#pragma warning disable CS0618 // Type or member is obsolete
61+
cls.Leak();
62+
#pragma warning restore CS0618 // Type or member is obsolete
5763
ns.Dispose();
5864

59-
Assert.Less(cls.Refcount, 256);
65+
Assert.Less(Runtime.Runtime.Refcount32(clsRef), 256);
6066

6167
PythonEngine.Shutdown();
62-
Assert.Greater(cls.Refcount, 0);
68+
Assert.Greater(Runtime.Runtime.Refcount32(clsRef), 0);
6369
}
6470

6571
/// <summary>
@@ -176,6 +182,7 @@ public static void TestRunExitFuncs()
176182
{
177183
Assert.Fail(msg);
178184
}
185+
PythonEngine.InteropConfiguration = InteropConfiguration.MakeDefault();
179186
return;
180187
}
181188
bool called = false;
@@ -187,6 +194,7 @@ public static void TestRunExitFuncs()
187194
atexit.Dispose();
188195
Runtime.Runtime.Shutdown();
189196
Assert.True(called);
197+
PythonEngine.InteropConfiguration = InteropConfiguration.MakeDefault();
190198
}
191199
}
192200

src/python_tests_runner/Python.PythonTestsRunner.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>

0 commit comments

Comments
 (0)