|
3 | 3 | import distutils |
4 | 4 | from distutils.command.build import build as _build |
5 | 5 | 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 |
6 | 10 | from setuptools import Distribution |
7 | 11 | from setuptools import setup, Command |
8 | 12 |
|
|
16 | 20 | NET46_SUPPORT = NET46_SUPPORT_OPTION in sys.argv |
17 | 21 | if NET46_SUPPORT: |
18 | 22 | sys.argv.remove(NET46_SUPPORT_OPTION) |
| 23 | +WINDOWS_PLATFORM_TAG = "win32.win_amd64" |
19 | 24 |
|
20 | 25 |
|
21 | 26 | class DotnetLib: |
@@ -111,27 +116,51 @@ def install_for_development(self): |
111 | 116 | return super().install_for_development() |
112 | 117 |
|
113 | 118 |
|
| 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 | + |
114 | 145 | # Monkey-patch Distribution s.t. it supports the dotnet_libs attribute |
115 | 146 | Distribution.dotnet_libs = None |
116 | 147 |
|
117 | 148 | cmdclass = { |
118 | 149 | "build": build, |
119 | 150 | "build_dotnet": build_dotnet, |
120 | 151 | "develop": develop, |
| 152 | + "bdist_wheel": bdist_wheel, |
121 | 153 | } |
122 | 154 |
|
123 | 155 |
|
124 | 156 | if NET46_SUPPORT: |
125 | 157 | csproj = "src/compat/Python.Runtime.Compat.csproj" |
126 | | - plat_name = "win32" |
127 | 158 | else: |
128 | 159 | csproj = "src/runtime/Python.Runtime.csproj" |
129 | | - plat_name = "any" |
130 | 160 |
|
131 | 161 | dotnet_libs = [DotnetLib("python-runtime", csproj, output="pythonnet/runtime")] |
132 | 162 |
|
133 | 163 | setup( |
134 | 164 | cmdclass=cmdclass, |
135 | 165 | dotnet_libs=dotnet_libs, |
136 | | - options={"bdist_wheel": {"plat_name": plat_name}}, |
137 | 166 | ) |
0 commit comments