You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2023/03/10 22:02:18 UTC

[allura] 03/03: [#8502] run ruff all at once, instead of in groups of files

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 13a0670bcb84525dd84d03afce6a52e7d5d4193e
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Fri Mar 10 16:51:21 2023 -0500

    [#8502] run ruff all at once, instead of in groups of files
---
 AlluraTest/alluratest/test_syntax.py | 44 +++---------------------------------
 scripts/perf/call_count.py           |  4 ++--
 2 files changed, 5 insertions(+), 43 deletions(-)

diff --git a/AlluraTest/alluratest/test_syntax.py b/AlluraTest/alluratest/test_syntax.py
index 6bf68f3f1..39eef5302 100644
--- a/AlluraTest/alluratest/test_syntax.py
+++ b/AlluraTest/alluratest/test_syntax.py
@@ -37,13 +37,6 @@ def run(cmd):
 find_py = r"find Allura Forge* -not -path '*/\.*' -name '*.py'"
 
 
-# a recipe from itertools doc
-def grouper(n, iterable, fillvalue=None):
-    "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
-    args = [iter(iterable)] * n
-    return zip_longest(fillvalue=fillvalue, *args)
-
-
 def test_no_local_tz_functions():
     if run(find_py + r" | xargs grep '\.now(' ") not in [1, 123]:
         raise Exception("These should use .utcnow()")
@@ -62,7 +55,7 @@ def test_no_prints():
         '/scripts/',
         'ForgeSVN/setup.py',
     ]
-    if run(find_py + " | grep -v '" + "' | grep -v '".join(skips) + "' | xargs grep -v '^ *#' | egrep -n '\bprint\(' | grep -E -v '(pprint|#pragma: ?printok)' ") != 1:
+    if run(find_py + " | grep -v '" + "' | grep -v '".join(skips) + r"' | xargs grep -v '^ *#' | egrep -n '\bprint\(' | grep -E -v '(pprint|#pragma: ?printok)' ") != 1:
         raise Exception("These should use logging instead of print")
 
 
@@ -71,40 +64,9 @@ def test_no_tabs():
         raise Exception('These should not use tab chars')
 
 
-def run_ruff(files):
-    # skip some that aren't critical errors
-    files = [f for f in files if '/migrations/' not in f]
-    cmd = f"ruff check {' '.join(files)}  --config {BASE_PATH[0]}/ruff.toml --show-source"
+def test_ruff():
+    cmd = f"ruff check . --config {BASE_PATH[0]}/ruff.toml --show-source"
     if run(cmd) != 0:
         # print 'Command was: %s' % cmd
         raise Exception('ruff failure, see stdout')
 
-
-class TestLinters:
-    # this will get populated dynamically with test methods, see below
-    pass
-
-
-# Dynamically generate many test methods, to run pylint & ruff commands in separate batches
-# Can't use http://nose.readthedocs.io/en/latest/writing_tests.html#test-generators because nose doesn't run
-# those in parallel
-def create_many_lint_methods():
-    proc = Popen(find_py, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
-    (find_stdout, stderr) = proc.communicate()
-    find_stdout = find_stdout.decode('utf-8')
-    stderr = stderr.decode('utf-8')
-    sys.stderr.write(stderr)
-    assert proc.returncode == 0, proc.returncode
-    py_files = find_stdout.split('\n')
-
-    for i, files in enumerate(grouper(40, py_files)):
-        files = [_f for _f in files if _f]
-        if not files:
-            continue
-
-        pyflake_test_method = lambda self, these_files=files: run_ruff(these_files)
-        pyflake_test_method.__name__ = str(f'test_ruff_{i}')
-        setattr(TestLinters, f'test_ruff_{i}', pyflake_test_method)
-
-
-create_many_lint_methods()
diff --git a/scripts/perf/call_count.py b/scripts/perf/call_count.py
index 4c567b7df..32cf5f3d8 100755
--- a/scripts/perf/call_count.py
+++ b/scripts/perf/call_count.py
@@ -70,7 +70,7 @@ def main(args):
                         debug_html=args.debug_html)
     print(json.dumps(counts))
     write_csv(counts, args.id, args.data_file)
-    test.teardown_method(method)
+    test.teardown_method()
 
 
 def setup(test):
@@ -79,7 +79,7 @@ def setup(test):
                                   'stats.debug_line_length': 1000,
                                   }), \
             patch('timermiddleware.log.isEnabledFor', return_value=True):  # can't set this via logging configuration since setUp() will load a logging config and then start using it before we have a good place to tweak it
-        test.setup_method(method)
+        test.setup_method()
 
     tmw_log = logging.getLogger('timermiddleware')
     tmw_log.disabled = 0  # gets disabled when .ini file is loaded; dumb.