~obensonne/poole

Silence a warning and fix test runner.

Details
Message ID
<20191111125322.GB28639@arrakis.home>
DKIM signature
missing
Download raw message
Hi,

This diff silences a deprecation warning and fixes the test runner
(`python` may not be the right binary).

This is close to the PR I raised on bitbucket prior to the move to
sr.ht. I had to resolve a merge conflict in the test runner.

I didn't use `hg email`. I'd prefer to just mail the diff normally. Hope
that's ok.

Thanks


# HG changeset patch
# User Edd Barrett <vext01@gmail.com>
# Date 1573476379 0
#      Mon Nov 11 12:46:19 2019 +0000
# Branch py-tweaks
# Node ID b07ee48b2236cda92266c9cba72e1ff31974748e
# Parent  c54b90d5ff0498537b84edc92a857267350e4bbc
Use `importlib` instead of the deprecated `imp`.

diff -r c54b90d5ff04 -r b07ee48b2236 poole.py
--- a/poole.py	Sun Nov 10 12:33:25 2019 +0100
+++ b/poole.py	Mon Nov 11 12:46:19 2019 +0000
@@ -24,7 +24,8 @@
 # =============================================================================
 
 import glob
-import imp
+import importlib
+import importlib.util
 import optparse
 import os
 from os.path import join as opj
@@ -519,7 +520,15 @@
 
     # macro module
     fname = opj(opts.project, "macros.py")
-    macros = imp.load_source("macros", fname).__dict__ if opx(fname) else {}
+    if os.path.exists(fname):
+        module_name, fname = "macros", opj(opts.project, "macros.py")
+        spec = importlib.util.spec_from_file_location(module_name, fname)
+        module = importlib.util.module_from_spec(spec)
+        sys.modules[module_name] = module
+        spec.loader.exec_module(module)
+        macros = module.__dict__ if opx(fname) else {}
+    else:
+        macros = {}
 
     macros["options"] = opts
     macros["project"] = project
# HG changeset patch
# User Edd Barrett <vext01@gmail.com>
# Date 1573476423 0
#      Mon Nov 11 12:47:03 2019 +0000
# Branch py-tweaks
# Node ID 98a50de712b8b318f5d6251294b577d2708c0ae5
# Parent  b07ee48b2236cda92266c9cba72e1ff31974748e
Use the same Python for tests as the test runner was invoked with.

diff -r b07ee48b2236 -r 98a50de712b8 tests/run.py
--- a/tests/run.py	Mon Nov 11 12:46:19 2019 +0000
+++ b/tests/run.py	Mon Nov 11 12:47:03 2019 +0000
@@ -8,7 +8,7 @@
 
 HERE = os.path.dirname(__file__)
 POOLE = [
-    os.path.join(HERE, "..", "env", "bin", "python"),
+    os.path.join(HERE, "..", "env", "bin", sys.executable),
     os.path.join(HERE, "..", "poole.py"),
 ]
 ACTUAL = os.path.join(HERE, "actual")


-- 
Best Regards
Edd Barrett

http://www.theunixzoo.co.uk
Export thread (mbox)