Yasuhito FUTATSUKI wrote on Fri, Jan 03, 2020 at 05:34:48 +0900:
> +++ build/run_tests.py (working copy)
> @@ -64,6 +64,11 @@
> +if sys.version_info < (3, 5):
> + import imp
> +else:
> + import importlib.util
Add a comment here explaining the reason for this? E.g., —
# The imp module is deprecated since Python 3.4; the replacement we use,
# module_from_spec(), is available since Python 3.5.
> @@ -821,10 +826,15 @@
> if sys.version_info < (3, 0):
> prog_mod = imp.load_module(progbase[:-3], open(progabs, 'r'),
> progabs,
> ('.py', 'U', imp.PY_SOURCE))
> - else:
> + elif sys.version_info < (3, 5):
> prog_mod = imp.load_module(progbase[:-3],
> open(progabs, 'r', encoding="utf-8"),
> progabs, ('.py', 'U', imp.PY_SOURCE))
> + else:
> + spec = importlib.util.spec_from_file_location(progbase[:-3],
> progabs)
> + prog_mod = importlib.util.module_from_spec(spec)
> + sys.modules[progbase[:-3]] = prog_mod
> + spec.loader.exec_module(prog_mod)
Looks good to me. I looked at the docstrings of the called functions and
I don't see any reason not to use the code example as-is.
All tests pass, Python 3.5.3 on Linux.
Cheers,
Daniel