From 6e9fe4cd2fe6080658ace308d5dacdd3e7c682b2 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Thu, 30 Nov 2023 09:13:19 +0100 Subject: [PATCH] fix python shebang in scripts --- CHANGELOG.md | 2 ++ cmeel/utils.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9efdbf..074fe61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- fix python shebang in scripts + ## [v0.52.1] - 2023-11-21 ## [v0.52.0] - 2023-11-21 diff --git a/cmeel/utils.py b/cmeel/utils.py index 4b56683..3c1a7a1 100644 --- a/cmeel/utils.py +++ b/cmeel/utils.py @@ -20,10 +20,7 @@ "The next patch would delete", ] -EXECUTABLE = """#!python -from cmeel.run import cmeel_run -cmeel_run() -""" +EXECUTABLE = ["#!python", "from cmeel.run import cmeel_run", "cmeel_run()"] class PatchError(CalledProcessError): @@ -176,7 +173,10 @@ def expose_bin(install: Path, wheel_dir: Path, distribution: str): with fn.open("rb") as fo: is_script = fo.read(2) == b"#!" with executable.open("w") as fe: - fe.write(fn.read_text() if is_script else EXECUTABLE) + content = fn.read_text().split("\n") if is_script else EXECUTABLE + if "python" in content[0]: + content = ["#!python", *content[1:]] + fe.write("\n".join(content)) executable.chmod(0o755)