From df1779b742caa7ffdfa4115eafff3ce96da0c6f1 Mon Sep 17 00:00:00 2001 From: Anish Rajan Date: Fri, 1 Sep 2023 05:20:19 +0530 Subject: [PATCH] Robust Username Masking in print_config (#6922) Fixes #6914. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: anishrajan25 --- monai/config/deviceconfig.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/monai/config/deviceconfig.py b/monai/config/deviceconfig.py index 023eb8bfd3..a4580c741b 100644 --- a/monai/config/deviceconfig.py +++ b/monai/config/deviceconfig.py @@ -11,6 +11,7 @@ from __future__ import annotations +import getpass import os import platform import re @@ -100,15 +101,8 @@ def print_config(file=sys.stdout): print(f"{k} version: {v}", file=file, flush=True) print(f"MONAI flags: HAS_EXT = {HAS_EXT}, USE_COMPILED = {USE_COMPILED}, USE_META_DICT = {USE_META_DICT}") print(f"MONAI rev id: {monai.__revision_id__}") - masked_file_path = re.sub( - r"/home/\w+/", - "/home//", - re.sub( - r"/Users/\w+/", - "/Users//", - re.sub(r"C:\\Users\\\w+\\", r"C:\\Users\\\\", monai.__file__), - ), - ) + username = getpass.getuser() + masked_file_path = re.sub(username, "", monai.__file__) print(f"MONAI __file__: {masked_file_path}", file=file, flush=True) print("\nOptional dependencies:", file=file, flush=True) for k, v in get_optional_config_values().items():