Skip to content

Commit

Permalink
feat: second version of package
Browse files Browse the repository at this point in the history
  • Loading branch information
A.Shpak committed Nov 14, 2024
1 parent 0517dc8 commit b28b4ae
Show file tree
Hide file tree
Showing 15 changed files with 381 additions and 576 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ jobs:
strategy:
matrix:
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
steps:
-
name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
-
uses: actions/checkout@v2
-
name: Install dependencies
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v2
- name: Install dependencies
run: |
python -m pip install poetry==1.1.7
poetry install
-
name: pytest
- name: pytest
run: poetry run pytest -vv
11 changes: 4 additions & 7 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
SOURCE_DIR := "winregistry"

tests: pytest
fmt: black isort

isort:
poetry run isort {{ SOURCE_DIR }} --diff
# poetry run isort test_curlify3.py --diff
poetry run isort winregistry.py

black:
poetry run isort {{ SOURCE_DIR }}
poetry run black winregistry.py
# poetry run isort test_curlify3.py

pytest:
poetry run pytest -vv

ruff:
poetry run ruff check --fix {{SOURCE_DIR}}
poetry run ruff check --fix winregistry.py

mypy:
poetry run mypy --pretty -p {{SOURCE_DIR}}
poetry run mypy --pretty winregistry.py
41 changes: 15 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![PyPI](https://img.shields.io/pypi/v/winregistry.svg)](https://pypi.python.org/pypi/winregistry)
[![PyPI](https://img.shields.io/pypi/dm/winregistry.svg)](https://pypi.python.org/pypi/winregistry)

Minimalist Python library aimed at working with Windows Registry.
Minimalist Python library aimed at working with Windows Registry

## Installation

Expand All @@ -14,31 +14,20 @@ pip install winregistry
## Usage

```py
from winregistry import WinRegistry

TEST_REG_PATH = r"HKLM\SOFTWARE\_REMOVE_ME_"

import winreg
from winregistry import registry_connect

if __name__ == "__main__":
with WinRegistry() as client:
client.create_key(TEST_REG_PATH)
client.write_entry(TEST_REG_PATH, "remove_me", "test")
test_entry = client.read_entry(TEST_REG_PATH, "remove_me")
assert test_entry.value == "test"
client.delete_entry(TEST_REG_PATH, "remove_me")
```

Usage with ``Robot Testing Framework`` Library
----------------------------------------------

```
*** Settings ***
Library winregistry.robot
*** Test Cases ***
Valid Login
${path} = Set Variable HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run
Write Registry Entry ${path} Notepad notepad.exe
${autorun} = Read Registry Key ${path}
Delete Registry Entry ${path} Notepad
with registry_connect(winreg.HKEY_LOCAL_MACHINE) as hklm:
hklm.create_subkey('SOFTWARE\_REMOVE_ME_')
with hklm.open_subkey('SOFTWARE\_REMOVE_ME_', access_mode=winreg.KEY_ALL_ACCESS) as subkey:
subkey.set_value("remove_me", "remove_me!", winreg.REG_SZ)
value = subkey.read_value("remove_me")
print(f'{value=}: {value.data}')
value.data = 'remove me again!'
print(f'{value=}: {value.data}')
print(f'{list(subkey.values)=}')
subkey.unset_value("remove_me")
print(f'{list(subkey.values)=}')
hklm.delete_subkey('SOFTWARE\_REMOVE_ME_')
```
171 changes: 4 additions & 167 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "winregistry"
version = "1.1.1"
version = "0.0.0"
description = "Library aimed at working with Windows registry"
authors = ["Aleksandr Shpak <[email protected]>"]
readme = "README.md"
Expand All @@ -20,7 +20,7 @@ python = ">=3.9"
mypy = "^1.13"
pytest = "^8.3"
black = "^24.10"
robotframework = "^7.1"
robotframework = ">=7.1"
isort = "^5.13"
ruff = "^0.7.3"

Expand Down
16 changes: 3 additions & 13 deletions tests/test_utils.py → test_winregistry.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
from winreg import HKEY_CURRENT_USER, KEY_READ

from winregistry import WinRegistry
from winregistry.utils import expand_short_root, get_access_key, parse_path
from _winregistry import WinRegistry
from _winregistry._utils import get_access_key, parse_key_name

TEST_REG_PATH = r"HKCU\SOFTWARE\_REMOVE_ME_"


def test_expand_short_root() -> None:
root = expand_short_root("HKU")
assert root == "HKEY_USERS", root


def test_expand_long_root() -> None:
root = expand_short_root("SOME_LONG_STRING")
assert root == "SOME_LONG_STRING", root


def test_get_access_key() -> None:
access_key = get_access_key(KEY_READ, True)
assert access_key


def test_parse_path() -> None:
root, path = parse_path(TEST_REG_PATH)
root, path = parse_key_name(TEST_REG_PATH)
assert root == HKEY_CURRENT_USER, root
assert path == TEST_REG_PATH.lstrip("HKCU\\")

Expand Down
Empty file removed tests/__init__.py
Empty file.
Loading

0 comments on commit b28b4ae

Please sign in to comment.