Skip to content

Commit

Permalink
Feature python 3 11 (#82)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Martin-Molinero and filmor authored Mar 18, 2024
1 parent 8bf39fc commit a967d46
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 108 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [windows, ubuntu, macos]
python: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
platform: [x64, x86]
exclude:
- os: ubuntu
Expand Down Expand Up @@ -54,15 +54,17 @@ jobs:
run: |
pip install -v .
- name: Set Python DLL path (non Windows)
- name: Set Python DLL path and PYTHONHOME (non Windows)
if: ${{ matrix.os != 'windows' }}
run: |
python -m pythonnet.find_libpython --export >> $GITHUB_ENV
echo PYTHONNET_PYDLL=$(python -m find_libpython) >> $GITHUB_ENV
echo PYTHONHOME=$(python -c 'import sys; print(sys.prefix)') >> $GITHUB_ENV
- name: Set Python DLL path (Windows)
- name: Set Python DLL path and PYTHONHOME (Windows)
if: ${{ matrix.os == 'windows' }}
run: |
python -m pythonnet.find_libpython --export | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -InputObject "PYTHONNET_PYDLL=$(python -m find_libpython)"
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -InputObject "PYTHONHOME=$(python -c 'import sys; print(sys.prefix)')"
- name: Embedding tests
run: dotnet test --runtime any-${{ matrix.platform }} --logger "console;verbosity=detailed" src/embed_tests/
Expand Down
49 changes: 49 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,55 @@
requires = ["setuptools>=42", "wheel", "pycparser"]
build-backend = "setuptools.build_meta"

[project]
name = "pythonnet"
description = ".NET and Mono integration for Python"
license = {text = "MIT"}

readme = "README.rst"

dependencies = [
"clr_loader>=0.2.2,<0.3.0"
]

requires-python = ">=3.7, <3.12"

classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: C#",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
]

dynamic = ["version"]

[[project.authors]]
name = "The Contributors of the Python.NET Project"
email = "[email protected]"

[project.urls]
Homepage = "https://pythonnet.github.io/"
Sources = "https://github.com/pythonnet/pythonnet"

[tool.setuptools]
zip-safe = false
py-modules = ["clr"]

[tool.setuptools.dynamic.version]
file = "version.txt"

[tool.setuptools.packages.find]
include = ["pythonnet*"]

