소스 검색

autodetect print/breakpoints (#4581)

* catch stray breakpoints and prints

* autodetect debug prints and breakpoints in main code

* readd hacky print in pyi_generator?
Thomas Brandého 4 달 전
부모
커밋
53f09756b6
5개의 변경된 파일10개의 추가작업 그리고 10개의 파일을 삭제
  1. 1 1
      benchmarks/benchmark_package_size.py
  2. 2 2
      pyproject.toml
  3. 3 3
      reflex/testing.py
  4. 1 1
      reflex/utils/pyi_generator.py
  5. 3 3
      scripts/wait_for_listening_port.py

+ 1 - 1
benchmarks/benchmark_package_size.py

@@ -21,7 +21,7 @@ def get_package_size(venv_path: Path, os_name):
         ValueError: when venv does not exist or python version is None.
     """
     python_version = get_python_version(venv_path, os_name)
-    print("Python version:", python_version)
+    print("Python version:", python_version)  # noqa: T201
     if python_version is None:
         raise ValueError("Error: Failed to determine Python version.")
 

+ 2 - 2
pyproject.toml

@@ -87,13 +87,13 @@ build-backend = "poetry.core.masonry.api"
 target-version = "py39"
 output-format = "concise"
 lint.isort.split-on-trailing-comma = false
-lint.select = ["B", "C4", "D", "E", "ERA", "F", "FURB", "I", "PERF", "PTH", "RUF", "SIM", "W"]
+lint.select = ["B", "C4", "D", "E", "ERA", "F", "FURB", "I", "PERF", "PTH", "RUF", "SIM", "T", "W"]
 lint.ignore = ["B008", "D205", "E501", "F403", "SIM115", "RUF006", "RUF012"]
 lint.pydocstyle.convention = "google"
 
 [tool.ruff.lint.per-file-ignores]
 "__init__.py" = ["F401"]
-"tests/*.py" = ["D100", "D103", "D104", "B018", "PERF"]
+"tests/*.py" = ["D100", "D103", "D104", "B018", "PERF", "T"]
 "reflex/.templates/*.py" = ["D100", "D103", "D104"]
 "*.pyi" = ["D301", "D415", "D417", "D418", "E742"]
 "*/blank.py" = ["I001"]

+ 3 - 3
reflex/testing.py

@@ -52,6 +52,7 @@ from reflex.state import (
     StateManagerRedis,
     reload_state_module,
 )
+from reflex.utils import console
 
 try:
     from selenium import webdriver  # pyright: ignore [reportMissingImports]
@@ -385,7 +386,7 @@ class AppHarness:
             )
             if not line:
                 break
-            print(line)  # for pytest diagnosis
+            print(line)  # for pytest diagnosis #noqa: T201
             m = re.search(reflex.constants.Next.FRONTEND_LISTENING_REGEX, line)
             if m is not None:
                 self.frontend_url = m.group(1)
@@ -403,11 +404,10 @@ class AppHarness:
                     )
                 # catch I/O operation on closed file.
                 except ValueError as e:
-                    print(e)
+                    console.error(str(e))
                     break
                 if not line:
                     break
-                print(line)
 
         self.frontend_output_thread = threading.Thread(target=consume_frontend_output)
         self.frontend_output_thread.start()

+ 1 - 1
reflex/utils/pyi_generator.py

@@ -1202,4 +1202,4 @@ class PyiGenerator:
                         or "Var[Template]" in line
                     ):
                         line = line.rstrip() + "  # type: ignore\n"
-                    print(line, end="")
+                    print(line, end="")  # noqa: T201

+ 3 - 3
scripts/wait_for_listening_port.py

@@ -25,7 +25,7 @@ def _pid_exists(pid):
 
 def _wait_for_port(port, server_pid, timeout) -> Tuple[bool, str]:
     start = time.time()
-    print(f"Waiting for up to {timeout} seconds for port {port} to start listening.")
+    print(f"Waiting for up to {timeout} seconds for port {port} to start listening.")  # noqa: T201
     while True:
         if not _pid_exists(server_pid):
             return False, f"Server PID {server_pid} is not running."
@@ -56,9 +56,9 @@ def main():
     for f in as_completed(futures):
         ok, msg = f.result()
         if ok:
-            print(f"OK: {msg}")
+            print(f"OK: {msg}")  # noqa: T201
         else:
-            print(f"FAIL: {msg}")
+            print(f"FAIL: {msg}")  # noqa: T201
             exit(1)