Skip to content

Commit

Permalink
Adding data to host_env (#205)
Browse files Browse the repository at this point in the history
* Added stuff to host_env

* Undo last reset

* Put back critical stuff

* undoing whitespace change
  • Loading branch information
HowieG authored May 16, 2024
1 parent 5b13f9b commit ed9d7b3
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions agentops/host_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,78 @@
import psutil
import socket
from .helpers import get_agentops_version
import importlib.metadata
import os
import sys


def get_sdk_details():
try:
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 {}
Expand Down Expand Up @@ -51,7 +116,6 @@ def get_ram_details():
return {}



def get_disk_details():
partitions = psutil.disk_partitions()
disk_info = {}
Expand All @@ -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 {
Expand All @@ -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()
}

0 comments on commit ed9d7b3

Please sign in to comment.