Skip to content

Commit 0238387

Browse files
authored
Merge pull request #2701 from Metadorius/feature/net461
Support .NET Framework 4.6.1
2 parents 39c575e + 19dc42e commit 0238387

11 files changed

Lines changed: 88 additions & 19 deletions

File tree

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@
8989
- Ehsan Iran-Nejad ([@eirannejad](https://github.com/eirannejad))
9090
- ([@legomanww](https://github.com/legomanww))
9191
- ([@gertdreyer](https://github.com/gertdreyer))
92+
- Kerbiter ([@Metadorius](https://github.com/Metadorius))

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1010
### Added
1111

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

1415
### Changed
1516
### Fixed
1617

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

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

Justfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
default:
2+
@just --choose
3+
4+
setup:
5+
dotnet restore
6+
uv sync
7+
8+
docs:
9+
doxygen doc/Doxyfile
10+
uv run --group doc sphinx-build doc/source/ ./doc/build/html/
11+
12+
build-wheels:
13+
uv build
14+
uv build --wheel -C="--global-option=--net46-support"

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
graft src/runtime
22
prune src/runtime/obj
33
prune src/runtime/bin
4+
graft src/compat
45
include src/pythonnet.snk
56
include Directory.Build.*
67
include pythonnet.sln

doc/source/python.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ Mono (``mono``)
4545

4646
.NET Framework (``netfx``)
4747
Default on Windows and also only supported there. Must be at least version
48-
4.7.2.
48+
4.6.1, with 4.7.2 or later recommended. For .NET 4.6 support, the wheel has
49+
to be built with the environment variable `PYTHONNET_BUILD_NET46_SUPPORT=1`.
4950

5051
.NET Core (``coreclr``)
5152
Self-contained is not supported, must be at least version 3.1.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ email = "pythonnet@python.org"
5555
Homepage = "https://pythonnet.github.io/"
5656
Sources = "https://github.com/pythonnet/pythonnet"
5757

58+
[project.entry-points.pyinstaller40]
59+
hook-dirs = "pythonnet._pyinstaller:get_hook_dirs"
60+
5861
[tool.setuptools]
5962
zip-safe = false
6063
py-modules = ["clr"]

pythonnet/_pyinstaller/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
def get_hook_dirs():
4+
return [os.path.dirname(__file__)]

pythonnet/_pyinstaller/hook-clr.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from PyInstaller.utils.hooks import collect_data_files, collect_dynamic_libs
2+
3+
try:
4+
binaries = collect_dynamic_libs("pythonnet")
5+
datas = collect_data_files("pythonnet")
6+
except Exception:
7+
# name conflict with https://pypi.org/project/clr/, do not crash if just clr is present
8+
binaries = []
9+
datas = []

setup.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
import distutils
44
from distutils.command.build import build as _build
55
from setuptools.command.develop import develop as _develop
6-
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
76
from setuptools import Distribution
87
from setuptools import setup, Command
98

109
import os
10+
import sys
1111

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

15+
NET46_SUPPORT_OPTION = "--net46-support"
16+
NET46_SUPPORT = NET46_SUPPORT_OPTION in sys.argv
17+
if NET46_SUPPORT:
18+
sys.argv.remove(NET46_SUPPORT_OPTION)
19+
1520

1621
class DotnetLib:
1722
def __init__(self, name, path, **kwargs):
@@ -106,33 +111,27 @@ def install_for_development(self):
106111
return super().install_for_development()
107112

108113

109-
class bdist_wheel(_bdist_wheel):
110-
def finalize_options(self):
111-
# Monkey patch bdist_wheel to think the package is pure even though we
112-
# include DLLs
113-
super().finalize_options()
114-
self.root_is_pure = True
115-
116-
117114
# Monkey-patch Distribution s.t. it supports the dotnet_libs attribute
118115
Distribution.dotnet_libs = None
119116

120117
cmdclass = {
121118
"build": build,
122119
"build_dotnet": build_dotnet,
123120
"develop": develop,
124-
"bdist_wheel": bdist_wheel,
125121
}
126122

127-
dotnet_libs = [
128-
DotnetLib(
129-
"python-runtime",
130-
"src/runtime/Python.Runtime.csproj",
131-
output="pythonnet/runtime",
132-
)
133-
]
123+
124+
if NET46_SUPPORT:
125+
csproj = "src/compat/Python.Runtime.Compat.csproj"
126+
plat_name = "win32"
127+
else:
128+
csproj = "src/runtime/Python.Runtime.csproj"
129+
plat_name = "any"
130+
131+
dotnet_libs = [DotnetLib("python-runtime", csproj, output="pythonnet/runtime")]
134132

135133
setup(
136134
cmdclass=cmdclass,
137135
dotnet_libs=dotnet_libs,
136+
options={"bdist_wheel": {"plat_name": plat_name}},
138137
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- A dummy project to force MSBuild to package .NET 4.6.1 requirements -->
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net461</TargetFramework>
5+
<OutputType>Library</OutputType>
6+
<!-- Don't copy the dummy assembly/pdb to output; we only need the resolved references -->
7+
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
8+
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<ProjectReference Include="..\runtime\Python.Runtime.csproj" />
12+
</ItemGroup>
13+
</Project>

0 commit comments

Comments
 (0)