pyhw 0.4.1__py3-none-any.whl → 0.6.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
pyhw/backend/gpu/macos.py CHANGED
@@ -2,6 +2,8 @@ from .gpuInfo import GPUInfo
2
2
  from ...pyhwUtil import getArch
3
3
  import json
4
4
  import subprocess
5
+ import ctypes
6
+ from pathlib import Path
5
7
 
6
8
 
7
9
  class GPUDetectMacOS:
@@ -32,24 +34,49 @@ class GPUDetectMacOS:
32
34
  self.__gpuInfo.gpus.append(f'{gpu.get("sppci_model")} ({gpu.get("sppci_cores")} cores) [SOC Integrated]')
33
35
 
34
36
  def __getGPUIntel(self):
35
- gpus = list()
36
- try:
37
- gpu_info_dict = json.loads(subprocess.check_output(["system_profiler", "SPDisplaysDataType", "-json"]))
38
- if 'SPDisplaysDataType' in gpu_info_dict:
39
- gpus = gpu_info_dict['SPDisplaysDataType']
40
- self.__gpuInfo.number = len(gpus)
41
- else:
42
- pass
43
- except Exception:
44
- return
37
+ if self.__getGPUIOKit():
38
+ pass
39
+ else:
40
+ gpus = list()
41
+ try:
42
+ gpu_info_dict = json.loads(subprocess.check_output(["system_profiler", "SPDisplaysDataType", "-json"]))
43
+ if 'SPDisplaysDataType' in gpu_info_dict:
44
+ gpus = gpu_info_dict['SPDisplaysDataType']
45
+ self.__gpuInfo.number = len(gpus)
46
+ else:
47
+ pass
48
+ except Exception:
49
+ return
45
50
 
46
- for gpu in gpus:
47
- if self.__handleVendor(gpu.get("spdisplays_vendor")) == "Intel": # Integrated GPU
48
- self.__gpuInfo.gpus.append(f'{gpu.get("sppci_model")} [CPU Integrated]')
49
- elif self.__handleVendor(gpu.get("spdisplays_vendor")) == "AMD": # dGPU
50
- self.__gpuInfo.gpus.append(f'{gpu.get("sppci_model")} {gpu.get("spdisplays_vram")} [Discrete]')
51
- elif self.__handleVendor(gpu.get("spdisplays_vendor")) == "Nvidia": # Since current macOS does not support NVIDIA GPUs, this condition is not applicable
52
- pass
51
+ for gpu in gpus:
52
+ if self.__handleVendor(gpu.get("spdisplays_vendor")) == "Intel": # Integrated GPU
53
+ self.__gpuInfo.gpus.append(f'{gpu.get("sppci_model")} [CPU Integrated]')
54
+ elif self.__handleVendor(gpu.get("spdisplays_vendor")) == "AMD": # dGPU
55
+ self.__gpuInfo.gpus.append(f'{gpu.get("sppci_model")} {gpu.get("spdisplays_vram")} [Discrete]')
56
+ elif self.__handleVendor(gpu.get("spdisplays_vendor")) == "Nvidia": # Since current macOS does not support NVIDIA GPUs, this condition is not applicable
57
+ pass
58
+
59
+ def __getGPUIOKit(self):
60
+ try:
61
+ package_root = Path(__file__).resolve().parent.parent
62
+ lib = ctypes.CDLL(f"{package_root}/library/lib/iokitGPULib.dylib")
63
+ lib.getGPUInfo.restype = ctypes.c_char_p
64
+ gpu_info = lib.getGPUInfo()
65
+ gpus = gpu_info.decode('utf-8').split("; ")
66
+ self.__gpuInfo.number = len(gpus)
67
+ for gpu in gpus:
68
+ info_list = gpu.split(", ")
69
+ model = info_list[0]
70
+ vendor_id = info_list[1]
71
+ vram = int(info_list[2]) / 1024
72
+ if self.__handleVendorID(vendor_id) == "Intel": # Integrated GPU
73
+ self.__gpuInfo.gpus.append(f'{model} [CPU Integrated]')
74
+ elif self.__handleVendorID(vendor_id) == "AMD": # dGPU
75
+ self.__gpuInfo.gpus.append(f'{model} {vram} GB [Discrete]')
76
+ return True
77
+ except Exception as e:
78
+ print(f"An error occurred while getting GPU info using IOKit: {e}")
79
+ return False
53
80
 
