Skip to content

fix(vendor): restore sys.path when an IPX crawler import fails - #2601

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2589-ipx-sys-path
Nov 2, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2589-ipx-sys-path

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

pcapkit.vendor.ipx, ipx.packet and ipx.socket each pop sys.path[0] before their imports, so that the crawler's own socket.py does not shadow the standard library's when a crawler runs as a script. The pop is still needed: without it, import requests loads ipx/socket.py as socket. But the entry was put back only on success. Each failed import, for example one where requests is missing, dropped one more entry, until test_conventions_doc_claims hit IndexError: pop from empty list. The entry is now restored in a finally, so sys.path comes back exactly on success, on ImportError and on any other exception.

test_vendor_ipx_sys_path_2589_unit hides requests and checks that sys.path is unchanged after a failed package import and after a failed script-mode run of each crawler. It fails without the fix. It isolates pcapkit.vendor itself, so it leaves no half-imported package behind.

Closes #2589

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.
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 1, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 5e0aa5872 (Sonnet review plus a fold I checked myself). The restore happens in every case: success, ImportError, RuntimeError and KeyboardInterrupt. A list subclass that logs pop and insert confirms the order and that nothing is inserted twice. The pop is still needed, since without it urllib3's import socket loads the crawler's socket.py. The test fails 3 of 3 without the fix, isolates pcapkit.vendor, and leaves no state behind under unittest or pytest. Regenerating changes nothing.

@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 1, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

The red "Python pypy3.11" leg is #2600's PyPy shard stall, not this change, which touches only pcapkit/vendor/ipx. test_transport_edge_roundtrip_unit's tcp/make/default and tcp/make/every-flag hit the 30 s TimeoutError at the tail of the tests/protocols shard, the same signature as on main and #2593. #2604 is the fix. Re-run this leg once #2604 merges. The verdict stands.

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Coverage: 94.03% (unit tier, Python 3.15, 5e0aa5872, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 20093 144 2712 125 98.78%
pcapkit/corekit 2605 74 818 37 96.52%
pcapkit/dumpkit 281 3 100 3 98.43%
pcapkit/foundation 3360 27 1186 32 98.70%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 20346 220 5370 204 98.34%
pcapkit/toolkit 961 28 342 10 96.32%
pcapkit/utilities 506 7 144 5 98.15%
pcapkit/vendor 5012 2222 1148 182 52.34%

Per-file detail: the coverage-html artifact of this run.

@github-actions github-actions Bot added this to the PyPCAPKit v1.6 milestone Nov 2, 2026
@JarryShaw
JarryShaw merged commit 19e1eca into main Nov 2, 2026
97 of 99 checks passed
@JarryShaw
JarryShaw deleted the fix/2589-ipx-sys-path branch November 2, 2026 02:22
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 2, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 2, 2026
JarryShaw added a commit that referenced this pull request Nov 2, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(vendor): pcapkit.vendor.ipx pops sys.path[0] and does not restore it when an import fails

1 participant