Skip to content

Commit e396580

Browse files
committed
Choose shebang rewriting for pyproject scripts to match shebang target
Remember that linux has a very small (127) character shebang limit and /usr/bin/env should be used all the time except for cases where SIP is involved on macOS.
1 parent 1ca295d commit e396580

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

python/lsst/sconsUtils/builders.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from . import state
1717
from .installation import determineVersion, getFingerprint
18-
from .utils import memberOf, whichPython
18+
from .utils import memberOf, needShebangRewrite, whichPython
1919

2020

2121
@memberOf(SConsEnvironment)
@@ -805,11 +805,17 @@ def makePythonScript(target, source, env):
805805
return
806806
os.makedirs(os.path.dirname(cmdfile), exist_ok=True)
807807
package, func = scripts[command].split(":", maxsplit=1)
808+
python_exe = whichPython()
809+
if needShebangRewrite():
810+
shebang = python_exe
811+
else:
812+
# Linux has very small shebang limit so always use env.
813+
shebang = f"/usr/bin/env {os.path.basename(python_exe)}"
808814
with open(cmdfile, "w") as fd:
809815
# Follow setuptools convention and always change the shebang.
810816
# Can not add noqa on Linux for long paths so do not add anywhere.
811817
print(
812-
rf"""#!{whichPython()}
818+
rf"""#!{shebang}
813819
import sys
814820
from {package} import {func}
815821
if __name__ == '__main__':

0 commit comments

Comments
 (0)