54
81
  @staticmethod
55
82
  def __handleVendor(vendor):
@@ -61,3 +88,13 @@ class GPUDetectMacOS:
61
88
  return "AMD"
62
89
  else:
63
90
  return vendor
91
+
92
+ @staticmethod
93
+ def __handleVendorID(vendor_id):
94
+ if vendor_id == "0x8086":
95
+ return "Intel"
96
+ elif vendor_id == "0x1002":
97
+ return "AMD"
98
+ else:
99
+ return vendor_id
100
+
pyhw/backend/nic/macos.py CHANGED
@@ -7,12 +7,21 @@ class NICDetectMacOS:
7
7
  self.__nicInfo = NICInfo()
8
8
 
9
9
  def getNICInfo(self):
10
- self.__nicInfo.nics.append("en0")
11
- self.__nicInfo.number = 1
10
+ self.__getNICInfo()
12
11
  return self.__nicInfo
13
12
 
14
13
  def __getNICInfo(self):
15
14
  # Placeholder for a more advanced method.
16
- interfaces = subprocess.run(["bash", "-c", "route get default | grep interface"], capture_output=True, text=True).stdout.strip()
15
+ try:
16
+ interface = subprocess.run(["bash", "-c", "route get default | grep interface"], capture_output=True, text=True).stdout.strip().split(":")[1]
17
+ if_ip = subprocess.run(["bash", "-c", f"ipconfig getifaddr {interface}"], capture_output=True, text=True).stdout.strip()
18
+ self.__nicInfo.nics.append(f"{interface} @ {if_ip}")
19
+ self.__nicInfo.number += 1
20
+ except:
21
+ self.__handleError()
22
+
23
+ def __handleError(self):
24
+ self.__nicInfo.nics.append("en0")
25
+ self.__nicInfo.number = 1
17
26
 
18
27
 
pyhw/backend/npu/macos.py CHANGED
@@ -18,7 +18,7 @@ class NPUDetectMacOS:
18
18
 
19
19
  def __getNPUAppleSilicon(self):
20
20
  # Place holder
21
- self.__npuInfo.npus.append("Neural Engine [SOC Integrated]")
21
+ self.__npuInfo.npus.append("Apple Neural Engine [SOC Integrated]")
22
22
  self.__npuInfo.number += 1
23
23
 
24
24
  def __getNPUIntel(self):
@@ -0,0 +1,12 @@
1
+ import ctypes
2
+
3
+ # Load the dynamic library
4
+ lib = ctypes.CDLL('./iokitGPULib.dylib')
5
+
6
+ # Define the function return type as c_char_p (pointer to C char)
7
+ lib.getGPUInfo.restype = ctypes.c_char_p
8
+
9
+ # Call the function and get the result
10
+ gpu_info = lib.getGPUInfo()
11
+ print("Detected GPUs:", gpu_info)
12
+
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyhw
3
- Version: 0.4.1
3
+ Version: 0.6.0
4
4
  Summary: PyHw, a neofetch-like command line tool for fetching system information but written mostly in python.
5
5
  Author-email: Xiao Ran <xiaoran.007@icloud.com>
6
6
  License: BSD-3-Clause
@@ -19,7 +19,8 @@ Requires-Dist: pypci-ng>=0.0.3
19
19
  [![Downloads](https://static.pepy.tech/badge/pyhw)](https://pepy.tech/project/pyhw)
20
20
  ![PyPI - Version](https://img.shields.io/pypi/v/pyhw?label=version)
21
21
 
22
- ![Static Badge](https://img.shields.io/badge/macOS-brightgreen)
22
+ ![Static Badge](https://img.shields.io/badge/macOS-11%2B-green
23
+ )
23
24
  ![Static Badge](https://img.shields.io/badge/Linux-blue)
24
25
 
25
26
 
@@ -42,6 +43,8 @@ pip install pyhw
42
43
  ```
43
44
  To upgrade pyhw:
44
45
  ```shell
46
+ pip install pyhw -U
47
+ # or
45
48
  pip install pyhw --upgrade
46
49
  ```
47
50
  You can then use this tool directly from the command line with the following command, just like neofetch.
@@ -74,7 +77,7 @@ This is due to the fact that system python is not supposed to be managed by pip.
74
77
 
75
78
  ## Supported (Tested) OS
76
79
  * macOS arm64, x86_64
77
- * debian-based distro x86_64
80
+ * debian-based distro arm64, x86_64
78
81
  * RaspberryPi OS arm64
79
82
 
80
83
 
@@ -90,8 +93,7 @@ clone the project, and run:
90
93
  ```shell
91
94
  python -m build
92
95
  ```
93
- or you can use the old setup.py style command:
96
+ After the build process, the source package and the binary whl package can be found in the dist folder. Then you can use the following command to install the new package.
94
97
  ```shell
95
- python setup.py sdist bdist_wheel
98
+ pip install dist/*.whl --force-reinstall
96
99
  ```
97
- After the build process, the source package and the binary whl package can be found in the dist folder.
@@ -12,7 +12,7 @@ pyhw/backend/gpu/__init__.py,sha256=EpMjPvUaXt0LTNMvGmB8WgXbUB9keCxuOhu8NT3Re6o,
12
12
  pyhw/backend/gpu/gpuBase.py,sha256=Ge0DX2P8_EB7ovM7glmPUnVsPJL3OUHV2t_1T5mimR0,409
13
13
  pyhw/backend/gpu/gpuInfo.py,sha256=d_z_z5DiZAg85wP0VOBQEU0QHdaK3qFqA2Tp9Eq8-Zs,133
14
14
  pyhw/backend/gpu/linux.py,sha256=E-evoL-spQbHB8JvbZXSq5ypc2SeePVUPnhEQrSPQpg,1619
15
- pyhw/backend/gpu/macos.py,sha256=kkTq9_ZJwTQ0Jwep4oYq41STDTplFz83jKRYbvlbMhg,2337
15
+ pyhw/backend/gpu/macos.py,sha256=J6BjGGzsMjwqtw6YbRaYK903s2CC7CefJKcVwyUFNV4,3786
16
16
  pyhw/backend/host/__init__.py,sha256=Efaj7-Oya7H8HdpZHQCLrwn-mcfPb-d6yfh4dzsE_7I,58
17
17
  pyhw/backend/host/hostBase.py,sha256=POyDW3f5JSWtEKyCfrVSBEddSwoywe_OBgUExCEuje8,563
18
18
  pyhw/backend/host/hostInfo.py,sha256=Xvz0LugPiCSWMkcDsp4p2rrojYFZauL6Q-gCZ6NLz5k,184
@@ -32,12 +32,12 @@ pyhw/backend/memory/memoryInfo.py,sha256=OQF165uEyuapAsi7cKacQYDRnKdrQHeldfyFwzS
32
32
  pyhw/backend/metal/t.py,sha256=52yv-JoXNfaIOfcxEEidIg0MoyFtzWvTRm550kQKPZA,391
33
33
  pyhw/backend/nic/__init__.py,sha256=eP4eOYIvMF3LcTf954hJa6TnB8R4Qahss2g-UcgypKY,57
34
34
  pyhw/backend/nic/linux.py,sha256=2IDhesM77qLt7QK8HzYiMeLyuKWOVVrrDtkLHs7R6lU,1321
35
- pyhw/backend/nic/macos.py,sha256=Gi-XAf2ZvJcWbwJvTlkpdyKaRDSXXiI2WhISeASxbvc,481
35
+ pyhw/backend/nic/macos.py,sha256=63gZjSmUGwGqfs41IWrEXmSz9O8eQy4G5oql3JLZmoo,855
36
36
  pyhw/backend/nic/nicBase.py,sha256=hmVbiPOrDFClQrOBgAUgE8GVkC5nVH280jnlb65CDV4,539
37
37
  pyhw/backend/nic/nicInfo.py,sha256=wuBuL-aIzD441IUDPGz5e0xctcZ-opdpgqkVxgbvZLg,133
38
38
  pyhw/backend/npu/__init__.py,sha256=PgLKbwpgT5vw9xpa294Zxb94McyxNXW46_vMbT2Iqyc,58
39
39
  pyhw/backend/npu/linux.py,sha256=eQLozhGOh3iHoFXdRYp_Fn9OsrmJ7tsyxcOPUvopOSw,1286
40
- pyhw/backend/npu/macos.py,sha256=-eoZXMcwiYUeO_ba9lLqWyhV8jmBYkgMi7iMlmVsbeY,1031
40
+ pyhw/backend/npu/macos.py,sha256=mNnfvjjPQNlA-mViuhmfeb__uI1be93ZSZvv7PVD52s,1037
41
41
  pyhw/backend/npu/npuBase.py,sha256=6lPYmsOGHO-lT-GqaJ2hNXRV_FLYqguuZ_7L6JJCG-g,411
42
42
  pyhw/backend/npu/npuInfo.py,sha256=82dK6XvW_XKw4O5-RfR4-qQRR7Plh8qqJLj0YDzISmU,135
43
43
  pyhw/backend/os/__init__.py,sha256=rPHQYdQK3qU6ZwwodqVoEWeqBnKffXlJyi4k3-8ViPY,53
@@ -77,14 +77,16 @@ pyhw/frontend/logo/ascii/macOS.pyhw,sha256=HBGROtBb7wrNtRqAQ9ND7zxK0l17BRsmpgc2d
77
77
  pyhw/frontend/logo/ascii/raspbian.pyhw,sha256=jEl6WMKF-FGx359ipQ1kzweUJS-NuauYQCFaYime4PQ,159
78
78
  pyhw/frontend/logo/ascii/ubuntu.pyhw,sha256=l-Q0PfutxXYMwTojqeiM88063x4V0RBkZUHmi6YdsNc,833
79
79
  pyhw/frontend/logo/ascii/ubuntu_small.pyhw,sha256=Xf8LSZdZUu9aEG3efhb1FUlUEuJ-3UztcIOJISpKhPw,229
80
+ pyhw/library/iokitGPULib/te.py,sha256=UbRUT82ckEFWP_r1-52wGFhaVO9bGSsON_NTBeTawCw,294
81
+ pyhw/library/lib/iokitGPULib.dylib,sha256=DcJ0GZY79gTFckLFYtZgeKn1T0NFvdO_k_ccCa7od5Y,154808
80
82
  pyhw/pyhwException/__init__.py,sha256=8JsFvtF13g0Y5t4z9fRndDXtfCzuBM59jDf6PhWSFSk,220
81
83
  pyhw/pyhwException/pyhwException.py,sha256=wxuzFQa9g7XB1q9TUKO_55lw7wMEJMpzG8w1GVTFVa0,197
82
84
  pyhw/pyhwUtil/__init__.py,sha256=PzeP9fXsIhvr3sUpJ4DxW9_H25DEIasBFfXd_NztfR4,226
83
85
  pyhw/pyhwUtil/pyhwUtil.py,sha256=CKXJrt6KGhZCV1J7MjsQ21c_jPmC1I3wZBPCKJfdqbM,2478
84
86
  pyhw/pyhwUtil/sysctlUtil.py,sha256=S-rUvqi7ZrMyMouIhxlyHEQ4agM7sCT1Y7uzs3Hu5-o,841
85
- pyhw-0.4.1.dist-info/LICENSE,sha256=hJs6RBqSVCexbTsalkMLNFI5t06kekQEsSVaOt_-yLs,1497
86
- pyhw-0.4.1.dist-info/METADATA,sha256=unr5Vf2YvG3dQfGma2Ahm1BzNwC5lGyJdLNbvdNCFng,4136
87
- pyhw-0.4.1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
88
- pyhw-0.4.1.dist-info/entry_points.txt,sha256=q-AB8im_QahpmNrmy4aPTJRGi0LlbNlnI3kF7s6pKss,44
89
- pyhw-0.4.1.dist-info/top_level.txt,sha256=7Inxvxt1TngEricKZEex9_WJZS3DbKYFUXDz4v5WHYU,5
90
- pyhw-0.4.1.dist-info/RECORD,,
87
+ pyhw-0.6.0.dist-info/LICENSE,sha256=hJs6RBqSVCexbTsalkMLNFI5t06kekQEsSVaOt_-yLs,1497
88
+ pyhw-0.6.0.dist-info/METADATA,sha256=tc8zhFjdGBZG5sWdem_ABeGpEqe35P6cq2dSDDcXofo,4196
89
+ pyhw-0.6.0.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
90
+ pyhw-0.6.0.dist-info/entry_points.txt,sha256=q-AB8im_QahpmNrmy4aPTJRGi0LlbNlnI3kF7s6pKss,44
91
+ pyhw-0.6.0.dist-info/top_level.txt,sha256=7Inxvxt1TngEricKZEex9_WJZS3DbKYFUXDz4v5WHYU,5
92
+ pyhw-0.6.0.dist-info/RECORD,,
File without changes
File without changes