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

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

commit 2790de3e9ecf1b85af7b6b90834ab4a43c4bfb82
Author: Dave Brondsema <dbronds...@slashdotmedia.com>
AuthorDate: Wed Jan 3 14:58:33 2024 -0500

    [#8532] use ruff to check for print/debug/etc
---
 .pre-commit-config.yaml     | 37 -------------------------------------
 Allura/allura/lib/utils.py  |  2 +-
 Allura/ldap-userconfig.py   |  6 +++++-
 Allura/setup.py             |  2 +-
 ruff.toml                   | 13 ++++++++++---
 scripts/teamforge-import.py |  3 ++-
 6 files changed, 19 insertions(+), 44 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 10f947e3d..0e3a5168f 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -27,9 +27,6 @@ repos:
         exclude: '.babelrc'
     -   id: check-merge-conflict
         fail_fast: true
-    # python checks
-    -   id: debug-statements
-        exclude: '^Allura/allura/lib/utils.py$'
     # other checks
     -   id: check-docstring-first
         exclude: |
@@ -43,11 +40,6 @@ repos:
 -   repo: https://github.com/pre-commit/pygrep-hooks
     rev: v1.10.0
     hooks:
-    -   id: python-check-blanket-noqa
-        exclude: '^Allura/setup.py$'
-    -   id: python-check-mock-methods
-        exclude: '^Allura/allura/tests/test_tasks.py$'
-    -   id: python-no-log-warn
     -   id: rst-backticks
         exclude:
           (?x)^(
@@ -70,35 +62,6 @@ repos:
         language: pygrep
         types: [python]
         entry: '\.now\(|\.fromtimestamp\(|\.mktime\('
-      - id: noprint
-        name: check for print statements
-        language: pygrep
-        types: [python]
-        entry: '\bprint\('
-        exclude: |
-            (?x)^(
-                /tests/.*|
-                Allura/allura/command/.*|
-                Allura/ldap-setup.py|
-                scripts/.*|
-                Allura/ldap-userconfig.py|
-                /scripts/.*|
-                ForgeSVN/setup.py|
-                Allura/allura/scripts/.*|
-                Allura/allura/tests/.*|
-                AlluraTest/alluratest/.*|
-                ForgeGit/forgegit/tests/.*|
-                fuse/.*|
-                run_tests|
-                ForgeSVN/forgesvn/tests/.*|
-                ForgeWiki/forgewiki/tests/.*|
-                ForgeImporters/forgeimporters/tests/.*
-            )$
-      - id: notab
-        name: check for tabs
-        language: pygrep
-        types: [python]
-        entry: '       '
 # SCSS Syntax: could use placeholders instead of extending a class or tag 
directly
       - id: scss_extend_pattern
         name: search for scss invalid extend patterns in class elements
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index df42eeeeb..683a7fcae 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -461,7 +461,7 @@ class CaseInsensitiveDict(TransformedDict):
 
 def postmortem_hook(etype, value, tb):  # pragma no cover
     import sys
-    import pdb
+    import pdb  # noqa: T100
     import traceback
     sys.stderr.write('Entering post-mortem PDB shell\n')
     traceback.print_exception(etype, value, tb)
diff --git a/Allura/ldap-userconfig.py b/Allura/ldap-userconfig.py
index a300d4d02..dd1c270c0 100644
--- a/Allura/ldap-userconfig.py
+++ b/Allura/ldap-userconfig.py
@@ -26,7 +26,11 @@ import grp
 def main():
     command = sys.argv[1]
     uname = sys.argv[2]
-    eval(command)(uname, *sys.argv[3:])
+    fn = {
+        'init': init,
+        'upload': upload,
+    }[command]
+    fn(uname, *sys.argv[3:])
 
 
 def init(uname):
diff --git a/Allura/setup.py b/Allura/setup.py
index ece157874..a6016bbbf 100644
--- a/Allura/setup.py
+++ b/Allura/setup.py
@@ -26,7 +26,7 @@ lists, wiki pages, blogs and more for any number of 
individual projects.
 '''
 setup(
     name='Allura',
-    version=__version__, # noqa
+    version=__version__, # noqa: F821
     description='Base distribution of the Allura development platform',
     long_description=PROJECT_DESCRIPTION,
     author='Allura Team',
diff --git a/ruff.toml b/ruff.toml
index 7fdb9bcd6..2b8e99ba6 100644
--- a/ruff.toml
+++ b/ruff.toml
@@ -16,7 +16,7 @@
 #       under the License.
 
 line-length = 119
-
+show-source = true
 
 select = [
     # all flake8 & pep8 (except 'ignore' below)
@@ -27,6 +27,9 @@ select = [
     "RUF013",  # implicit Optional (=None)
     "ISC001",  # NIC001 in flake8 codes
     "B",
+    "PGH",  # https://github.com/pre-commit/pygrep-hooks
+    "T10",  # debugger breakpoints
+    "T20",  # print()
 ]
 
 ignore = [
@@ -41,7 +44,11 @@ ignore = [
     'B904', # use raise from
 ]
 
-
 [per-file-ignores]
 '__init__.py' = ['F403']  # import *
-'**/{alluratest,tests}/*' = ['B011']  # assert False
+'**/{alluratest,tests}/*' = [
+    'B011',  # assert False
+    'T20',  # print
+]
+'{scripts,Allura/allura/scripts,Allura/allura/command}/*' = ['T20']  # print
+'{run_tests,fuse/accessfs.py,ForgeSVN/setup.py}' = ['T20']  # print
diff --git a/scripts/teamforge-import.py b/scripts/teamforge-import.py
index 7c68ede2b..15b669d38 100644
--- a/scripts/teamforge-import.py
+++ b/scripts/teamforge-import.py
@@ -16,6 +16,7 @@
 #       under the License.
 
 import logging
+from ast import literal_eval
 from getpass import getpass
 from optparse import OptionParser
 from tg import tmpl_context as c
@@ -89,7 +90,7 @@ def main():
         config = ConfigParser()
         config.read(options.config_file)
         defaults.update(
-            (k, eval(v)) for k, v in config.items('teamforge-import'))
+            (k, literal_eval(v)) for k, v in config.items('teamforge-import'))
         optparser = get_parser(defaults)
         options, project_ids = optparser.parse_args()
 

Reply via email to