Repository navigation
fix(vendor): restore sys.path when an IPX crawler import fails - #2601
Conversation
pcapkit.vendor.ipx and its packet and socket crawlers pop sys.path[0] around their imports: run as a script, a crawler has the package directory first on sys.path, and the sibling socket.py would shadow the socket module requests imports. The entry went back only on success, so a failed import lost it, and pkgutil.walk_packages, retrying on every walk, drained sys.path until pop raised IndexError without requests installed. Restore the entry in a finally in all three modules. The new tests/vendor/test_vendor_ipx_sys_path_2589_unit.py hides requests and checks sys.path after a failed package import and a failed script-mode run of each crawler; it fails without the fix.
|
GOOD TO GO at |
|
The red "Python pypy3.11" leg is #2600's PyPy shard stall, not this change, which touches only |
|
Coverage: 94.03% (unit tier, Python 3.15,
Per-file detail: the |
…1.6.0 (#2449) - Added: DCCP, its checksum over the IP pseudo-header, register_dccp and register_dccp_option, and the pcapkit.const.dccp registries (#2593). - Folded into unreleased entries: LinuxSLL's stop on its ARPHRD path (#2587) and ARPHRD's __proto_dest__ (#2598), SSLv2 records chained in a segment (#2585), the checksum's move to pcapkit.corekit.checksum.internet (#2586), and IGMPv2's and IGMPv3's versioned name (#2590). - Breaking: InARP moves to pcapkit.protocols.link.inarp with no re-export, joining the DRARP entry (#2596). - Changed: the conventions' new rulings (#2599), the milestone workflow's next-open-milestone lookup (#2591), the PyPy protocols shards (#2604). Fixed: a handled next-layer refusal is quiet under beholder (#2597); the IPX crawlers restore sys.path (#2601). - CHANGELOG.md regenerated; util/changelog_md.py --check passes.
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
pcapkit.vendor.ipx,ipx.packetandipx.socketeach popsys.path[0]before their imports, so that the crawler's ownsocket.pydoes not shadow the standard library's when a crawler runs as a script. The pop is still needed: without it,import requestsloadsipx/socket.pyassocket. But the entry was put back only on success. Each failed import, for example one whererequestsis missing, dropped one more entry, untiltest_conventions_doc_claimshitIndexError: pop from empty list. The entry is now restored in afinally, sosys.pathcomes back exactly on success, on ImportError and on any other exception.test_vendor_ipx_sys_path_2589_unithidesrequestsand checks thatsys.pathis unchanged after a failed package import and after a failed script-mode run of each crawler. It fails without the fix. It isolatespcapkit.vendoritself, so it leaves no half-imported package behind.Closes #2589