Skip to content

Commit 2663a48

Browse files
Fix CodeRabbit critical issues in examples
- Change absolute imports to relative imports in all __init__.py files - Fix security issue: log encryption key fingerprints instead of actual keys - Add pytest asyncio configuration (asyncio_mode = auto) to all examples - Constrain pydantic to <3.0.0 in all examples Co-authored-by: William Easton <strawgate@users.noreply.github.com>
1 parent 74331ba commit 2663a48

File tree

10 files changed

+24
-11
lines changed

10 files changed

+24
-11
lines changed

examples/chat_app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Chat app example for py-key-value."""
22

3-
from chat_app import ChatApp, ChatMessage
3+
from .chat_app import ChatApp, ChatMessage
44

55
__all__ = ["ChatApp", "ChatMessage"]

examples/chat_app/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Simple async chat application using py-key-value"
55
requires-python = ">=3.10"
66
dependencies = [
77
"py-key-value-aio>=0.2.8",
8-
"pydantic>=2.0.0",
8+
"pydantic>=2.0.0,<3.0.0",
99
]
1010

1111
[project.optional-dependencies]
@@ -14,6 +14,9 @@ dev = [
1414
"pytest-asyncio>=1.2.0",
1515
]
1616

17+
[tool.pytest.ini_options]
18+
asyncio_mode = "auto"
19+
1720
[build-system]
1821
requires = ["hatchling"]
1922
build-backend = "hatchling.build"

examples/chat_app/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
py-key-value-aio>=0.2.8
2-
pydantic>=2.0.0
2+
pydantic>=2.0.0,<3.0.0

examples/trading_data/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Trading data cache example for py-key-value."""
22

3-
from trading_app import PriceData, TradingDataCache
3+
from .trading_app import PriceData, TradingDataCache
44

55
__all__ = ["PriceData", "TradingDataCache"]

examples/trading_data/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Trading data caching using py-key-value with compression and mult
55
requires-python = ">=3.10"
66
dependencies = [
77
"py-key-value-aio>=0.2.8",
8-
"pydantic>=2.0.0",
8+
"pydantic>=2.0.0,<3.0.0",
99
]
1010

1111
[project.optional-dependencies]
@@ -14,6 +14,9 @@ dev = [
1414
"pytest-asyncio>=1.2.0",
1515
]
1616

17+
[tool.pytest.ini_options]
18+
asyncio_mode = "auto"
19+
1720
[build-system]
1821
requires = ["hatchling"]
1922
build-backend = "hatchling.build"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
py-key-value-aio>=0.2.8
2-
pydantic>=2.0.0
2+
pydantic>=2.0.0,<3.0.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Web scraper cache example for py-key-value."""
22

3-
from scraper import ScrapedPage, WebScraperCache
3+
from .scraper import ScrapedPage, WebScraperCache
44

55
__all__ = ["ScrapedPage", "WebScraperCache"]

examples/web_scraper_cache/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Web scraper cache using py-key-value with encryption and size lim
55
requires-python = ">=3.10"
66
dependencies = [
77
"py-key-value-aio>=0.2.8",
8-
"pydantic>=2.0.0",
8+
"pydantic>=2.0.0,<3.0.0",
99
"cryptography>=41.0.0",
1010
]
1111

@@ -15,6 +15,9 @@ dev = [
1515
"pytest-asyncio>=1.2.0",
1616
]
1717

18+
[tool.pytest.ini_options]
19+
asyncio_mode = "auto"
20+
1821
[build-system]
1922
requires = ["hatchling"]
2023
build-backend = "hatchling.build"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
py-key-value-aio>=0.2.8
2-
pydantic>=2.0.0
2+
pydantic>=2.0.0,<3.0.0
33
cryptography>=41.0.0

examples/web_scraper_cache/scraper.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def __init__(self, cache_dir: str = ".scraper_cache", encryption_key: bytes | No
5454
# Generate or use provided encryption key
5555
if encryption_key is None:
5656
encryption_key = Fernet.generate_key()
57-
logger.warning(f"Generated new encryption key: {encryption_key.decode()}")
57+
# Generate a safe fingerprint for identification (never log the actual key!)
58+
key_fingerprint = hashlib.sha256(encryption_key).hexdigest()[:16]
59+
logger.warning(f"Generated new encryption key (fingerprint: {key_fingerprint})")
5860
logger.warning("Store this key securely! Data encrypted with different keys cannot be decrypted.")
5961

6062
self.encryption_key = encryption_key
@@ -199,7 +201,9 @@ async def main():
199201
"""Demonstrate the web scraper cache."""
200202
# Generate a key for this demo (in production, load from secure storage)
201203
encryption_key = Fernet.generate_key()
202-
print(f"Using encryption key: {encryption_key.decode()}\n")
204+
# Only show fingerprint, never the actual key
205+
key_fingerprint = hashlib.sha256(encryption_key).hexdigest()[:16]
206+
print(f"Using encryption key (fingerprint: {key_fingerprint})\n")
203207

204208
cache = WebScraperCache(cache_dir=".demo_scraper_cache", encryption_key=encryption_key)
205209

0 commit comments

Comments
 (0)