[tool.pytest.ini_options]
xfail_strict = true
testpaths = [
Expand Down
54 changes: 35 additions & 19 deletions src/embed_tests/TestPythonEngineProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class TestPythonEngineProperties
[Test]
public static void GetBuildinfoDoesntCrash()
{
PythonEngine.Initialize();
using (Py.GIL())
{
string s = PythonEngine.BuildInfo;
Expand All @@ -21,6 +22,7 @@ public static void GetBuildinfoDoesntCrash()
[Test]
public static void GetCompilerDoesntCrash()
{
PythonEngine.Initialize();
using (Py.GIL())
{
string s = PythonEngine.Compiler;
Expand All @@ -34,6 +36,7 @@ public static void GetCompilerDoesntCrash()
[Test]
public static void GetCopyrightDoesntCrash()
{
PythonEngine.Initialize();
using (Py.GIL())
{
string s = PythonEngine.Copyright;
Expand All @@ -46,6 +49,7 @@ public static void GetCopyrightDoesntCrash()
[Test]
public static void GetPlatformDoesntCrash()
{
PythonEngine.Initialize();
using (Py.GIL())
{
string s = PythonEngine.Platform;
Expand All @@ -58,6 +62,7 @@ public static void GetPlatformDoesntCrash()
[Test]
public static void GetVersionDoesntCrash()
{
PythonEngine.Initialize();
using (Py.GIL())
{
string s = PythonEngine.Version;
Expand Down Expand Up @@ -91,9 +96,6 @@ public static void GetProgramNameDefault()
/// Test default behavior of PYTHONHOME. If ENVVAR is set it will
/// return the same value. If not, returns EmptyString.
/// </summary>
/// <remarks>
/// AppVeyor.yml has been update to tests with ENVVAR set.
/// </remarks>
[Test]
public static void GetPythonHomeDefault()
{
Expand All @@ -109,22 +111,19 @@ public static void GetPythonHomeDefault()
[Test]
public void SetPythonHome()
{
// We needs to ensure that engine was started and shutdown at least once before setting dummy home.
// Otherwise engine will not run with dummy path with random problem.
if (!PythonEngine.IsInitialized)
{
PythonEngine.Initialize();
}

PythonEngine.Initialize();
var pythonHomeBackup = PythonEngine.PythonHome;
PythonEngine.Shutdown();

var pythonHomeBackup = PythonEngine.PythonHome;
if (pythonHomeBackup == "")
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");

var pythonHome = "/dummypath/";

PythonEngine.PythonHome = pythonHome;
PythonEngine.Initialize();

Assert.AreEqual(pythonHome, PythonEngine.PythonHome);
PythonEngine.Shutdown();

// Restoring valid pythonhome.
Expand All @@ -134,15 +133,12 @@ public void SetPythonHome()
[Test]
public void SetPythonHomeTwice()
{
// We needs to ensure that engine was started and shutdown at least once before setting dummy home.
// Otherwise engine will not run with dummy path with random problem.
if (!PythonEngine.IsInitialized)
{
PythonEngine.Initialize();
}
PythonEngine.Initialize();
var pythonHomeBackup = PythonEngine.PythonHome;
PythonEngine.Shutdown();

var pythonHomeBackup = PythonEngine.PythonHome;
if (pythonHomeBackup == "")
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");

var pythonHome = "/dummypath/";

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

[Test]
[Ignore("Currently buggy in Python")]
public void SetPythonHomeEmptyString()
{
PythonEngine.Initialize();

var backup = PythonEngine.PythonHome;
if (backup == "")
{
PythonEngine.Shutdown();
Assert.Inconclusive("Can't reset PythonHome to empty string, skipping");
}
PythonEngine.PythonHome = "";

Assert.AreEqual("", PythonEngine.PythonHome);

PythonEngine.PythonHome = backup;
PythonEngine.Shutdown();
}

[Test]
public void SetProgramName()
{
Expand Down Expand Up @@ -202,7 +218,7 @@ public void SetPythonPath()
// The list sys.path is initialized with this value on interpreter startup;
// it can be (and usually is) modified later to change the search path for loading modules.
// See https://docs.python.org/3/c-api/init.html#c.Py_GetPath
// After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.
// After PythonPath is set, then PythonEngine.PythonPath will correctly return the full search path.

PythonEngine.Shutdown();

Expand Down
4 changes: 2 additions & 2 deletions src/perf_tests/Python.PerformanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
<PackageReference Include="quantconnect.pythonnet" Version="2.0.28" GeneratePathProperty="true">
<PackageReference Include="quantconnect.pythonnet" Version="2.0.29" GeneratePathProperty="true">
<IncludeAssets>compile</IncludeAssets>
</PackageReference>
</ItemGroup>
Expand All @@ -25,7 +25,7 @@
</Target>

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

<Target Name="CopyNewBuild" AfterTargets="Build">
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ private static NewReference TzInfo(DateTimeKind kind)
if (kind == DateTimeKind.Unspecified) return new NewReference(Runtime.PyNone);
var offset = kind == DateTimeKind.Local ? DateTimeOffset.Now.Offset : TimeSpan.Zero;
using var tzInfoArgs = Runtime.PyTuple_New(2);
Runtime.PyTuple_SetItem(tzInfoArgs.Borrow(), 0, Runtime.PyFloat_FromDouble(offset.Hours).Steal());
Runtime.PyTuple_SetItem(tzInfoArgs.Borrow(), 1, Runtime.PyFloat_FromDouble(offset.Minutes).Steal());
Runtime.PyTuple_SetItem(tzInfoArgs.Borrow(), 0, Runtime.PyLong_FromLongLong(offset.Hours).Steal());
Runtime.PyTuple_SetItem(tzInfoArgs.Borrow(), 1, Runtime.PyLong_FromLongLong(offset.Minutes).Steal());
var returnValue = Runtime.PyObject_CallObject(tzInfoCtor.Value, tzInfoArgs.Borrow());
return returnValue;
}
Expand Down
141 changes: 141 additions & 0 deletions src/runtime/Native/TypeOffset311.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@

// Auto-generated by geninterop.py.
// DO NOT MODIFY BY HAND.

// Python 3.11: ABI flags: ''

// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;

using Python.Runtime.Native;

namespace Python.Runtime
{
[SuppressMessage("Style", "IDE1006:Naming Styles",
Justification = "Following CPython",
Scope = "type")]

[StructLayout(LayoutKind.Sequential)]
internal class TypeOffset311 : GeneratedTypeOffsets, ITypeOffsets
{
public TypeOffset311() { }
// Auto-generated from PyHeapTypeObject in Python.h
public int ob_refcnt { get; private set; }
public int ob_type { get; private set; }
public int ob_size { get; private set; }
public int tp_name { get; private set; }
public int tp_basicsize { get; private set; }
public int tp_itemsize { get; private set; }
public int tp_dealloc { get; private set; }
public int tp_vectorcall_offset { get; private set; }
public int tp_getattr { get; private set; }
public int tp_setattr { get; private set; }
public int tp_as_async { get; private set; }
public int tp_repr { get; private set; }
public int tp_as_number { get; private set; }
public int tp_as_sequence { get; private set; }
public int tp_as_mapping { get; private set; }
public int tp_hash { get; private set; }
public int tp_call { get; private set; }
public int tp_str { get; private set; }
public int tp_getattro { get; private set; }
public int tp_setattro { get; private set; }
public int tp_as_buffer { get; private set; }
public int tp_flags { get; private set; }
public int tp_doc { get; private set; }
public int tp_traverse { get; private set; }
public int tp_clear { get; private set; }
public int tp_richcompare { get; private set; }
public int tp_weaklistoffset { get; private set; }
public int tp_iter { get; private set; }
public int tp_iternext { get; private set; }
public int tp_methods { get; private set; }
public int tp_members { get; private set; }
public int tp_getset { get; private set; }
public int tp_base { get; private set; }
public int tp_dict { get; private set; }
public int tp_descr_get { get; private set; }
public int tp_descr_set { get; private set; }
public int tp_dictoffset { get; private set; }
public int tp_init { get; private set; }
public int tp_alloc { get; private set; }
public int tp_new { get; private set; }
public int tp_free { get; private set; }
public int tp_is_gc { get; private set; }
public int tp_bases { get; private set; }
public int tp_mro { get; private set; }
public int tp_cache { get; private set; }
public int tp_subclasses { get; private set; }
public int tp_weaklist { get; private set; }
public int tp_del { get; private set; }
public int tp_version_tag { get; private set; }
public int tp_finalize { get; private set; }
public int tp_vectorcall { get; private set; }
public int am_await { get; private set; }
public int am_aiter { get; private set; }
public int am_anext { get; private set; }
public int am_send { get; private set; }
public int nb_add { get; private set; }
public int nb_subtract { get; private set; }
public int nb_multiply { get; private set; }
public int nb_remainder { get; private set; }
public int nb_divmod { get; private set; }
public int nb_power { get; private set; }
public int nb_negative { get; private set; }
public int nb_positive { get; private set; }
public int nb_absolute { get; private set; }
public int nb_bool { get; private set; }
public int nb_invert { get; private set; }
public int nb_lshift { get; private set; }
public int nb_rshift { get; private set; }
public int nb_and { get; private set; }
public int nb_xor { get; private set; }
public int nb_or { get; private set; }
public int nb_int { get; private set; }
public int nb_reserved { get; private set; }
public int nb_float { get; private set; }
public int nb_inplace_add { get; private set; }
public int nb_inplace_subtract { get; private set; }
public int nb_inplace_multiply { get; private set; }
public int nb_inplace_remainder { get; private set; }
public int nb_inplace_power { get; private set; }
public int nb_inplace_lshift { get; private set; }
public int nb_inplace_rshift { get; private set; }
public int nb_inplace_and { get; private set; }
public int nb_inplace_xor { get; private set; }
public int nb_inplace_or { get; private set; }
public int nb_floor_divide { get; private set; }
public int nb_true_divide { get; private set; }
public int nb_inplace_floor_divide { get; private set; }
public int nb_inplace_true_divide { get; private set; }
public int nb_index { get; private set; }
public int nb_matrix_multiply { get; private set; }
public int nb_inplace_matrix_multiply { get; private set; }
public int mp_length { get; private set; }
public int mp_subscript { get; private set; }
public int mp_ass_subscript { get; private set; }
public int sq_length { get; private set; }
public int sq_concat { get; private set; }
public int sq_repeat { get; private set; }
public int sq_item { get; private set; }
public int was_sq_slice { get; private set; }
public int sq_ass_item { get; private set; }
public int was_sq_ass_slice { get; private set; }
public int sq_contains { get; private set; }
public int sq_inplace_concat { get; private set; }
public int sq_inplace_repeat { get; private set; }
public int bf_getbuffer { get; private set; }
public int bf_releasebuffer { get; private set; }
public int name { get; private set; }
public int ht_slots { get; private set; }
public int qualname { get; private set; }
public int ht_cached_keys { get; private set; }
public int ht_module { get; private set; }
public int _ht_tpname { get; private set; }
public int spec_cache_getitem { get; private set; }
}
}
4 changes: 2 additions & 2 deletions src/runtime/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
[assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]
[assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]

[assembly: AssemblyVersion("2.0.28")]
[assembly: AssemblyFileVersion("2.0.28")]
[assembly: AssemblyVersion("2.0.29")]
[assembly: AssemblyFileVersion("2.0.29")]
Loading

0 comments on commit a967d46

Please sign in to comment.