Skip to content

PYTHON-5048 - Synchro script should correctly process all files #2069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions tools/synchro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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__":
Expand Down
Loading