Open
Conversation
This merge removes `LD_LIBRARY_PATH` and `LD_PRELOAD` from the environment before making `hsi` calls so conda or pixi environments don't cause conflicts (e.g. with `libncurses`).
Contributor
Author
|
I'm not in a great position to test #!/usr/bin/env python3
import os
import shlex
import subprocess
import sys
def build_env(mode: str) -> dict[str, str]:
env = os.environ.copy()
if mode == "inherit":
return env
if mode == "drop-loader":
env.pop("LD_LIBRARY_PATH", None)
env.pop("LD_PRELOAD", None)
return env
if mode == "drop-pixi":
env.pop("LD_LIBRARY_PATH", None)
env.pop("LD_PRELOAD", None)
for key in list(env):
if key.startswith("PIXI_") or key.startswith("CONDA_"):
env.pop(key, None)
return env
if mode == "minimal":
return {
"HOME": env["HOME"],
"USER": env.get("USER", ""),
"LOGNAME": env.get("LOGNAME", ""),
"PATH": "/usr/bin:/bin",
"TERM": env.get("TERM", "xterm"),
}
raise ValueError(f"Unknown mode: {mode}")
def main() -> int:
mode = sys.argv[1] if len(sys.argv) > 1 else "inherit"
command = " ".join(sys.argv[2:]) if len(sys.argv) > 2 else "hsi --help"
env = build_env(mode)
args = shlex.split(command)
print(f"mode={mode}")
print(f"command={args}")
for key in ["LD_LIBRARY_PATH", "LD_PRELOAD", "PATH", "HOME", "USER", "LOGNAME"]:
print(f"{key}={env.get(key)!r}")
print("-" * 60)
proc = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env,
text=True,
)
stdout, stderr = proc.communicate()
print(f"returncode={proc.returncode}")
print("stdout:")
print(stdout if stdout else "<empty>")
print("stderr:")
print(stderr if stderr else "<empty>")
return proc.returncode
if __name__ == "__main__":
raise SystemExit(main())When this script is run from the e3sm-unified 1.13.0rc4 environment, I see: reproduces the error: The implementation here is equivalent to: which produces a clean help message from |
Collaborator
@xylar I've run the test suite using the commits from this branch, but in a Testing detailscd ~/ez/zstash
git status
# On branch main
# nothing to commit, working tree clean
git fetch xylar isolate-hsi-calls
git checkout -b isolate-hsi-calls xylar/isolate-hsi-calls
nersc_conda # Bash function to activate conda
rm -rf build
conda clean --all --y
conda env create -f conda/dev.yml -n zstash_pr440_20260410
conda activate zstash_pr440_20260410
pre-commit run --all-files
python -m pip install .
git log --oneline | head -n 3
# 2aca27b Add unit tests for sanitized commands
# f916017 Sanitize environment before `hsi` subprocess calls
# ed6a77e Bump to 1.6.0rc1 (#438)
# Good, matches https://github.com/E3SM-Project/zstash/pull/440/commits
# AND is based off 1.6.0rc1
pytest tests/unit/test_*.py
# 27 passed, 46 warnings in 0.56s
python -m unittest tests/integration/python_tests/group_by_command/test_*.py
# Ran 69 tests in 412.734s
# OK
python -m unittest tests/integration/python_tests/group_by_workflow/test_*.py
# Ran 4 tests in 5.055s
# OK
cd tests/integration/bash_tests/run_from_perlmutter/
time ./follow_symlinks.sh
# real 0m40.858s
# Good, no errors
time ./test_update_non_empty_hpss.bash
# real 0m11.592s
# Good, no errors
# Log into globus.org
# Log into endpoints (NERSC Perlmutter, Globus Tutorial Collection 1) at globus.org: File Manager > Add the endpoints in the "Collection" fields
time ./test_ls_globus.bash # NOTE: Paste auth code
# real 0m41.169s
# No errors✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Objectives:
hsierrors related tolibncursesin Unified 1.13.0rc4 reported in E3SM Unified 1.13.0 testing #439Issue resolution:
Select one: This pull request is...
Please fill out either the "Small Change" or "Big Change" section (the latter includes the numbered subsections), and delete the other.
Small Change