Summary
bip-0327/reference.py and bip-0327/gen_vectors_helper.py both locate the test-vector JSON files via os.path.join(sys.path[0], 'vectors', '<file>.json'). As Sebastian Falbesoner noted in 4e18ee6 ("BIP-374: avoid using sys.path[0] to find current working directory"), this pattern is incompatible with any future sys.path.insert(0, ...) extension — for example, the sys.path.insert(0, str(Path(__file__).parent / "secp256k1lab/src")) shim that bip-0352 and bip-0374 use to locate their vendored secp256k1lab copies. Should bip-0327 follow the same vendoring pattern, every test-vector load would silently miss its file.
This PR switches both files to the Path(__file__).parent / 'vectors' / '...' pattern so the path is always resolved relative to the script itself, matching the BIP-374 precedent. import os and import sys are removed from reference.py (no remaining uses); gen_vectors_helper.py gets an explicit from pathlib import Path since it can no longer inherit those names through from reference import *.
Diff
| Old call (×10 across 2 files) | New call |
|---|---|
os.path.join(sys.path[0], 'vectors', 'X.json') |
Path(__file__).parent / 'vectors' / 'X.json' |
reference.py: 8 call sites (lines 499, 508, 532, 559, 577, 660, 717, 764). gen_vectors_helper.py: 2 call sites (lines 21, 49).
Imports adjusted to match.
Verification
$ python3 bip-0327/reference.py
$ echo $?
0
$ python3 bip-0327/gen_vectors_helper.py > /dev/null
$ echo $?
0
Both scripts continue to exit 0 with all test vectors loading.
(Note: bash bip-0327/tests.sh exits non-zero on master too — current local mypy versions flag four pre-existing bytearray/bytes mismatches at reference.py:354,355,671,672 that are unrelated to this PR. CI is presumably pinned to an older mypy; the runtime tests themselves pass on both branches.)
Notes
- Direct follow-up to 4e18ee6 ("BIP-374: avoid using sys.path[0]…"). Same shape, same justification, applied to the next reference implementation in the same family.
- No behavior change beyond path-resolution robustness.