use importlib.machinery when available

avoids deprecation warning on startup, and allows tests to pass with
PYTHONWARNINGS=d

closes #4051

candidate for backport to 1.2