Skip to content

Commit 9e80044

Browse files
replace offending os.getlogin call with getpass.getuser (#419)
1 parent 4aded51 commit 9e80044

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/ansys/dynamicreporting/core/utils/filelock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# Modules
3131
# ------------------------------------------------
3232
import functools
33+
import getpass
3334
import logging
3435
import os
3536
import threading
@@ -473,7 +474,7 @@ def nexus_file_lock(filename: str) -> BaseFileLock:
473474
# We will consider two pathnames:
474475
# 1) the original pathname
475476
# 2) replace the original filename directory with tempfile.gettempdir()
476-
base_filename = os.path.basename(filename) + "." + os.getlogin()
477+
base_filename = os.path.basename(filename) + "." + getpass.getuser()
477478
lcl_filename = os.path.join(tempfile.gettempdir(), base_filename)
478479

479480
# if we are on Linux and the target filename is on an NFS drive

tests/test_filelock.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,11 @@ def test_soft(request) -> None:
111111
def test_nexus_filelock(request) -> None:
112112
test_path = join(request.fspath.dirname, "test_data")
113113
tmp_file = join(test_path, "n_lock.txt")
114-
try:
115-
success = type(fl.nexus_file_lock(filename=tmp_file)) is fl.FileLock
116-
except OSError: # Error due to not being able to get os.getlogin() on the machine
117-
success = True
118-
else:
119-
success = False
120-
if "win" in platform.system().lower():
121-
success = True
122-
assert success
114+
115+
lock = fl.nexus_file_lock(filename=tmp_file)
116+
117+
# Debug info
118+
print("Resolved lock type:", type(lock))
119+
print("Expected FileLock type:", fl.FileLock)
120+
121+
assert isinstance(lock, fl.FileLock)

0 commit comments

Comments
 (0)