Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@
- Ehsan Iran-Nejad ([@eirannejad](https://github.com/eirannejad))
- ([@legomanww](https://github.com/legomanww))
- ([@gertdreyer](https://github.com/gertdreyer))
- Kerbiter ([@Metadorius](https://github.com/Metadorius))
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
### Added

- Support `del obj[...]` for types derived from `IList<T>` and `IDictionary<K, V>`
- Support for .NET Framework 4.6.1 (#2701)

### Changed
### Fixed

- Fixed crash when trying to `del clrObj[...]` for non-arrays
- ci: properly exclude job (#2542)
- ci: properly exclude job (#2542)

## [3.0.5](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.5) - 2024-12-13

Expand Down
2 changes: 1 addition & 1 deletion doc/source/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Mono (``mono``)

.NET Framework (``netfx``)
Default on Windows and also only supported there. Must be at least version
4.7.2.
4.6.1, with 4.7.2 or later recommended.

.NET Core (``coreclr``)
Self-contained is not supported, must be at least version 3.1.
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ email = "[email protected]"
Homepage = "https://pythonnet.github.io/"
Sources = "https://github.com/pythonnet/pythonnet"

[project.entry-points.pyinstaller40]
hook-dirs = "pythonnet._pyinstaller:get_hook_dirs"

[tool.setuptools]
zip-safe = false
py-modules = ["clr"]
Expand Down
4 changes: 4 additions & 0 deletions pythonnet/_pyinstaller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

def get_hook_dirs():
return [os.path.dirname(__file__)]
9 changes: 9 additions & 0 deletions pythonnet/_pyinstaller/hook-clr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from PyInstaller.utils.hooks import collect_data_files, collect_dynamic_libs

try:
binaries = collect_dynamic_libs("pythonnet")
datas = collect_data_files("pythonnet")
except Exception:
# name conflict with https://pypi.org/project/clr/, do not crash if just clr is present
binaries = []
datas = []
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def finalize_options(self):
dotnet_libs = [
DotnetLib(
"python-runtime",
"src/runtime/Python.Runtime.csproj",
"src/compat/Python.Runtime.Compat.csproj",
output="pythonnet/runtime",
)
]
Expand Down
13 changes: 13 additions & 0 deletions src/compat/Python.Runtime.Compat.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- A dummy project to force MSBuild to package .NET 4.6.1 requirements -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<OutputType>Library</OutputType>
<!-- Don't copy the dummy assembly/pdb to output; we only need the resolved references -->
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\runtime\Python.Runtime.csproj" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions src/runtime/Loader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Text;

namespace Python.Runtime
Expand All @@ -12,6 +13,22 @@ public unsafe static int Initialize(IntPtr data, int size)
{
try
{
// On .NET Framework, the host is python.exe which has no binding
// redirects for netstandard2.0 shims (e.g. RuntimeInformation
// Version=0.0.0.0 vs the 4.0.2.0 shim on disk). Binding redirects
// via config files can't be injected after AppDomain creation, so
// resolve assemblies from our runtime directory directly.
AppDomain.CurrentDomain.AssemblyResolve += (_, args) =>
{
var name = new System.Reflection.AssemblyName(args.Name);
var dir = Path.GetDirectoryName(typeof(Loader).Assembly.Location);
var path = Path.Combine(dir, name.Name + ".dll");

return File.Exists(path)
? System.Reflection.Assembly.LoadFrom(path)
: null;
};

var dllPath = Encodings.UTF8.GetString((byte*)data.ToPointer(), size);

if (!string.IsNullOrEmpty(dllPath))
Expand Down