Backport PR #4928: user importlib.machinery when available