Skip to content
Merged
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
14 changes: 14 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default:
@just --choose

setup:
dotnet restore
uv sync

docs:
doxygen doc/Doxyfile
uv run --group doc sphinx-build doc/source/ ./doc/build/html/

build-wheels:
uv build
uv build --wheel -C="--global-option=--net46-support"
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
graft src/runtime
prune src/runtime/obj
prune src/runtime/bin
graft src/compat
include src/pythonnet.snk
include Directory.Build.*
include pythonnet.sln
Expand Down
3 changes: 2 additions & 1 deletion doc/source/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ 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. For .NET 4.6 support, the wheel has
to be built with the environment variable `PYTHONNET_BUILD_NET46_SUPPORT=1`.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be outdated now, judging by uv build --wheel -C="--global-option=--net46-support" below


.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 @@ -55,6 +55,9 @@ email = "pythonnet@python.org"
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 = []
33 changes: 16 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import distutils
from distutils.command.build import build as _build
from setuptools.command.develop import develop as _develop
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
from setuptools import Distribution
from setuptools import setup, Command

import os
import sys

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

NET46_SUPPORT_OPTION = "--net46-support"
NET46_SUPPORT = NET46_SUPPORT_OPTION in sys.argv
if NET46_SUPPORT:
sys.argv.remove(NET46_SUPPORT_OPTION)


class DotnetLib:
def __init__(self, name, path, **kwargs):
Expand Down Expand Up @@ -106,33 +111,27 @@ def install_for_development(self):
return super().install_for_development()


class bdist_wheel(_bdist_wheel):
def finalize_options(self):
# Monkey patch bdist_wheel to think the package is pure even though we
# include DLLs
super().finalize_options()
self.root_is_pure = True


# Monkey-patch Distribution s.t. it supports the dotnet_libs attribute
Distribution.dotnet_libs = None

cmdclass = {
"build": build,
"build_dotnet": build_dotnet,
"develop": develop,
"bdist_wheel": bdist_wheel,
}

dotnet_libs = [
DotnetLib(
"python-runtime",
"src/runtime/Python.Runtime.csproj",
output="pythonnet/runtime",
)
]

if NET46_SUPPORT:
csproj = "src/compat/Python.Runtime.Compat.csproj"
plat_name = "win32"
else:
csproj = "src/runtime/Python.Runtime.csproj"
plat_name = "any"

dotnet_libs = [DotnetLib("python-runtime", csproj, output="pythonnet/runtime")]

setup(
cmdclass=cmdclass,
dotnet_libs=dotnet_libs,
options={"bdist_wheel": {"plat_name": plat_name}},
)
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>
23 changes: 23 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,28 @@ 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.
// Only needed on .NET Framework; on .NET (Core) this causes
// duplicate assembly loads, as .deps.json is respected and
// the correct assembly is already found.
if (typeof(object).Assembly.GetName().Name == "mscorlib")
{
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
Loading