Skip to content

Commit 925e5ed

Browse files
check that unasync'ed files are up to date (#2605)
1 parent b44e963 commit 925e5ed

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

noxfile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ def lint(session):
8585
session.run("python", "-c", "from elasticsearch import Elasticsearch")
8686
session.run("python", "-c", "from elasticsearch._otel import OpenTelemetry")
8787

88-
session.install("flake8", "black~=24.0", "mypy", "isort", "types-requests")
88+
session.install(
89+
"flake8", "black~=24.0", "mypy", "isort", "types-requests", "unasync>=0.6.0"
90+
)
8991
session.run("isort", "--check", "--profile=black", *SOURCE_FILES)
9092
session.run("black", "--check", *SOURCE_FILES)
93+
session.run("python", "utils/run-unasync.py", "--check")
9194
session.run("flake8", *SOURCE_FILES)
9295
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)
9396

utils/run-unasync.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import os
1919
import subprocess
20+
import sys
2021
from glob import glob
2122
from pathlib import Path
2223

@@ -34,10 +35,14 @@ def cleanup(source_dir: Path, output_dir: Path, patterns: list[str]):
3435
def run(
3536
rule: unasync.Rule,
3637
cleanup_patterns: list[str] = [],
38+
check: bool = False,
3739
):
3840
root_dir = Path(__file__).absolute().parent.parent
3941
source_dir = root_dir / rule.fromdir.lstrip("/")
40-
output_dir = root_dir / rule.todir.lstrip("/")
42+
output_dir = check_dir = root_dir / rule.todir.lstrip("/")
43+
if check:
44+
rule.todir += "_sync_check/"
45+
output_dir = root_dir / rule.todir.lstrip("/")
4146

4247
filepaths = []
4348
for root, _, filenames in os.walk(source_dir):
@@ -53,8 +58,23 @@ def run(
5358
if cleanup_patterns:
5459
cleanup(source_dir, output_dir, cleanup_patterns)
5560

61+
if check:
62+
subprocess.check_call(["black", output_dir])
63+
subprocess.check_call(["isort", "--profile=black", output_dir])
5664

57-
def main():
65+
# make sure there are no differences between _sync and _sync_check
66+
for file in glob("*.py", root_dir=output_dir):
67+
subprocess.check_call(
68+
[
69+
"diff",
70+
f"{check_dir}/{file}",
71+
f"{output_dir}/{file}",
72+
]
73+
)
74+
subprocess.check_call(["rm", "-rf", output_dir])
75+
76+
77+
def main(check: bool = False):
5878
run(
5979
rule=unasync.Rule(
6080
fromdir="/elasticsearch/_async/client/",
@@ -69,6 +89,7 @@ def main():
6989
"_TYPE_ASYNC_SNIFF_CALLBACK": "_TYPE_SYNC_SNIFF_CALLBACK",
7090
},
7191
),
92+
check=check,
7293
)
7394

7495
run(
@@ -93,8 +114,9 @@ def main():
93114
cleanup_patterns=[
94115
"/^import asyncio$/d",
95116
],
117+
check=check,
96118
)
97119

98120

99121
if __name__ == "__main__":
100-
main()
122+
main(check="--check" in sys.argv)

0 commit comments

Comments
 (0)