Skip to content

Commit 19dc42e

Browse files
committed
Build .NET 4.6 support conditionally
1 parent 89a4b24 commit 19dc42e

4 files changed

Lines changed: 33 additions & 18 deletions

File tree

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.6.1, with 4.7.2 or later recommended.
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.

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/compat/Python.Runtime.Compat.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
)

0 commit comments

Comments
 (0)