Skip to content

Commit 4e61c18

Browse files
authored
Merge pull request #2716 from pythonnet/fix-wheel-tags
Fix wheel tags
1 parent 0238387 commit 4e61c18

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=80"]
2+
requires = ["setuptools>=80", "packaging>=24", "pyproject-parser>=0.14"]
33
build-backend = "setuptools.build_meta"
44

55
[project]

setup.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import distutils
44
from distutils.command.build import build as _build
55
from setuptools.command.develop import develop as _develop
6+
from setuptools.command.bdist_wheel import bdist_wheel as _bdist_wheel
7+
from packaging.specifiers import SpecifierSet
8+
from packaging.version import Version
9+
from pyproject_parser import PyProject
610
from setuptools import Distribution
711
from setuptools import setup, Command
812

@@ -16,6 +20,7 @@
1620
NET46_SUPPORT = NET46_SUPPORT_OPTION in sys.argv
1721
if NET46_SUPPORT:
1822
sys.argv.remove(NET46_SUPPORT_OPTION)
23+
WINDOWS_PLATFORM_TAG = "win32.win_amd64"
1924

2025

2126
class DotnetLib:
@@ -111,27 +116,51 @@ def install_for_development(self):
111116
return super().install_for_development()
112117

113118

119+
class bdist_wheel(_bdist_wheel):
120+
def get_tag(self):
121+
if NET46_SUPPORT:
122+
platform_tag = WINDOWS_PLATFORM_TAG
123+
else:
124+
platform_tag = "any"
125+
abi_tag = "none"
126+
python_tag = self._get_python_tag()
127+
return python_tag, abi_tag, platform_tag
128+
129+
def _get_python_tag(self) -> str:
130+
pyproject = PyProject.load("pyproject.toml")
131+
project = pyproject.project or {}
132+
133+
requires_python = project.get("requires-python")
134+
if not requires_python:
135+
raise RuntimeError("project.requires-python is required")
136+
137+
specifiers = SpecifierSet(str(requires_python))
138+
return ".".join(
139+
f"cp3{minor}"
140+
for minor in range(0, 100)
141+
if specifiers.contains(Version(f"3.{minor}"), prereleases=True)
142+
)
143+
144+
114145
# Monkey-patch Distribution s.t. it supports the dotnet_libs attribute
115146
Distribution.dotnet_libs = None
116147

117148
cmdclass = {
118149
"build": build,
119150
"build_dotnet": build_dotnet,
120151
"develop": develop,
152+
"bdist_wheel": bdist_wheel,
121153
}
122154

123155

124156
if NET46_SUPPORT:
125157
csproj = "src/compat/Python.Runtime.Compat.csproj"
126-
plat_name = "win32"
127158
else:
128159
csproj = "src/runtime/Python.Runtime.csproj"
129-
plat_name = "any"
130160

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

133163
setup(
134164
cmdclass=cmdclass,
135165
dotnet_libs=dotnet_libs,
136-
options={"bdist_wheel": {"plat_name": plat_name}},
137166
)

0 commit comments

Comments
 (0)