From 2b0417f7c42ad1e28e3fc8051e163bf689000a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Krzy=C5=9Bk=C3=B3w?= <34622465+kamilkrzyskow@users.noreply.github.com> Date: Sun, 29 Jun 2025 18:43:26 +0200 Subject: [PATCH] Updated info plugin to exclude guessed venv paths (#8286) * Updated info plugin to hide usernames * Updated info plugin to show active venv directory * Updated info plugin to exclude possible venv paths * Added exception handling in info plugin --- material/plugins/info/plugin.py | 23 ++++++++++++++++++++++- src/plugins/info/plugin.py | 23 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/material/plugins/info/plugin.py b/material/plugins/info/plugin.py index 4ec2e802b..efc7c939a 100644 --- a/material/plugins/info/plugin.py +++ b/material/plugins/info/plugin.py @@ -18,6 +18,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +import getpass import glob import json import logging @@ -200,6 +201,19 @@ class InfoPlugin(BasePlugin[InfoConfig]): if path.startswith(os.getcwd()): self.exclusion_patterns.append(_resolve_pattern(path)) + # Guess other Virtual Environment paths in case we forget to activate + # them or in case we have multiple. Making sure which venv is activated + # is not necessary, as it is an optional step in the guidelines. + for path in glob.iglob( + pathname = "**/pyvenv.cfg", + root_dir = os.getcwd(), + recursive = True + ): + path = os.path.join(os.getcwd(), os.path.dirname(path)) + if path not in site.PREFIXES: + print(f"Possible inactive venv: {path}") + self.exclusion_patterns.append(_resolve_pattern(path)) + # Exclude site_dir for projects if projects_plugin: for path in glob.iglob( @@ -266,6 +280,12 @@ class InfoPlugin(BasePlugin[InfoConfig]): ])) ) + # Try to get login to replace it with USERNAME placeholder + try: + username = getpass.getuser() + except Exception: + username = "" + # Add information on platform f.writestr( os.path.join(example, "platform.json"), @@ -280,12 +300,13 @@ class InfoPlugin(BasePlugin[InfoConfig]): *sys.argv[1:] ]), "env:$PYTHONPATH": os.getenv("PYTHONPATH", ""), + "env:$VIRTUAL_ENV": os.getenv("VIRTUAL_ENV", ""), "sys.path": sys.path, "excluded_entries": self.excluded_entries }, default = str, indent = 2 - ) + ).replace(username, "USERNAME") ) # Retrieve list of processed files diff --git a/src/plugins/info/plugin.py b/src/plugins/info/plugin.py index 4ec2e802b..efc7c939a 100644 --- a/src/plugins/info/plugin.py +++ b/src/plugins/info/plugin.py @@ -18,6 +18,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +import getpass import glob import json import logging @@ -200,6 +201,19 @@ class InfoPlugin(BasePlugin[InfoConfig]): if path.startswith(os.getcwd()): self.exclusion_patterns.append(_resolve_pattern(path)) + # Guess other Virtual Environment paths in case we forget to activate + # them or in case we have multiple. Making sure which venv is activated + # is not necessary, as it is an optional step in the guidelines. + for path in glob.iglob( + pathname = "**/pyvenv.cfg", + root_dir = os.getcwd(), + recursive = True + ): + path = os.path.join(os.getcwd(), os.path.dirname(path)) + if path not in site.PREFIXES: + print(f"Possible inactive venv: {path}") + self.exclusion_patterns.append(_resolve_pattern(path)) + # Exclude site_dir for projects if projects_plugin: for path in glob.iglob( @@ -266,6 +280,12 @@ class InfoPlugin(BasePlugin[InfoConfig]): ])) ) + # Try to get login to replace it with USERNAME placeholder + try: + username = getpass.getuser() + except Exception: + username = "" + # Add information on platform f.writestr( os.path.join(example, "platform.json"), @@ -280,12 +300,13 @@ class InfoPlugin(BasePlugin[InfoConfig]): *sys.argv[1:] ]), "env:$PYTHONPATH": os.getenv("PYTHONPATH", ""), + "env:$VIRTUAL_ENV": os.getenv("VIRTUAL_ENV", ""), "sys.path": sys.path, "excluded_entries": self.excluded_entries }, default = str, indent = 2 - ) + ).replace(username, "USERNAME") ) # Retrieve list of processed files