@@ -189,18 +189,39 @@ def sanitize_env():
189189 """
190190 Sanitize environment.
191191
192- This function undefines all $PYTHON* environment variables,
193- since they may affect the build/install procedure of Python packages.
192+ This function:
194193
195- cfr. https://docs.python.org/2/using/cmdline.html#environment-variables
194+ * Filters out empty entries from environment variables like $PATH, $LD_LIBRARY_PATH, etc.
195+ Empty entries make no sense, and can cause problems,
196+ see for example https://github.com/easybuilders/easybuild-easyconfigs/issues/9843 .
196197
197- While the $PYTHON* environment variables may be relevant/required for EasyBuild itself,
198- and for any non-stdlib Python packages it uses,
199- they are irrelevant (and potentially harmful) when installing Python packages.
198+ * Undefines all $PYTHON* environment variables,
199+ since they may affect the build/install procedure of Python packages.
200200
201- Note that this is not an airtight protection against the Python being used in the build/install procedure
202- picking up non-stdlib Python packages (e.g., setuptools, vsc-base, ...), thanks to the magic of .pth files,
203- cfr. https://docs.python.org/2/library/site.html .
201+ cfr. https://docs.python.org/2/using/cmdline.html#environment-variables
202+
203+ While the $PYTHON* environment variables may be relevant/required for EasyBuild itself,
204+ and for any non-stdlib Python packages it uses,
205+ they are irrelevant (and potentially harmful) when installing Python packages.
206+
207+ Note that this is not an airtight protection against the Python being used in the build/install procedure
208+ picking up non-stdlib Python packages (e.g., setuptools, vsc-base, ...), thanks to the magic of .pth files,
209+ cfr. https://docs.python.org/2/library/site.html .
204210 """
211+
212+ # remove empty entries from $*PATH variables
213+ for key in ['CPATH' , 'LD_LIBRARY_PATH' , 'LIBRARY_PATH' , 'LD_PRELOAD' , 'PATH' ]:
214+ val = os .getenv (key )
215+ if val :
216+ entries = val .split (os .pathsep )
217+ if '' in entries :
218+ _log .info ("Found %d empty entries in $%s, filtering them out..." , entries .count ('' ), key )
219+ newval = os .pathsep .join (x for x in entries if x )
220+ if newval :
221+ setvar (key , newval )
222+ else :
223+ unset_env_vars ([key ], verbose = False )
224+
225+ # unset all $PYTHON* environment variables
205226 keys_to_unset = [key for key in os .environ if key .startswith ('PYTHON' )]
206227 unset_env_vars (keys_to_unset , verbose = False )
0 commit comments