subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From futat...@apache.org
Subject svn commit: r1872308 - /subversion/trunk/build/run_tests.py
Date Sat, 04 Jan 2020 08:32:25 GMT
Author: futatuki
Date: Sat Jan  4 08:32:25 2020
New Revision: 1872308

URL: http://svn.apache.org/viewvc?rev=1872308&view=rev
Log:
Use importlib package on Python >= 3.5, instead of imp package

* build/run_tets.py
 (): Import importlib.util if Python >= 3.5, else import imp as it is 
 (TestHarness._run_py_test): Use recipe to import a source module from
 absolute path [1] for Python >= 3.5

[1] https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly

Review by: danielsh
           hartmannathan

Modified:
    subversion/trunk/build/run_tests.py

Modified: subversion/trunk/build/run_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/build/run_tests.py?rev=1872308&r1=1872307&r2=1872308&view=diff
==============================================================================
--- subversion/trunk/build/run_tests.py (original)
+++ subversion/trunk/build/run_tests.py Sat Jan  4 08:32:25 2020
@@ -50,7 +50,7 @@ separated list of test numbers; the defa
 import os, sys, shutil, codecs
 import re
 import logging
-import optparse, subprocess, imp, threading, traceback
+import optparse, subprocess, threading, traceback
 from datetime import datetime
 
 try:
@@ -64,6 +64,13 @@ if sys.version_info < (3, 0):
   # Python >= 3.0 already has this build in
   import exceptions
 
+if sys.version_info < (3, 5):
+  import imp
+else:
+  # The imp module is deprecated since Python 3.4; the replacement we use,
+  # module_from_spec(), is available since Python 3.5.
+  import importlib.util
+
 # Ensure the compiled C tests use a known locale (Python tests set the locale
 # explicitly).
 os.environ['LC_ALL'] = 'C'
@@ -821,10 +828,15 @@ class TestHarness:
       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)
     except:
       print("\nError loading test (details in following traceback): " + progbase)
       traceback.print_exc()



Mime
View raw message