From b0ffd8a08c6eb9cd0d5d366f2e907a02c7dfd4c2 Mon Sep 17 00:00:00 2001 From: torzdf <36920800+torzdf@users.noreply.github.com> Date: Mon, 10 Dec 2018 11:09:54 +0000 Subject: [PATCH] Add virtual_env check to sysinfo --- lib/sysinfo.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/sysinfo.py b/lib/sysinfo.py index 75255362..cb25ff07 100644 --- a/lib/sysinfo.py +++ b/lib/sysinfo.py @@ -38,19 +38,25 @@ class SysInfo(): @property def is_linux(self): - """ Boolean for whether in a conda environment """ + """ Boolean for whether system is Linux """ return self.system.lower() == "linux" @property def is_macos(self): - """ Boolean for whether in a conda environment """ + """ Boolean for whether system is macOS """ return self.system.lower() == "darwin" @property def is_windows(self): - """ Boolean for whether in a conda environment """ + """ Boolean for whether system is Windows """ return self.system.lower() == "windows" + @property + def is_virtual_env(self): + """ Boolean for whether running in a virtual environment """ + return hasattr(sys, "real_prefix") or ( + hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix) + @property def ram(self): """ Return RAM stats """ @@ -241,6 +247,7 @@ class SysInfo(): "py_implementation": self.py_implementation, "py_version": self.py_version, "py_command": self.fs_command, + "py_virtual_env": self.is_virtual_env, "sys_cores": self.cpu_count, "sys_processor": self.processor, "sys_ram": self.format_ram(),