Repository: Project-MONAI/MONAI

Issue:
print_config to hide user info
**Is your feature request related to a problem? Please describe.**
https://github.com/Project-MONAI/MONAI/blob/25c9c3951858bd60b4d02bcaca7fff9c4236bff7/monai/config/deviceconfig.py#L101

`print_config` is extensively used in the notebooks, and would be great to make sure the output not leaking any user-specific information such as `/home/username`


Discussion:
Heyy @wyli Just wanted to check if this issue is still open?
yes @owais8 please feel free to create a pull request.
Hey @wyli I have noticed there isn't any pull request for this issue and I would like to work on it if it is still open to my knowledge I think I have to replace the code in deviceconfig.py to replace the user's home directory with a generic representation using the os.path.expanduser('~') method. 
Thanks @anudeepadi, the goal of the print is to provide diagnostic info about where monai is actually located in user's system, but the usernames in the logs should be masked out. Perhaps you can do it with a simple regex replacing, or if you are interested, feel free to enhance the monai logger to have a generic filter to hide sensitive info. 

https://github.com/Project-MONAI/MONAI/blob/3b6b11a815b2de9e2b1bc1f1dbbca4e66189458f/monai/apps/utils.py#L48C1-L48C1


Please have a look at the contrib doc https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md  and let me know if you have questions regarding new pull requests.
Hello @wyli,

I've worked on the feature to mask out usernames in the `print_config` function to prevent leaking user-specific information. I've tested the function for paths in different operating systems, and it looks good. The function now masks the username from paths and retains all other information for diagnostic purposes.

I apologize for the delay in getting to this, and I appreciate your patience.

Could you please review the code and let me know if anything else is needed before I can raise a pull request?


```python 
import re

def print_config(file=sys.stdout):
    """
    Print the package versions to `file`.

    Args:
        file: `print()` text stream file. Defaults to `sys.stdout`.
    """

    for k, v in get_config_values().items():
        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__)))
    
    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():
        print(f"{k} version: {v}", file=file, flush=True)
    print("\nFor details about installing the optional dependencies, please visit:", file=file, flush=True)
    print(
        "    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
        file=file,
        flush=True,
    )
```
thanks @anudeepadi, that's a nice starting point. please submit a pull request https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md#preparing-pull-requests

Resolving patch:
diff --git a/monai/config/deviceconfig.py b/monai/config/deviceconfig.py
--- a/monai/config/deviceconfig.py
+++ b/monai/config/deviceconfig.py
@@ -100,8 +100,16 @@ 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__}")
-    print(f"MONAI __file__: {monai.__file__}")
-
+    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__),
+        ),
+    )
+    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():
         print(f"{k} version: {v}", file=file, flush=True)


Test patch: