Skip to content

Commit

Permalink
validate _sync directory during lint phase
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Mar 11, 2024
1 parent b68c4bd commit 156bf80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def format(session):

@nox.session(python="3.12")
def lint(session):
session.install("flake8", "black~=24.0", "isort")
session.install("flake8", "black~=24.0", "isort", "unasync", "setuptools")
session.run("black", "--check", "--target-version=py37", *SOURCE_FILES)
session.run("isort", "--check", *SOURCE_FILES)
session.run("python", "utils/run-unasync.py", "check")
session.run("flake8", "--ignore=E501,E741,W503", *SOURCE_FILES)
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)

Expand Down
26 changes: 23 additions & 3 deletions utils/run-unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
# under the License.

import os
import subprocess
import sys
from pathlib import Path

import unasync


def main():
def main(check=False):
output_dir = "_sync" if not check else "_sync_check"

# Unasync all the generated async code
additional_replacements = {
"aiter": "iter",
Expand All @@ -35,7 +39,7 @@ def main():
rules = [
unasync.Rule(
fromdir="/elasticsearch_dsl/_async/",
todir="/elasticsearch_dsl/_sync/",
todir=f"/elasticsearch_dsl/{output_dir}/",
additional_replacements=additional_replacements,
),
]
Expand All @@ -53,6 +57,22 @@ def main():

unasync.unasync_files(filepaths, rules)

if check:
# make sure there are no differences between _sync and _sync_check
subprocess.check_call(
["black", "--target-version=py37", "elasticsearch_dsl/_sync_check/"]
)
subprocess.check_call(
[
"diff",
"-x",
"__pycache__",
"elasticsearch_dsl/_sync",
"elasticsearch_dsl/_sync_check",
]
)
subprocess.check_call(["rm", "-rf", "elasticsearch_dsl/_sync_check"])


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

0 comments on commit 156bf80

Please sign in to comment.