Skip to content

ndifftest.py fails to import on Python 3.12+ (imp module removed) #3468

Closed

Description

@gargamel778

ndifftest.py fails to import on Python 3.12+ (imp module removed)

Component: Ndiff (test harness only)
Affects: Python 3.12 and newer. Not macOS-specific.
Tested at: master b97fabd935362f85ad0575632e6d887f4d778b59

Summary

ndiff/ndifftest.py:15 does import imp. The imp module was deprecated in
Python 3.4 and removed in 3.12, so the Ndiff test suite dies at import on any
interpreter from 3.12 onward. The tests themselves are fine — this is purely the
harness's module-loading shim.

Reproduction

cd ndiff && ./ndifftest.py
Interpreter Result
3.9.6 exit 0 — Ran 57 tests ... OK
3.11.15 exit 0 — Ran 57 tests ... OK
3.12.11 exit 1 — ModuleNotFoundError: No module named 'imp'
3.14.7 exit 1 — ModuleNotFoundError: No module named 'imp'

Through the build system, with Ndiff configured in:

$ make check-ndiff
make: *** [check-ndiff] Error 1

Fix

imp.load_source() has a documented replacement:

import importlib.util
_spec = importlib.util.spec_from_file_location("ndiff", "ndiff.py")
ndiff = importlib.util.module_from_spec(_spec)
sys.modules["ndiff"] = ndiff          # preserves imp.load_source's side effect
_spec.loader.exec_module(ndiff)

After the change, all four interpreters above report Ran 57 tests ... OK, and
make check-ndiff exits 0.

Scope, stated honestly

  • This restores the 57 tests that already passed on ≤3.11. It adds no coverage.
  • ndiff.py itself is unaffected — it imports no removed modules and runs
    correctly on 3.12+.
  • This does not break GitHub Actions CI: .github/workflows/build.yml does
    not run make check on any of its legs.
  • It is masked whenever configure's chosen python3 lacks setuptools/build,
    because Ndiff is then skipped entirely (WARNING: Not building Ndiff because Python with setuptools was not found) and check-ndiff is omitted from the
    generated check: target.

Prior art

This looks like the remaining half of #2649, which migrated Ndiff to
setuptools and was closed as completed. The CHANGELOG entry for it is explicitly
packaging-only:

o [Zenmap][Ndiff][GH#2649] Zenmap and Ndiff now use setuptools, not distutils
for packaging.

The Python 3 port of Ndiff itself (12d41ec2cd, "Closes #1807") also walked past
this line and left it.

Two distributions already carry exactly this patch downstream:

  • GNU Guix — "gnu: nmap: Fix tests under python@3.12." (2026-02-07)
    substitutes import imp for import importlib.util and swaps in
    spec_from_file_location / module_from_spec / exec_module.
  • BLFS — sed -e '/import imp/d' -e 's/^ndiff = .*$/import ndiff/' -i ndiff/ndifftest.py

Two unrelated packagers patching the same two lines suggests it is worth fixing
upstream rather than downstream repeatedly.

Searched issues and PRs (open, closed and merged) for ndifftest, imp module,
python 3.12, importlib, load_source, ModuleNotFoundError imp; and the
nmap-dev archive. No existing report found.

Tested on macOS 26 (arm64) only.

Activity

  1. added a commit that references this issue on Sep 19, 2026
    a9171ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions