Skip to content

Commit

Permalink
fix compat with winregistry v2
Browse files Browse the repository at this point in the history
* feat: bump winregistry version
* fix winregistry version in setup.py file
* add alias to winregistry lib import

---------

Co-authored-by: A.Shpak <[email protected]>
  • Loading branch information
shpaker and A.Shpak authored Dec 14, 2024
1 parent 3d3de82 commit 4aafc46
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
Expand Down
20 changes: 11 additions & 9 deletions machineid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
from sys import platform

try:
from winregistry import WinRegistry
import winregistry as winregistry_lib
except ImportError:
WinRegistry = None
winregistry_lib = None

class MachineIdNotFound(RuntimeError):
"""
Expand Down Expand Up @@ -64,14 +64,16 @@ def __read__(path: str) -> str:
except IOError:
return None

def __reg__(registry: str, key: str) -> str:
def __reg__(key_name: str, value_name: str) -> str:
if winregistry_lib is None:
return None
try:
with WinRegistry() as reg:
return reg.read_entry(registry, key) \
.value \
.strip()
with winregistry_lib.open_value(key_name, value_name) as reg:
if reg.data and isinstance(reg.data, str):
return reg.data.strip()
except OSError:
return None
pass
return None

def id(winregistry: bool = True) -> str:
"""
Expand All @@ -82,7 +84,7 @@ def id(winregistry: bool = True) -> str:
if platform == 'darwin':
id = __exec__("ioreg -d2 -c IOPlatformExpertDevice | awk -F\\\" '/IOPlatformUUID/{print $(NF-1)}'")
elif platform in ('win32', 'cygwin', 'msys'):
if winregistry and WinRegistry is not None:
if winregistry:
id = __reg__(r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography', 'MachineGuid')
else:
id = __exec__("powershell.exe -ExecutionPolicy bypass -command (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
author=__author__,
author_email='[email protected]',
license='MIT',
install_requires=['winregistry; sys_platform == "win32"'],
install_requires=['winregistry>=2.0.1,<3.0.0; sys_platform == "win32"'],
packages=['machineid'],
package_data={
'machineid': ['py.typed'],
Expand Down

0 comments on commit 4aafc46

Please sign in to comment.