From b063765c2efecb7937d9f6bbbbb34cd41efd1286 Mon Sep 17 00:00:00 2001 From: Martin Lang <67915889+lang-m@users.noreply.github.com> Date: Thu, 24 Oct 2024 21:26:04 +0200 Subject: [PATCH] miniforge3: wrong sbang replacement (#47178) --- .../repos/builtin/packages/miniforge3/package.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/var/spack/repos/builtin/packages/miniforge3/package.py b/var/spack/repos/builtin/packages/miniforge3/package.py index f690742acaf..8f5d3c05e25 100644 --- a/var/spack/repos/builtin/packages/miniforge3/package.py +++ b/var/spack/repos/builtin/packages/miniforge3/package.py @@ -56,6 +56,21 @@ def install(self, spec, prefix): bash = which("bash") bash(script, "-b", "-f", "-p", self.prefix) + @run_after("install") + def patch_sbang(self): + # Conda replaces the full path to the Python executable with `/usr/bin/env python` + # if the full path exceeds 127 characters. This does however break `conda deactivate` + # because the wrong Python interpreter is used after activating an environment. + # The 127 character limit is not relevant in Spack as Spack will automatically + # use the `sbang` script to deal with the overly long sbang line. + filter_file( + r"#!/usr/bin/env python", rf"#!{self.prefix.bin.python}", self.prefix.bin.conda + ) + if "+mamba" in self.spec: + filter_file( + r"#!/usr/bin/env python", rf"#!{self.prefix.bin.python}", self.prefix.bin.mamba + ) + def setup_run_environment(self, env): filename = self.prefix.etc.join("profile.d").join("conda.sh") env.extend(EnvironmentModifications.from_sourcing_file(filename))