diff options
author | Greg Becker <becker33@llnl.gov> | 2022-11-08 10:36:10 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-08 10:36:10 -0800 |
commit | 97fe7ad32bcdab65beb080843c9eb7bbeae9cb51 (patch) | |
tree | e98306d6c2daaa29b9fc2aee28a25de26eca823c /lib | |
parent | 052bf6b9dfe6cf6539c22b915a9d026d6fc37cd6 (diff) | |
download | spack-97fe7ad32bcdab65beb080843c9eb7bbeae9cb51.tar.gz spack-97fe7ad32bcdab65beb080843c9eb7bbeae9cb51.tar.bz2 spack-97fe7ad32bcdab65beb080843c9eb7bbeae9cb51.tar.xz spack-97fe7ad32bcdab65beb080843c9eb7bbeae9cb51.zip |
use pwd for usernames on unix (#19980)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/util/path.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/spack/spack/util/path.py b/lib/spack/spack/util/path.py index c378f1eb2d..d18d719c8f 100644 --- a/lib/spack/spack/util/path.py +++ b/lib/spack/spack/util/path.py @@ -39,6 +39,18 @@ def architecture(): return spack.spec.ArchSpec((str(host_platform), str(host_os), str(host_target))) +def get_user(): + # User pwd where available because it accounts for effective uids when using ksu and similar + try: + # user pwd for unix systems + import pwd + + return pwd.getpwuid(os.geteuid()).pw_name + except ImportError: + # fallback on getpass + return getpass.getuser() + + # Substitutions to perform def replacements(): # break circular import from spack.util.executable @@ -48,7 +60,7 @@ def replacements(): return { "spack": spack.paths.prefix, - "user": getpass.getuser(), + "user": get_user(), "tempdir": tempfile.gettempdir(), "user_cache_path": spack.paths.user_cache_path, "architecture": str(arch), |