Revert "[BE] enforce style for empty lines in import segments (#129751)"

This reverts commit f5ff1a3ab9.

Reverted https://github.com/pytorch/pytorch/pull/129751 on behalf of https://github.com/huydhn due to Sorry for reverting your change but I need to revert to cleanly revert https://github.com/pytorch/pytorch/pull/129374, please do a rebase and reland this ([comment](https://github.com/pytorch/pytorch/pull/129751#issuecomment-2197799814))
This commit is contained in:
PyTorch MergeBot 2024-06-29 00:41:41 +00:00
parent fa6c0fe3e4
commit 00d7bba2fa
4 changed files with 13 additions and 94 deletions

View File

@ -1695,9 +1695,8 @@ init_command = [
'--dry-run={{DRYRUN}}',
'--no-black-binary',
'black==23.12.1',
'ufmt==2.7.0',
'usort==1.0.8.post1',
'isort==5.13.2',
'ufmt==2.1.0',
'usort==1.0.6',
]
is_formatter = true

View File

@ -2,89 +2,20 @@ from __future__ import annotations
import argparse
import concurrent.futures
import fnmatch
import json
import logging
import os
import re
import sys
from enum import Enum
from pathlib import Path
from typing import Any, NamedTuple
import isort
from isort import Config as IsortConfig
from ufmt.core import ufmt_string
from ufmt.util import make_black_config
from usort import Config as UsortConfig
IS_WINDOWS: bool = os.name == "nt"
REPO_ROOT = Path(__file__).absolute().parents[3]
ISORT_WHITELIST = re.compile(
"|".join(
(
r"\A\Z", # empty string
*map(
fnmatch.translate,
[
# **
"**",
# .ci/**
".ci/**",
# .github/**
".github/**",
# benchmarks/**
"benchmarks/**",
# functorch/**
"functorch/**",
# tools/**
"tools/**",
# torchgen/**
"torchgen/**",
# test/**
"test/**",
# test/[a-c]*/**
"test/[a-c]*/**",
# test/d*/**
"test/d*/**",
# test/dy*/**
"test/dy*/**",
# test/[e-h]*/**
"test/[e-h]*/**",
# test/i*/**
"test/i*/**",
# test/j*/**
"test/j*/**",
# test/[k-p]*/**
"test/[k-p]*/**",
# test/[q-z]*/**
"test/[q-z]*/**",
# torch/**
"torch/**",
# torch/_[a-c]*/**
"torch/_[a-c]*/**",
# torch/_d*/**
"torch/_d*/**",
# torch/_[e-h]*/**
"torch/_[e-h]*/**",
# torch/_i*/**
"torch/_i*/**",
# torch/_[j-z]*/**
"torch/_[j-z]*/**",
# torch/[a-c]*/**
"torch/[a-c]*/**",
# torch/d*/**
"torch/d*/**",
# torch/[e-n]*/**
"torch/[e-n]*/**",
# torch/[o-z]*/**
"torch/[o-z]*/**",
],
),
)
)
)
def eprint(*args: Any, **kwargs: Any) -> None:
@ -128,33 +59,22 @@ def format_error_message(filename: str, err: Exception) -> LintMessage:
)
def check_file(filename: str) -> list[LintMessage]:
path = Path(filename).absolute()
original = path.read_text(encoding="utf-8")
def check_file(
filename: str,
) -> list[LintMessage]:
with open(filename, "rb") as f:
original = f.read().decode("utf-8")
try:
path = Path(filename)
usort_config = UsortConfig.find(path)
black_config = make_black_config(path)
if not path.samefile(__file__) and not ISORT_WHITELIST.match(
path.absolute().relative_to(REPO_ROOT).as_posix()
):
isorted_replacement = re.sub(
r"(#.*\b)isort: split\b",
r"\g<1>usort: skip",
isort.code(
re.sub(r"(#.*\b)usort:\s*skip\b", r"\g<1>isort: split", original),
config=IsortConfig(settings_path=str(REPO_ROOT)),
file_path=path,
),
)
else:
isorted_replacement = original
# Use UFMT API to call both usort and black
replacement = ufmt_string(
path=path,
content=isorted_replacement,
content=original,
usort_config=usort_config,
black_config=black_config,
)

View File

@ -17,15 +17,14 @@ from ._ndarray import (
from ._ufuncs import * # noqa: F403
from ._util import AxisError, UFuncTypeError
from math import pi, e # usort: skip
# from . import testing
alltrue = all
sometrue = any
inf = float("inf")
nan = float("nan")
from math import pi, e # isort: skip
False_ = False
True_ = True

View File

@ -1,4 +1,5 @@
# mypy: allow-untyped-defs
"""isort:skip_file"""
from pickle import ( # type: ignore[attr-defined]
_compat_pickle,
_extension_registry,