]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
lock down format_docs_code.py to specific paths
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 Sep 2025 13:08:52 +0000 (09:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 29 Sep 2025 15:56:05 +0000 (11:56 -0400)
the script too quick to pick up on dot directories,
random .py files I have in my local checkout, etc.

Change-Id: I6eb66ddd3598495a420d9e4fc0f644b60fb3ec6d

tools/format_docs_code.py
tox.ini

index 76c341652e34816e31d85b70b2002d886f3f7fec..056e7ef70293fb9bd25d71785f870a0d5b482042 100644 (file)
@@ -27,11 +27,19 @@ from black.mode import TargetVersion
 
 
 home = Path(__file__).parent.parent
+include_paths = (
+    re.compile(r"lib/sqlalchemy"),
+    re.compile(r"examples/"),
+    re.compile(r"test/"),
+    re.compile(r"tools/"),
+    re.compile(r"doc/build"),
+    re.compile(r"[^/]+\.rst"),
+    re.compile(r"setup.py|reap_dbs.py"),
+)
+
 ignore_paths = (
-    re.compile(r"changelog/unreleased_\d{2}"),
+    re.compile(r".*/changelog/unreleased_\d{2}"),
     re.compile(r"README\.unittests\.rst"),
-    re.compile(r"\.tox"),
-    re.compile(rf"{home.as_posix()}/build"),
 )
 
 CUSTOM_TARGET_VERSIONS = {"declarative_tables.rst": "PY312"}
@@ -319,13 +327,13 @@ def format_file(
 
 def iter_files(directory: str) -> Iterator[Path]:
     dir_path = home / directory
-    yield from (
-        file
-        for file in chain(
-            dir_path.glob("./**/*.rst"), dir_path.glob("./**/*.py")
-        )
-        if not any(pattern.search(file.as_posix()) for pattern in ignore_paths)
-    )
+
+    for file in chain(dir_path.glob("./**/*.rst"), dir_path.glob("./**/*.py")):
+        local = file.relative_to(home).as_posix()
+        if any(pattern.match(local) for pattern in include_paths) and not any(
+            pattern.match(local) for pattern in ignore_paths
+        ):
+            yield file
 
 
 def main(
diff --git a/tox.ini b/tox.ini
index 712da788587c40acddc17cfd1059bebf4d42be24..383edfc4e2d93f8548edf7808a325a6ab564d18e 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -273,6 +273,8 @@ commands =
      python ./tools/walk_packages.py
 
 
+# this is a test.
+#
 # "pep8" env was renamed to "lint".
 # Kept for backwards compatibility until rename is completed elsewhere.
 [testenv:pep8]