|
257 | 257 | from collections import defaultdict
|
258 | 258 |
|
259 | 259 | import setuptools.command.build_ext
|
260 |
| -import setuptools.command.install |
261 | 260 | import setuptools.command.sdist
|
262 | 261 | from setuptools import Extension, find_packages, setup
|
| 262 | +from setuptools.command.install import install |
263 | 263 | from setuptools.dist import Distribution
|
264 | 264 | from tools.build_pytorch_libs import build_pytorch
|
265 | 265 | from tools.generate_torch_version import get_torch_version
|
|
268 | 268 | from tools.setup_helpers.generate_linker_script import gen_linker_script
|
269 | 269 |
|
270 | 270 |
|
| 271 | +class SetupToolsInstallOverride(install): |
| 272 | + def run(self): |
| 273 | + super().run() |
| 274 | + if sys.platform == "win32": |
| 275 | + self.remove_shebang_from_easy_install_generated_scripts() |
| 276 | + |
| 277 | + def remove_shebang_from_easy_install_generated_scripts(self): |
| 278 | + for script in self.get_outputs(): |
| 279 | + if script.endswith("-script.py"): |
| 280 | + with open(script, "rb") as f: |
| 281 | + lines = f.readlines() |
| 282 | + if len(lines) > 0 and lines[0].startswith(b"#!"): |
| 283 | + with open(script, "wb") as f: |
| 284 | + f.writelines(lines[1:]) |
| 285 | + |
| 286 | + |
271 | 287 | def _get_package_path(package_name):
|
272 | 288 | spec = importlib.util.find_spec(package_name)
|
273 | 289 | if spec:
|
@@ -1069,7 +1085,7 @@ def make_relative_rpath_args(path):
|
1069 | 1085 | "bdist_wheel": wheel_concatenate,
|
1070 | 1086 | "build_ext": build_ext,
|
1071 | 1087 | "clean": clean,
|
1072 |
| - "install": install, |
| 1088 | + "install": SetupToolsInstallOverride, |
1073 | 1089 | "sdist": sdist,
|
1074 | 1090 | }
|
1075 | 1091 |
|
|
0 commit comments