Skip to content

Commit 41ddfee

Browse files
authored
update to version 3.0.2 from upstream (#9)
2 parents f498ad5 + 8f56f45 commit 41ddfee

File tree

20 files changed

+194
-71
lines changed

20 files changed

+194
-71
lines changed

.github/workflows/ARM.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
3030
- name: Install dependencies
3131
run: |
32-
pip install --upgrade -r requirements.txt
32+
pip install -r requirements.txt
3333
pip install pytest numpy # for tests
3434
3535
- name: Build and Install

.github/workflows/ci_cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
strategy:
4848
fail-fast: false
4949
matrix:
50-
os: [windows, ubuntu, macos]
50+
os: [windows, ubuntu]
5151
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
5252
platform: [x64, x86]
5353
exclude:

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@
8585
- ([@alxnull](https://github.com/alxnull))
8686
- ([@gpetrou](https://github.com/gpetrou))
8787
- Ehsan Iran-Nejad ([@eirannejad](https://github.com/eirannejad))
88+
- ([@legomanww](https://github.com/legomanww))

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1313

1414
### Fixed
1515

16-
- Fixed error occuring when inheriting a class containing a virtual generic method.
16+
## [3.0.2](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.2) - 2023-08-29
17+
18+
### Fixed
19+
20+
- Fixed error occuring when inheriting a class containing a virtual generic method
21+
- Make a second call to `pythonnet.load` a no-op, as it was intended
22+
- Added support for multiple inheritance when inheriting from a class and/or multiple interfaces
23+
- Fixed error occuring when calling `GetBuffer` for anything other than `PyBUF.SIMPLE`
24+
- Bumped `clr_loader` dependency to incorporate patches
1725

1826
## [3.0.1](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.1) - 2022-11-03
1927

doc/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ pygments>=2.7
77
# C# via doxygen
88
breathe
99
git+https://github.com/rogerbarton/sphinx-csharp.git
10+
11+
# Dependency of pythonnet, needed for autodocs
12+
clr_loader

doc/source/dotnet.rst

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ to:
1717

1818
- Reference ``Python.Runtime.dll`` (e.g. via a ``PackageReference``)
1919
- Call ``PythonEngine.Initialize()`` to initialize Python
20-
- Call ``PythonEngine.ImportModule(name)`` to import a module
20+
- Call ``var mod = PyModule.Import(name)`` to import a module as ``mod``
2121

2222
The module you import can either start working with your managed app
2323
environment at the time its imported, or you can explicitly lookup and
@@ -42,28 +42,39 @@ application.
4242

4343
Before interacting with any of the objects or APIs provided by the
4444
``Python.Runtime`` namespace, calling code must have acquired the Python
45-
global interpreter lock by calling the ``PythonEngine.AcquireLock``
46-
method. The only exception to this rule is the
47-
``PythonEngine.Initialize`` method, which may be called at startup
48-
without having acquired the GIL.
49-
50-
When finished using Python APIs, managed code must call a corresponding
51-
``PythonEngine.ReleaseLock`` to release the GIL and allow other threads
52-
to use Python.
53-
54-
A ``using`` statement may be used to acquire and release the GIL:
45+
global interpreter lock by ``using'' ``Py.GIL()``. The only exception to
46+
this rule is the ``PythonEngine.Initialize`` method, which may be called
47+
at startup without having acquired the GIL. The GIL is released again
48+
by disposing the return value of `Py.GIL()`:
5549

5650
.. code:: csharp
5751
5852
using (Py.GIL())
5953
{
6054
PythonEngine.Exec("doStuff()");
6155
}
56+
57+
// or
58+
{
59+
using var _ = Py.GIL()
60+
PythonEngine.Exec("doStuff()");
61+
}
62+
63+
// or
64+
var gil = Py.GIL();
65+
try
66+
{
67+
PythonEngine.Exec("doStuff()");
68+
}
69+
finally
70+
{
71+
gil.Dispose();
72+
}
6273
63-
The AcquireLock and ReleaseLock methods are thin wrappers over the
64-
unmanaged ``PyGILState_Ensure`` and ``PyGILState_Release`` functions
65-
from the Python API, and the documentation for those APIs applies to the
66-
managed versions.
74+
The ``Py.GIL()'' object is a thin wrapper over the unmanaged
75+
``PyGILState_Ensure`` (on construction) and ``PyGILState_Release`` (on
76+
disposal) functions from the Python API, and the documentation for those
77+
APIs applies to the managed versions.
6778

6879
Passing C# Objects to the Python Engine
6980
---------------------------------------

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = {text = "MIT"}
1010
readme = "README.rst"
1111

1212
dependencies = [
13-
"clr_loader>=0.2.5,<0.3.0"
13+
"clr_loader>=0.2.6,<0.3.0"
1414
]
1515

1616
requires-python = ">=3.7, <3.12"
@@ -50,6 +50,7 @@ file = "version.txt"
5050

5151
[tool.setuptools.packages.find]
5252
include = ["pythonnet*"]
53+
exclude = [".gitignore"]
5354

5455
[tool.pytest.ini_options]
5556
xfail_strict = true

pythonnet/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ def load(runtime: Union[clr_loader.Runtime, str, None] = None, **params: str) ->
120120
121121
The same parameters as for `set_runtime` can be used. By default,
122122
`set_default_runtime` is called if no environment has been set yet and no
123-
parameters are passed."""
123+
parameters are passed.
124+
125+
After a successful call, further invocations will return immediately."""
124126
global _LOADED, _LOADER_ASSEMBLY
125127

126128
if _LOADED:
@@ -142,6 +144,8 @@ def load(runtime: Union[clr_loader.Runtime, str, None] = None, **params: str) ->
142144

143145
if func(b"") != 0:
144146
raise RuntimeError("Failed to initialize Python.Runtime.dll")
147+
148+
_LOADED = True
145149

146150
import atexit
147151

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ codecov
88

99
wheel
1010
pycparser
11-
setuptools
12-
clr-loader
11+
clr-loader==0.2.*
1312

1413
# Discover libpython
15-
find_libpython
14+
find_libpython==0.3.*

src/embed_tests/TestPyBuffer.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ public void Finalization()
110110
Assert.AreEqual(1, arr.Refcount);
111111
}
112112

113+
[Test]
114+
public void MultidimensionalNumPyArray()
115+
{
116+
var ndarray = np.arange(24).reshape(1,2,3,4).T;
117+
PyObject ndim = ndarray.ndim;
118+
PyObject shape = ndarray.shape;
119+
PyObject strides = ndarray.strides;
120+
PyObject contiguous = ndarray.flags["C_CONTIGUOUS"];
121+
122+
using PyBuffer buf = ndarray.GetBuffer(PyBUF.STRIDED);
123+
124+
Assert.Multiple(() =>
125+
{
126+
Assert.That(buf.Dimensions, Is.EqualTo(ndim.As<int>()));
127+
Assert.That(buf.Shape, Is.EqualTo(shape.As<long[]>()));
128+
Assert.That(buf.Strides, Is.EqualTo(strides.As<long[]>()));
129+
Assert.That(buf.IsContiguous(BufferOrderStyle.C), Is.EqualTo(contiguous.As<bool>()));
130+
});
131+
}
132+
113133
[MethodImpl(MethodImplOptions.NoInlining)]
114134
static void MakeBufAndLeak(PyObject bufProvider)
115135
{
@@ -121,5 +141,21 @@ static PyObject ByteArrayFromAsciiString(string str)
121141
using var scope = Py.CreateScope();
122142
return Runtime.Runtime.PyByteArray_FromStringAndSize(str).MoveToPyObject();
123143
}
144+
145+
dynamic np
146+
{
147+
get
148+
{
149+
try
150+
{
151+
return Py.Import("numpy");
152+
}
153+
catch (PythonException)
154+
{
155+
Assert.Inconclusive("Numpy or dependency not installed");
156+
return null;
157+
}
158+
}
159+
}
124160
}
125161
}

0 commit comments

Comments
 (0)