Skip to content

Commit

Permalink
Release v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Jan 1, 2025
1 parent af79f1d commit fcf6329
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 50 deletions.
43 changes: 8 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -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]

Expand All @@ -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

Expand Down
29 changes: 16 additions & 13 deletions pyarchitecture/__init__.py
Original file line number Diff line number Diff line change
@@ -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]:
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyarchitecture/gpu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ dependencies = [

[tool.setuptools]
packages = [
"pyarchitecture"
"pyarchitecture",
"pyarchitecture.cpu",
"pyarchitecture.disks",
"pyarchitecture.gpu",
]

[tool.setuptools.dynamic]
Expand Down

0 comments on commit fcf6329

Please sign in to comment.