Skip to content

Remove shebang line from easy_install generated python scripts on Windows only #148673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@
from collections import defaultdict

import setuptools.command.build_ext
import setuptools.command.install
import setuptools.command.sdist
from setuptools import Extension, find_packages, setup
from setuptools.command.install import install
from setuptools.dist import Distribution
from tools.build_pytorch_libs import build_pytorch
from tools.generate_torch_version import get_torch_version
Expand All @@ -268,6 +268,22 @@
from tools.setup_helpers.generate_linker_script import gen_linker_script


class SetupToolsInstallOverride(install):
def run(self):
super().run()
if sys.platform == "win32":
self.remove_shebang_from_easy_install_generated_scripts()

def remove_shebang_from_easy_install_generated_scripts(self):
for script in self.get_outputs():
if script.endswith("-script.py"):
with open(script, "rb") as f:
lines = f.readlines()
if len(lines) > 0 and lines[0].startswith(b"#!"):
with open(script, "wb") as f:
f.writelines(lines[1:])


def _get_package_path(package_name):
spec = importlib.util.find_spec(package_name)
if spec:
Expand Down Expand Up @@ -1068,7 +1084,7 @@ def make_relative_rpath_args(path):
"bdist_wheel": wheel_concatenate,
"build_ext": build_ext,
"clean": clean,
"install": install,
"install": SetupToolsInstallOverride,
"sdist": sdist,
}

Expand Down
Loading