From d0d50a60d963f93961af9cb0831366ff2572a89d Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 21 Jan 2025 10:06:45 -0500 Subject: [PATCH] PYTHON-5048 - Synchro script should correctly process all files --- tools/synchro.py | 49 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/tools/synchro.py b/tools/synchro.py index 577e82d14e..dbcbbd1351 100644 --- a/tools/synchro.py +++ b/tools/synchro.py @@ -149,6 +149,10 @@ _gridfs_dest_base = "./gridfs/synchronous/" _test_dest_base = "./test/" +if not Path.exists(Path(_pymongo_dest_base)): + Path.mkdir(Path(_pymongo_dest_base)) +if not Path.exists(Path(_gridfs_dest_base)): + Path.mkdir(Path(_gridfs_dest_base)) async_files = [ _pymongo_base + f for f in listdir(_pymongo_base) if (Path(_pymongo_base) / f).is_file() @@ -170,18 +174,6 @@ def async_only_test(f: str) -> bool: if (Path(_test_base) / f).is_file() and not async_only_test(f) ] -sync_files = [ - _pymongo_dest_base + f - for f in listdir(_pymongo_dest_base) - if (Path(_pymongo_dest_base) / f).is_file() -] - -sync_gridfs_files = [ - _gridfs_dest_base + f - for f in listdir(_gridfs_dest_base) - if (Path(_gridfs_dest_base) / f).is_file() -] - # Add each asynchronized test here as part of the converting PR converted_tests = [ "__init__.py", @@ -223,15 +215,10 @@ def async_only_test(f: str) -> bool: "unified_format.py", ] -sync_test_files = [ - _test_dest_base + f for f in converted_tests if (Path(_test_dest_base) / f).is_file() -] - - -docstring_translate_files = sync_files + sync_gridfs_files + sync_test_files - -def process_files(files: list[str]) -> None: +def process_files( + files: list[str], docstring_translate_files: list[str], sync_test_files: list[str] +) -> None: for file in files: if "__init__" not in file or "__init__" and "test" in file: with open(file, "r+") as f: @@ -374,7 +361,27 @@ def main() -> None: unasync_directory(async_files, _pymongo_base, _pymongo_dest_base, replacements) unasync_directory(gridfs_files, _gridfs_base, _gridfs_dest_base, replacements) unasync_directory(test_files, _test_base, _test_dest_base, replacements) - process_files(sync_files + sync_gridfs_files + sync_test_files) + + sync_files = [ + _pymongo_dest_base + f + for f in listdir(_pymongo_dest_base) + if (Path(_pymongo_dest_base) / f).is_file() + ] + + sync_gridfs_files = [ + _gridfs_dest_base + f + for f in listdir(_gridfs_dest_base) + if (Path(_gridfs_dest_base) / f).is_file() + ] + sync_test_files = [ + _test_dest_base + f for f in converted_tests if (Path(_test_dest_base) / f).is_file() + ] + + docstring_translate_files = sync_files + sync_gridfs_files + sync_test_files + + process_files( + sync_files + sync_gridfs_files + sync_test_files, docstring_translate_files, sync_test_files + ) if __name__ == "__main__":