From 9f16251b648af0532786e6c5f3951a2a9bc6732f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 29 Sep 2025 09:08:52 -0400 Subject: [PATCH] lock down format_docs_code.py to specific paths 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 | 28 ++++++++++++++++++---------- tox.ini | 2 ++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tools/format_docs_code.py b/tools/format_docs_code.py index 76c341652e..056e7ef702 100644 --- a/tools/format_docs_code.py +++ b/tools/format_docs_code.py @@ -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 712da78858..383edfc4e2 100644 --- 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] -- 2.47.3