Skip to content

Commit 79df6bb

Browse files
committed
Remove shebang line from easy_install generated python scripts on
Windows only (#108602)
1 parent 002accf commit 79df6bb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

setup.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@
257257
from collections import defaultdict
258258

259259
import setuptools.command.build_ext
260-
import setuptools.command.install
261260
import setuptools.command.sdist
262261
from setuptools import Extension, find_packages, setup
262+
from setuptools.command.install import install
263263
from setuptools.dist import Distribution
264264
from tools.build_pytorch_libs import build_pytorch
265265
from tools.generate_torch_version import get_torch_version
@@ -268,6 +268,22 @@
268268
from tools.setup_helpers.generate_linker_script import gen_linker_script
269269

270270

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+
271287
def _get_package_path(package_name):
272288
spec = importlib.util.find_spec(package_name)
273289
if spec:
@@ -1069,7 +1085,7 @@ def make_relative_rpath_args(path):
10691085
"bdist_wheel": wheel_concatenate,
10701086
"build_ext": build_ext,
10711087
"clean": clean,
1072-
"install": install,
1088+
"install": SetupToolsInstallOverride,
10731089
"sdist": sdist,
10741090
}
10751091

0 commit comments

Comments
 (0)