Replace isort with Ruff (#10912)

This commit is contained in:
Avasam
2023-10-27 23:14:38 -04:00
committed by GitHub
parent 77bccbe1f1
commit 49ba409da8
12 changed files with 29 additions and 50 deletions

View File

@@ -65,14 +65,9 @@ def run_black(stub_dir: str) -> None:
subprocess.run(["black", stub_dir])
def run_isort(stub_dir: str) -> None:
print(f"Running isort: isort {stub_dir}")
subprocess.run([sys.executable, "-m", "isort", stub_dir])
def run_ruff(stub_dir: str) -> None:
print(f"Running Ruff: ruff {stub_dir}")
subprocess.run([sys.executable, "-m", "ruff", stub_dir])
print(f"Running Ruff: ruff check {stub_dir} --fix-only")
subprocess.run([sys.executable, "-m", "ruff", "check", stub_dir, "--fix-only"])
async def get_project_urls_from_pypi(project: str, session: aiohttp.ClientSession) -> dict[str, str]:
@@ -189,7 +184,7 @@ def add_pyright_exclusion(stub_dir: str) -> None:
def main() -> None:
parser = argparse.ArgumentParser(
description="""Generate baseline stubs automatically for an installed pip package
using stubgen. Also run Black, isort and Ruff. If the name of
using stubgen. Also run Black and Ruff. If the name of
the project is different from the runtime Python package name, you may
need to use --package (example: --package yaml PyYAML)."""
)
@@ -239,7 +234,6 @@ def main() -> None:
run_stubdefaulter(stub_dir)
run_ruff(stub_dir)
run_isort(stub_dir)
run_black(stub_dir)
create_metadata(project, stub_dir, version)

View File

@@ -45,7 +45,7 @@ PYTHON_PROTOBUF_DIR="protobuf-$PYTHON_PROTOBUF_VERSION"
VENV=venv
python3 -m venv "$VENV"
source "$VENV/bin/activate"
pip install -r "$REPO_ROOT/requirements-tests.txt" # for Black and isort
pip install -r "$REPO_ROOT/requirements-tests.txt" # for Black and Ruff
# Install mypy-protobuf
pip install mypy-protobuf=="$MYPY_PROTOBUF_VERSION"
@@ -73,7 +73,7 @@ PROTO_FILES=$(grep "GenProto.*google" $PYTHON_PROTOBUF_DIR/python/setup.py | \
# shellcheck disable=SC2086
protoc_install/bin/protoc --proto_path="$PYTHON_PROTOBUF_DIR/src" --mypy_out="relax_strict_optional_primitives:$REPO_ROOT/stubs/protobuf" $PROTO_FILES
isort "$REPO_ROOT/stubs/protobuf"
ruff check "$REPO_ROOT/stubs/protobuf" --fix-only
black "$REPO_ROOT/stubs/protobuf"
sed --in-place="" \

View File

@@ -83,9 +83,7 @@ def main() -> None:
# Run formatters first. Order matters.
print("\nRunning Ruff...")
subprocess.run([sys.executable, "-m", "ruff", path])
print("\nRunning isort...")
subprocess.run([sys.executable, "-m", "isort", path])
subprocess.run([sys.executable, "-m", "ruff", "check", path])
print("\nRunning Black...")
black_result = subprocess.run([sys.executable, "-m", "black", path])
if black_result.returncode == 123:

View File

@@ -61,7 +61,7 @@ rm tensorflow/compiler/xla/service/hlo_execution_profile_data_pb2.pyi \
tensorflow/core/protobuf/worker_service_pb2.pyi \
tensorflow/core/util/example_proto_fast_parsing_test_pb2.pyi
isort "$REPO_ROOT/stubs/tensorflow/tensorflow"
ruff check "$REPO_ROOT/stubs/tensorflow/tensorflow" --fix-only
black "$REPO_ROOT/stubs/tensorflow/tensorflow"
sed --in-place="" \