Skip to content

Commit

Permalink
Robust Username Masking in print_config (#6922)
Browse files Browse the repository at this point in the history
Fixes #6914.


### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [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 <anishrajan2708@gmail.com>
  • Loading branch information
anishrajan25 authored Aug 31, 2023
1 parent be4e1f5 commit df1779b
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions monai/config/deviceconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from __future__ import annotations

import getpass
import os
import platform
import re
Expand Down Expand Up @@ -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/<username>/",
re.sub(
r"/Users/\w+/",
"/Users/<username>/",
re.sub(r"C:\\Users\\\w+\\", r"C:\\Users\\<username>\\", monai.__file__),
),
)
username = getpass.getuser()
masked_file_path = re.sub(username, "<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():
Expand Down

0 comments on commit df1779b

Please sign in to comment.