Skip to content

Commit a967d46

Browse files
Feature python 3 11 (#82)
* Merge pull request pythonnet#1955 from filmor/python-3.11 Python 3.11 * Minor fix for datetime tz conversion * Version bump to 2.0.29 --------- Co-authored-by: Benedikt Reinartz <filmor@gmail.com>
1 parent 8bf39fc commit a967d46

File tree

15 files changed

+371
-108
lines changed

15 files changed

+371
-108
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [windows, ubuntu, macos]
19-
python: ["3.6", "3.7", "3.8", "3.9", "3.10"]
19+
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
2020
platform: [x64, x86]
2121
exclude:
2222
- os: ubuntu
@@ -54,15 +54,17 @@ jobs:
5454
run: |
5555
pip install -v .
5656
57-
- name: Set Python DLL path (non Windows)
57+
- name: Set Python DLL path and PYTHONHOME (non Windows)
5858
if: ${{ matrix.os != 'windows' }}
5959
run: |
60-
python -m pythonnet.find_libpython --export >> $GITHUB_ENV
60+
echo PYTHONNET_PYDLL=$(python -m find_libpython) >> $GITHUB_ENV
61+
echo PYTHONHOME=$(python -c 'import sys; print(sys.prefix)') >> $GITHUB_ENV
6162
62-
- name: Set Python DLL path (Windows)
63+
- name: Set Python DLL path and PYTHONHOME (Windows)
6364
if: ${{ matrix.os == 'windows' }}
6465
run: |
65-
python -m pythonnet.find_libpython --export | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
66+
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -InputObject "PYTHONNET_PYDLL=$(python -m find_libpython)"
67+
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -InputObject "PYTHONHOME=$(python -c 'import sys; print(sys.prefix)')"
6668
6769
- name: Embedding tests
6870
run: dotnet test --runtime any-${{ matrix.platform }} --logger "console;verbosity=detailed" src/embed_tests/

pyproject.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,55 @@
22
requires = ["setuptools>=42", "wheel", "pycparser"]
33
build-backend = "setuptools.build_meta"
44

5+
[project]
6+
name = "pythonnet"
7+
description = ".NET and Mono integration for Python"
8+
license = {text = "MIT"}
9+
10+
readme = "README.rst"
11+
12+
dependencies = [
13+
"clr_loader>=0.2.2,<0.3.0"
14+
]
15+
16+
requires-python = ">=3.7, <3.12"
17+
18+
classifiers = [
19+
"Development Status :: 5 - Production/Stable",
20+
"Intended Audience :: Developers",
21+
"License :: OSI Approved :: MIT License",
22+
"Programming Language :: C#",
23+
"Programming Language :: Python :: 3",
24+
"Programming Language :: Python :: 3.7",
25+
"Programming Language :: Python :: 3.8",
26+
"Programming Language :: Python :: 3.9",
27+
"Programming Language :: Python :: 3.10",
28+
"Programming Language :: Python :: 3.11",
29+
"Operating System :: Microsoft :: Windows",
30+
"Operating System :: POSIX :: Linux",
31+
"Operating System :: MacOS :: MacOS X",
32+
]
33+
34+
dynamic = ["version"]
35+
36+
[[project.authors]]
37+
name = "The Contributors of the Python.NET Project"
38+
email = "pythonnet@python.org"
39+
40+
[project.urls]
41+
Homepage = "https://pythonnet.github.io/"
42+
Sources = "https://github.com/pythonnet/pythonnet"
43+
44+
[tool.setuptools]
45+
zip-safe = false
46+
py-modules = ["clr"]
47+
48+
[tool.setuptools.dynamic.version]
49+
file = "version.txt"
50+
51+
[tool.setuptools.packages.find]
52+
include = ["pythonnet*"]
53+
554
[tool.pytest.ini_options]
655
xfail_strict = true
756
testpaths = [

src/embed_tests/TestPythonEngineProperties.cs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class TestPythonEngineProperties
99
[Test]
1010
public static void GetBuildinfoDoesntCrash()
1111
{
12+
PythonEngine.Initialize();
1213
using (Py.GIL())
1314
{
1415
string s = PythonEngine.BuildInfo;
@@ -21,6 +22,7 @@ public static void GetBuildinfoDoesntCrash()
2122
[Test]
2223
public static void GetCompilerDoesntCrash()
2324
{
25+
PythonEngine.Initialize();
2426
using (Py.GIL())
2527
{
2628
string s = PythonEngine.Compiler;
@@ -34,6 +36,7 @@ public static void GetCompilerDoesntCrash()
3436
[Test]
3537
public static void GetCopyrightDoesntCrash()
3638
{
39+
PythonEngine.Initialize();
3740
using (Py.GIL())
3841
{
3942
string s = PythonEngine.Copyright;
@@ -46,6 +49,7 @@ public static void GetCopyrightDoesntCrash()
4649
[Test]
4750
public static void GetPlatformDoesntCrash()
4851
{
52+
PythonEngine.Initialize();
4953
using (Py.GIL())
5054
{
5155
string s = PythonEngine.Platform;
@@ -58,6 +62,7 @@ public static void GetPlatformDoesntCrash()
5862
[Test]
5963
public static void GetVersionDoesntCrash()
6064
{
65+
PythonEngine.Initialize();
6166
using (Py.GIL())
6267
{
6368
string s = PythonEngine.Version;
@@ -91,9 +96,6 @@ public static void GetProgramNameDefault()
9196
/// Test default behavior of PYTHONHOME. If ENVVAR is set it will
9297
/// return the same value. If not, returns EmptyString.
9398
/// </summary>
94-
/// <remarks>
95-
/// AppVeyor.yml has been update to tests with ENVVAR set.
96-
/// </remarks>
9799
[Test]
98100
public static void GetPythonHomeDefault()
99101
{
@@ -109,22 +111,19 @@ public static void GetPythonHomeDefault()
109111
[Test]
110112
public void SetPythonHome()
111113
{
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-
114+
PythonEngine.Initialize();
115+
var pythonHomeBackup = PythonEngine.PythonHome;
119116
PythonEngine.Shutdown();
120117

121-
var pythonHomeBackup = PythonEngine.PythonHome;
118+
if (pythonHomeBackup == "")
119+
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
122120

123121
var pythonHome = "/dummypath/";
124122

125123
PythonEngine.PythonHome = pythonHome;
126124
PythonEngine.Initialize();
127125

126+
Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
128127
PythonEngine.Shutdown();
129128

130129
// Restoring valid pythonhome.
@@ -134,15 +133,12 @@ public void SetPythonHome()
134133
[Test]
135134
public void SetPythonHomeTwice()
136135
{
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-
}
136+
PythonEngine.Initialize();
137+
var pythonHomeBackup = PythonEngine.PythonHome;
143138
PythonEngine.Shutdown();
144139

145-
var pythonHomeBackup = PythonEngine.PythonHome;
140+
if (pythonHomeBackup == "")
141+
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
146142

147143
var pythonHome = "/dummypath/";
148144

@@ -156,6 +152,26 @@ public void SetPythonHomeTwice()
156152
PythonEngine.PythonHome = pythonHomeBackup;
157153
}
158154

155+
[Test]
156+
[Ignore("Currently buggy in Python")]
157+
public void SetPythonHomeEmptyString()
158+
{
159+
PythonEngine.Initialize();
160+
161+
var backup = PythonEngine.PythonHome;
162+
if (backup == "")
163+
{
164+
PythonEngine.Shutdown();
165+
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
166+
}
167+
PythonEngine.PythonHome = "";
168+
169+
Assert.AreEqual("", PythonEngine.PythonHome);
170+
171+
PythonEngine.PythonHome = backup;
172+
PythonEngine.Shutdown();
173+
}
174+
159175
[Test]
160176
public void SetProgramName()
161177
{
@@ -202,7 +218,7 @@ public void SetPythonPath()
202218
// The list sys.path is initialized with this value on interpreter startup;
203219
// it can be (and usually is) modified later to change the search path for loading modules.
204220
// See https://docs.python.org/3/c-api/init.html#c.Py_GetPath
205-
// After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.
221+
// After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.
206222

207223
PythonEngine.Shutdown();
208224

src/perf_tests/Python.PerformanceTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
16-
<PackageReference Include="quantconnect.pythonnet" Version="2.0.28" GeneratePathProperty="true">
16+
<PackageReference Include="quantconnect.pythonnet" Version="2.0.29" GeneratePathProperty="true">
1717
<IncludeAssets>compile</IncludeAssets>
1818
</PackageReference>
1919
</ItemGroup>
@@ -25,7 +25,7 @@
2525
</Target>
2626

2727
<Target Name="CopyBaseline" AfterTargets="Build">
28-
<Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.28\lib\net5.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" />
28+
<Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.29\lib\net5.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" />
2929
</Target>
3030

3131
<Target Name="CopyNewBuild" AfterTargets="Build">

src/runtime/Converter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ private static NewReference TzInfo(DateTimeKind kind)
352352
if (kind == DateTimeKind.Unspecified) return new NewReference(Runtime.PyNone);
353353
var offset = kind == DateTimeKind.Local ? DateTimeOffset.Now.Offset : TimeSpan.Zero;
354354
using var tzInfoArgs = Runtime.PyTuple_New(2);
355-
Runtime.PyTuple_SetItem(tzInfoArgs.Borrow(), 0, Runtime.PyFloat_FromDouble(offset.Hours).Steal());
356-
Runtime.PyTuple_SetItem(tzInfoArgs.Borrow(), 1, Runtime.PyFloat_FromDouble(offset.Minutes).Steal());
355+
Runtime.PyTuple_SetItem(tzInfoArgs.Borrow(), 0, Runtime.PyLong_FromLongLong(offset.Hours).Steal());
356+
Runtime.PyTuple_SetItem(tzInfoArgs.Borrow(), 1, Runtime.PyLong_FromLongLong(offset.Minutes).Steal());
357357
var returnValue = Runtime.PyObject_CallObject(tzInfoCtor.Value, tzInfoArgs.Borrow());
358358
return returnValue;
359359
}

src/runtime/Native/TypeOffset311.cs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
2+
// Auto-generated by geninterop.py.
3+
// DO NOT MODIFY BY HAND.
4+
5+
// Python 3.11: ABI flags: ''
6+
7+
// ReSharper disable InconsistentNaming
8+
// ReSharper disable IdentifierTypo
9+
10+
using System;
11+
using System.Diagnostics.CodeAnalysis;
12+
using System.Runtime.InteropServices;
13+
14+
using Python.Runtime.Native;
15+
16+
namespace Python.Runtime
17+
{
18+
[SuppressMessage("Style", "IDE1006:Naming Styles",
19+
Justification = "Following CPython",
20+
Scope = "type")]
21+
22+
[StructLayout(LayoutKind.Sequential)]
23+
internal class TypeOffset311 : GeneratedTypeOffsets, ITypeOffsets
24+
{
25+
public TypeOffset311() { }
26+
// Auto-generated from PyHeapTypeObject in Python.h
27+
public int ob_refcnt { get; private set; }
28+
public int ob_type { get; private set; }
29+
public int ob_size { get; private set; }
30+
public int tp_name { get; private set; }
31+
public int tp_basicsize { get; private set; }
32+
public int tp_itemsize { get; private set; }
33+
public int tp_dealloc { get; private set; }
34+
public int tp_vectorcall_offset { get; private set; }
35+
public int tp_getattr { get; private set; }
36+
public int tp_setattr { get; private set; }
37+
public int tp_as_async { get; private set; }
38+
public int tp_repr { get; private set; }
39+
public int tp_as_number { get; private set; }
40+
public int tp_as_sequence { get; private set; }
41+
public int tp_as_mapping { get; private set; }
42+
public int tp_hash { get; private set; }
43+
public int tp_call { get; private set; }
44+
public int tp_str { get; private set; }
45+
public int tp_getattro { get; private set; }
46+
public int tp_setattro { get; private set; }
47+
public int tp_as_buffer { get; private set; }
48+
public int tp_flags { get; private set; }
49+
public int tp_doc { get; private set; }
50+
public int tp_traverse { get; private set; }
51+
public int tp_clear { get; private set; }
52+
public int tp_richcompare { get; private set; }
53+
public int tp_weaklistoffset { get; private set; }
54+
public int tp_iter { get; private set; }
55+
public int tp_iternext { get; private set; }
56+
public int tp_methods { get; private set; }
57+
public int tp_members { get; private set; }
58+
public int tp_getset { get; private set; }
59+
public int tp_base { get; private set; }
60+
public int tp_dict { get; private set; }
61+
public int tp_descr_get { get; private set; }
62+
public int tp_descr_set { get; private set; }
63+
public int tp_dictoffset { get; private set; }
64+
public int tp_init { get; private set; }
65+
public int tp_alloc { get; private set; }
66+
public int tp_new { get; private set; }
67+
public int tp_free { get; private set; }
68+
public int tp_is_gc { get; private set; }
69+
public int tp_bases { get; private set; }
70+
public int tp_mro { get; private set; }
71+
public int tp_cache { get; private set; }
72+
public int tp_subclasses { get; private set; }
73+
public int tp_weaklist { get; private set; }
74+
public int tp_del { get; private set; }
75+
public int tp_version_tag { get; private set; }
76+
public int tp_finalize { get; private set; }
77+
public int tp_vectorcall { get; private set; }
78+
public int am_await { get; private set; }
79+
public int am_aiter { get; private set; }
80+
public int am_anext { get; private set; }
81+
public int am_send { get; private set; }
82+
public int nb_add { get; private set; }
83+
public int nb_subtract { get; private set; }
84+
public int nb_multiply { get; private set; }
85+
public int nb_remainder { get; private set; }
86+
public int nb_divmod { get; private set; }
87+
public int nb_power { get; private set; }
88+
public int nb_negative { get; private set; }
89+
public int nb_positive { get; private set; }
90+
public int nb_absolute { get; private set; }
91+
public int nb_bool { get; private set; }
92+
public int nb_invert { get; private set; }
93+
public int nb_lshift { get; private set; }
94+
public int nb_rshift { get; private set; }
95+
public int nb_and { get; private set; }
96+
public int nb_xor { get; private set; }
97+
public int nb_or { get; private set; }
98+
public int nb_int { get; private set; }
99+
public int nb_reserved { get; private set; }
100+
public int nb_float { get; private set; }
101+
public int nb_inplace_add { get; private set; }
102+
public int nb_inplace_subtract { get; private set; }
103+
public int nb_inplace_multiply { get; private set; }
104+
public int nb_inplace_remainder { get; private set; }
105+
public int nb_inplace_power { get; private set; }
106+
public int nb_inplace_lshift { get; private set; }
107+
public int nb_inplace_rshift { get; private set; }
108+
public int nb_inplace_and { get; private set; }
109+
public int nb_inplace_xor { get; private set; }
110+
public int nb_inplace_or { get; private set; }
111+
public int nb_floor_divide { get; private set; }
112+
public int nb_true_divide { get; private set; }
113+
public int nb_inplace_floor_divide { get; private set; }
114+
public int nb_inplace_true_divide { get; private set; }
115+
public int nb_index { get; private set; }
116+
public int nb_matrix_multiply { get; private set; }
117+
public int nb_inplace_matrix_multiply { get; private set; }
118+
public int mp_length { get; private set; }
119+
public int mp_subscript { get; private set; }
120+
public int mp_ass_subscript { get; private set; }
121+
public int sq_length { get; private set; }
122+
public int sq_concat { get; private set; }
123+
public int sq_repeat { get; private set; }
124+
public int sq_item { get; private set; }
125+
public int was_sq_slice { get; private set; }
126+
public int sq_ass_item { get; private set; }
127+
public int was_sq_ass_slice { get; private set; }
128+
public int sq_contains { get; private set; }
129+
public int sq_inplace_concat { get; private set; }
130+
public int sq_inplace_repeat { get; private set; }
131+
public int bf_getbuffer { get; private set; }
132+
public int bf_releasebuffer { get; private set; }
133+
public int name { get; private set; }
134+
public int ht_slots { get; private set; }
135+
public int qualname { get; private set; }
136+
public int ht_cached_keys { get; private set; }
137+
public int ht_module { get; private set; }
138+
public int _ht_tpname { get; private set; }
139+
public int spec_cache_getitem { get; private set; }
140+
}
141+
}

src/runtime/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
[assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]
55
[assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]
66

7-
[assembly: AssemblyVersion("2.0.28")]
8-
[assembly: AssemblyFileVersion("2.0.28")]
7+
[assembly: AssemblyVersion("2.0.29")]
8+
[assembly: AssemblyFileVersion("2.0.29")]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy