Skip to content

Commit 5d201a0

Browse files
validate _sync directory during lint phase
1 parent b68c4bd commit 5d201a0

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Diff for: noxfile.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ def format(session):
6666

6767
@nox.session(python="3.12")
6868
def lint(session):
69-
session.install("flake8", "black~=24.0", "isort")
69+
session.install("flake8", "black~=24.0", "isort", "unasync", "setuptools")
7070
session.run("black", "--check", "--target-version=py37", *SOURCE_FILES)
7171
session.run("isort", "--check", *SOURCE_FILES)
72+
session.run("python", "utils/run-unasync.py", "--check")
7273
session.run("flake8", "--ignore=E501,E741,W503", *SOURCE_FILES)
7374
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)
7475

Diff for: utils/run-unasync.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
# under the License.
1717

1818
import os
19+
import subprocess
20+
import sys
1921
from pathlib import Path
2022

2123
import unasync
2224

2325

24-
def main():
26+
def main(check=False):
27+
output_dir = "_sync" if not check else "_sync_check"
28+
2529
# Unasync all the generated async code
2630
additional_replacements = {
2731
"aiter": "iter",
@@ -35,7 +39,7 @@ def main():
3539
rules = [
3640
unasync.Rule(
3741
fromdir="/elasticsearch_dsl/_async/",
38-
todir="/elasticsearch_dsl/_sync/",
42+
todir=f"/elasticsearch_dsl/{output_dir}/",
3943
additional_replacements=additional_replacements,
4044
),
4145
]
@@ -53,6 +57,22 @@ def main():
5357

5458
unasync.unasync_files(filepaths, rules)
5559

60+
if check:
61+
# make sure there are no differences between _sync and _sync_check
62+
subprocess.check_call(
63+
["black", "--target-version=py37", "elasticsearch_dsl/_sync_check/"]
64+
)
65+
subprocess.check_call(
66+
[
67+
"diff",
68+
"-x",
69+
"__pycache__",
70+
"elasticsearch_dsl/_sync",
71+
"elasticsearch_dsl/_sync_check",
72+
]
73+
)
74+
subprocess.check_call(["rm", "-rf", "elasticsearch_dsl/_sync_check"])
75+
5676

5777
if __name__ == "__main__":
58-
main()
78+
main(check="--check" in sys.argv)

0 commit comments

Comments
 (0)