From 91a4c4db8a4e352192ae71dcfb3b0d23976778bb Mon Sep 17 00:00:00 2001 From: Vignesh Rao Date: Wed, 1 Jan 2025 10:11:52 -0600 Subject: [PATCH] Release `v0.0.1` --- README.md | 43 +++++++--------------------------- pyarchitecture/__init__.py | 29 +++++++++++++---------- pyarchitecture/gpu/__init__.py | 2 +- pyproject.toml | 5 +++- 4 files changed, 29 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index e316059..2dd8934 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PyArchitecture -PyArchitecture is an ultra lightweight python module to get system architecture information. +PyArchitecture is a lightweight python module to get system architecture information. ![Python][label-pyversion] @@ -26,48 +26,21 @@ import pyarchitecture if __name__ == '__main__': all_disks = pyarchitecture.disks.get_all_disks() print(all_disks) + cpu_info = pyarchitecture.cpu.get_cpu_info() + print(cpu_info) + gpu_info = pyarchitecture.gpu.get_gpu_info() + print(gpu_info) + mem_info = pyarchitecture.memory.get_memory_info() + print(mem_info) ``` **Initiate - CLI** ```shell -pyarchitecture disk +pyarchitecture all ``` > Use `pyarchitecture --help` for usage instructions. -### Source Commands - -**Linux** - -```shell -/usr/bin/lsblk -o NAME,SIZE,TYPE,MODEL,MOUNTPOINT -J -``` - -**macOS** - -```shell -/usr/sbin/diskutil info -all -``` - -**Windows** - -```shell -C:\\Program Files\\PowerShell\\7\\pwsh.exe -Command -Get-PhysicalDisk | ForEach-Object { - $disk = $_ - $partitions = Get-Partition -DiskNumber $disk.DeviceID - $partitions | ForEach-Object { - [PSCustomObject]@{ - DiskNumber = $disk.DeviceID - Partition = $_.PartitionNumber - DriveLetter = (Get-Volume -Partition $_).DriveLetter - MountPoint = (Get-Volume -Partition $_).DriveLetter - } - } -} -``` - - ## Linting `pre-commit` will ensure linting diff --git a/pyarchitecture/__init__.py b/pyarchitecture/__init__.py index ee3bfbf..3c21ac1 100644 --- a/pyarchitecture/__init__.py +++ b/pyarchitecture/__init__.py @@ -1,12 +1,11 @@ import json -import pprint import sys import time -from typing import Any, Dict +from typing import Any, Dict, NoReturn from pyarchitecture import cpu, disks, gpu, memory -version = "0.0.0-a0" +version = "0.0.1" def all_components() -> Dict[str, Any]: @@ -19,11 +18,17 @@ def all_components() -> Dict[str, Any]: return { "Disks": disks.get_all_disks(), "CPU": cpu.get_cpu_info(), - "GPU": gpu.get_gpu_names(), + "GPU": gpu.get_gpu_info(), "Memory": memory.get_memory_info(), } +def pprint(data: Any) -> NoReturn: + """Pretty print the data and exit with return code 0.""" + print(json.dumps(data, indent=2)) + sys.exit(0) + + def commandline() -> None: """Starter function to invoke PyArchitecture via CLI commands. @@ -87,19 +92,17 @@ def commandline() -> None: sys.exit(0) if disk_info and not save_info: - pprint.pprint(disks.get_all_disks()) - sys.exit(0) + pprint(disks.get_all_disks()) if cpu_info and not save_info: - pprint.pprint(cpu.get_cpu_info()) - sys.exit(0) + pprint(cpu.get_cpu_info()) if gpu_info and not save_info: - pprint.pprint(gpu.get_gpu_names()) - sys.exit(0) + pprint(gpu.get_gpu_names()) if mem_info and not save_info: - pprint.pprint(memory.get_memory_info()) - sys.exit(0) + pprint(memory.get_memory_info()) + if all_info and not save_info: + pprint(all_components()) - if not any([disk_info, cpu_info, gpu_info]): + if not any([disk_info, cpu_info, gpu_info, all_info]): save_info = False if save_info: diff --git a/pyarchitecture/gpu/__init__.py b/pyarchitecture/gpu/__init__.py index 116549c..b9e0dd3 100644 --- a/pyarchitecture/gpu/__init__.py +++ b/pyarchitecture/gpu/__init__.py @@ -24,7 +24,7 @@ def _get_gpu_lib(user_input: str | os.PathLike) -> str: return gpu_lib -def get_gpu_names(gpu_lib: str | os.PathLike = None) -> List[Dict[str, str]]: +def get_gpu_info(gpu_lib: str | os.PathLike = None) -> List[Dict[str, str]]: """OS-agnostic function to get all GPUs connected to the host system. Args: diff --git a/pyproject.toml b/pyproject.toml index 28ffd3c..480c4e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,10 @@ dependencies = [ [tool.setuptools] packages = [ - "pyarchitecture" + "pyarchitecture", + "pyarchitecture.cpu", + "pyarchitecture.disks", + "pyarchitecture.gpu", ] [tool.setuptools.dynamic]