From ba6f87e46e15f9a582c1847b3943d67004573514 Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Mon, 11 Sep 2023 10:36:47 -0500 Subject: [PATCH] Drop run-black.py Mirroring the change in https://github.com/elastic/elasticsearch-py/pull/2289 --- noxfile.py | 4 +-- utils/run-black.py | 88 ---------------------------------------------- 2 files changed, 2 insertions(+), 90 deletions(-) delete mode 100644 utils/run-black.py diff --git a/noxfile.py b/noxfile.py index fa9e23e..ccaca59 100644 --- a/noxfile.py +++ b/noxfile.py @@ -56,7 +56,7 @@ def format(session): session.run("python", "utils/run-unasync.py") session.run("isort", "--profile=black", *SOURCE_FILES) session.run("flynt", *SOURCE_FILES) - session.run("python", "utils/run-black.py", *SOURCE_FILES) + session.run("black", *SOURCE_FILES) session.run("python", "utils/license-headers.py", "fix", *SOURCE_FILES) lint(session) @@ -67,7 +67,7 @@ def lint(session): session.install("flake8", "black", "mypy", "isort", "types-requests") session.run("isort", "--check", "--profile=black", *SOURCE_FILES) - session.run("python", "utils/run-black.py", "--check", *SOURCE_FILES) + session.run("black", "--check", *SOURCE_FILES) session.run("flake8", *SOURCE_FILES) session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES) diff --git a/utils/run-black.py b/utils/run-black.py deleted file mode 100644 index 36c57d4..0000000 --- a/utils/run-black.py +++ /dev/null @@ -1,88 +0,0 @@ -# Licensed to Elasticsearch B.V. under one or more contributor -# license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright -# ownership. Elasticsearch B.V. licenses this file to you under -# the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -import os -import re -import subprocess -import sys -import time - - -def sleep_if_hot() -> None: - def is_hot() -> bool: - try: - return ( - max( - map( - int, - re.findall( - r"_input\:\s([0-9]{2})\.[0-9]", - subprocess.check_output( - "sensors -u", - shell=True, - stderr=subprocess.STDOUT, - ).decode("utf-8"), - ), - ) - ) - > 80 - ) - except subprocess.CalledProcessError: - return False - - while is_hot(): - time.sleep(0.1) - - -def run_on_directory(dir: str, check: bool) -> None: - for root, _, filenames in os.walk(dir): - for filename in filenames: - if filename.endswith(".py") or filename.endswith(".pyi"): - run_on_file(os.path.join(root, filename), check) - - -def run_on_file(file: str, check: bool) -> None: - try: - subprocess.check_call( - f"black --target-version=py36 {'--check ' if check else ''}{file}", - shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - ) - except subprocess.CalledProcessError as e: - print(e.output) - exit(e.returncode) - sleep_if_hot() - - -def main() -> None: - cwd = os.getcwd() - check = ["--check"] == sys.argv[1:2] - targets = [ - os.path.expanduser(os.path.join(cwd, target)) - for target in sys.argv[1:] - if target != "--check" - ] - for target in targets: - if os.path.isdir(target): - run_on_directory(target, check) - else: - run_on_file(target, check) - - -if __name__ == "__main__": - main()