Skip to content

check that unasync'ed files are up to date #2605

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
Jul 1, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ def lint(session):
session.run("python", "-c", "from elasticsearch import Elasticsearch")
session.run("python", "-c", "from elasticsearch._otel import OpenTelemetry")

session.install("flake8", "black~=24.0", "mypy", "isort", "types-requests")
session.install(
"flake8", "black~=24.0", "mypy", "isort", "types-requests", "unasync>=0.6.0"
)
session.run("isort", "--check", "--profile=black", *SOURCE_FILES)
session.run("black", "--check", *SOURCE_FILES)
session.run("python", "utils/run-unasync.py", "--check")
session.run("flake8", *SOURCE_FILES)
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)

Expand Down
28 changes: 25 additions & 3 deletions utils/run-unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import os
import subprocess
import sys
from glob import glob
from pathlib import Path

Expand All @@ -34,10 +35,14 @@ def cleanup(source_dir: Path, output_dir: Path, patterns: list[str]):
def run(
rule: unasync.Rule,
cleanup_patterns: list[str] = [],
check: bool = False,
):
root_dir = Path(__file__).absolute().parent.parent
source_dir = root_dir / rule.fromdir.lstrip("/")
output_dir = root_dir / rule.todir.lstrip("/")
output_dir = check_dir = root_dir / rule.todir.lstrip("/")
if check:
rule.todir += "_sync_check/"
output_dir = root_dir / rule.todir.lstrip("/")

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

if check:
subprocess.check_call(["black", output_dir])
subprocess.check_call(["isort", "--profile=black", output_dir])

def main():
# make sure there are no differences between _sync and _sync_check
for file in glob("*.py", root_dir=output_dir):
subprocess.check_call(
[
"diff",
f"{check_dir}/{file}",
f"{output_dir}/{file}",
]
)
subprocess.check_call(["rm", "-rf", output_dir])


def main(check: bool = False):
run(
rule=unasync.Rule(
fromdir="/elasticsearch/_async/client/",
Expand All @@ -69,6 +89,7 @@ def main():
"_TYPE_ASYNC_SNIFF_CALLBACK": "_TYPE_SYNC_SNIFF_CALLBACK",
},
),
check=check,
)

run(
Expand All @@ -93,8 +114,9 @@ def main():
cleanup_patterns=[
"/^import asyncio$/d",
],
check=check,
)


if __name__ == "__main__":
main()
main(check="--check" in sys.argv)
Loading