Patchwork tests: check availability of pyflakes by trying to import pyflakes module

login
register
mail settings
Submitter Manuel Jacob
Date March 11, 2020, 4:41 a.m.
Message ID <14cffca0d2f0b0818ac9.1583901671@tmp.fritz.box>
Download mbox | patch
Permalink /patch/45693/
State Accepted
Headers show

Comments

Manuel Jacob - March 11, 2020, 4:41 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1583901662 -3600
#      Wed Mar 11 05:41:02 2020 +0100
# Node ID 14cffca0d2f0b0818ac98eefc432ba22b3d6e364
# Parent  a08bbdf839ae08ff69c6f99a289ee85b3a012f03
tests: check availability of pyflakes by trying to import pyflakes module

Since e397c6d74652, we use the pyflakes module instead of the pyflakes
executable. As was pointed out during the review, the hghave check can be
rewritten to try to import the pyflakes module instead of spawning a new
subprocess.
Yuya Nishihara - March 11, 2020, 12:48 p.m.
On Wed, 11 Mar 2020 05:41:11 +0100, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1583901662 -3600
> #      Wed Mar 11 05:41:02 2020 +0100
> # Node ID 14cffca0d2f0b0818ac98eefc432ba22b3d6e364
> # Parent  a08bbdf839ae08ff69c6f99a289ee85b3a012f03
> tests: check availability of pyflakes by trying to import pyflakes module

Queued, thanks.

Patch

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -563,11 +563,13 @@ 
 
 @check("pyflakes", "Pyflakes python linter")
 def has_pyflakes():
-    return matchoutput(
-        "sh -c \"echo 'import re' 2>&1 | $PYTHON -m pyflakes\"",
-        br"<stdin>:1: 're' imported but unused",
-        True,
-    )
+    try:
+        import pyflakes
+        pyflakes.__version__
+    except ImportError:
+        return False
+    else:
+        return True
 
 
 @check("pylint", "Pylint python linter")