Skip to content

Commit 4dd1ea0

Browse files
committed
Fix Python 3.12+ warnings and add local pytest target
1 parent 2ca79c8 commit 4dd1ea0

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
---
99

10+
## [1.0.2] - 2026-04-01
11+
12+
### Changed
13+
- add a `make pytest` target that installs the package in editable mode before running the test suite
14+
15+
### Fixed
16+
- remove `return` statements from `finally` blocks in encryption helpers to avoid newer Python `SyntaxWarning`s
17+
- harden optional `cryptography` imports so missing crypto dependencies do not break exception handling paths
18+
19+
---
20+
1021
## [1.0.1] - 2026-02-08
1122

1223
### Fixed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ test:
4141
$(ENVSTACK_CMD) -- ls -al
4242
${ENVSTACK_CMD} -- which python
4343

44+
# Run the pytest suite from an editable install, matching CI behavior
45+
pytest:
46+
python -m pip install -e .
47+
pytest tests -q
48+
4449
# Install dryrun target to simulate installation
4550
dryrun:
4651
$(ENVSTACK_CMD) -- dist --dryrun
@@ -51,4 +56,4 @@ install: build
5156
dist --force --yes
5257

5358
# Phony targets
54-
.PHONY: build dryrun install clean
59+
.PHONY: build dryrun install clean test pytest

lib/envstack/encrypt.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@
4444
# cryptography and _rust dependency may not be available everywhere
4545
# ImportError: DLL load failed while importing _rust: Module not found.
4646
Fernet = None
47+
InvalidToken = type("InvalidToken", (Exception,), {})
48+
InvalidTag = type("InvalidTag", (Exception,), {})
49+
padding = None
50+
Cipher = None
51+
algorithms = None
52+
modes = None
4753
try:
48-
import cryptography.exceptions
4954
from cryptography.fernet import Fernet, InvalidToken
55+
from cryptography.exceptions import InvalidTag
5056
from cryptography.hazmat.primitives import padding
5157
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
5258
except ImportError as err:
@@ -217,7 +223,7 @@ def encrypt(self, data: str):
217223
results = compact_store(encrypted_data)
218224
except binascii.Error as e:
219225
log.error("invalid base64 encoding: %s", e)
220-
except cryptography.exceptions.InvalidTag:
226+
except InvalidTag:
221227
log.error("invalid encryption key")
222228
except ValueError as e:
223229
log.error("invalid value: %s", e)
@@ -237,7 +243,7 @@ def decrypt(self, data: str):
237243
return decrypted.decode()
238244
except binascii.Error as e:
239245
log.debug("invalid base64 encoding: %s", e)
240-
except cryptography.exceptions.InvalidTag:
246+
except InvalidTag:
241247
log.debug("invalid encryption key")
242248
except ValueError as e:
243249
log.debug("invalid value: %s", e)

0 commit comments

Comments
 (0)