diff --git a/agentops/host_env.py b/agentops/host_env.py index 4eff0c89..13d27943 100644 --- a/agentops/host_env.py +++ b/agentops/host_env.py @@ -2,6 +2,9 @@ import psutil import socket from .helpers import get_agentops_version +import importlib.metadata +import os +import sys def get_sdk_details(): @@ -9,6 +12,68 @@ def get_sdk_details(): return { "AgentOps SDK Version": get_agentops_version(), "Python Version": platform.python_version(), + "System Packages": get_sys_packages() + } + except: + return {} + + +def get_python_details(): + try: + return { + "Python Version": platform.python_version() + } + except: + return {} + + +def get_agentops_details(): + try: + return { + "AgentOps SDK Version": get_agentops_version() + } + except: + return {} + + +def get_sys_packages(): + sys_packages = {} + for module in sys.modules: + try: + version = importlib.metadata.version(module) + sys_packages[module] = version + except importlib.metadata.PackageNotFoundError: + # Skip built-in modules and those without package metadata + continue + + return sys_packages + + +def get_installed_packages(): + + try: + return { + # TODO: test + # TODO: add to opt out + "Installed Packages": {dist.metadata['Name']: dist.version for dist in importlib.metadata.distributions()} + } + except: + return {} + + +def get_current_directory(): + try: + return { + "Project Working Directory": os.getcwd() + } + except: + return {} + + +def get_virtual_env(): + try: + return { + "Virtual Environment": os.environ.get('VIRTUAL_ENV', None) } except: return {} @@ -51,7 +116,6 @@ def get_ram_details(): return {} - def get_disk_details(): partitions = psutil.disk_partitions() disk_info = {} @@ -71,7 +135,9 @@ def get_host_env(opt_out: bool = False): if opt_out: return { "SDK": get_sdk_details(), - "OS": get_os_details() + "OS": get_os_details(), + "Project Working Directory": get_current_directory(), + "Virtual Environment": get_virtual_env() } else: return { @@ -80,4 +146,7 @@ def get_host_env(opt_out: bool = False): "CPU": get_cpu_details(), "RAM": get_ram_details(), "Disk": get_disk_details(), + "Installed Packages": get_installed_packages(), + "Project Working Directory": get_current_directory(), + "Virtual Environment": get_virtual_env() }