Skip to content

Commit

Permalink
[CodeStyle][isort] introducing isort (part1) (#46475)
Browse files Browse the repository at this point in the history
* add isort config

* isort all files
  • Loading branch information
SigureMo authored Nov 25, 2022
1 parent 34fd65c commit cfd7ff8
Show file tree
Hide file tree
Showing 964 changed files with 3,459 additions and 2,493 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ repos:
hooks:
- id: black
files: (.*\.(py|pyi|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
Expand Down
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,30 @@
exclude = "build"
line-length = 80
skip-string-normalization = true

[tool.isort]
profile = "black"
line_length = 80
known_first_party = ["paddle"]
skip = ["build", "__init__.py"]
extend_skip_glob = [
# These files do not need to be formatted,
# see .flake8 for more details
"python/paddle/fluid/[!t]**",
"python/paddle/fluid/tra**",
"*_pb2.py",
"python/paddle/utils/gast/**",
"python/paddle/fluid/tests/unittests/npu/**",
"python/paddle/fluid/tests/unittests/mlu/**",

# These files will be fixed in the future
"cmake/**",
"paddle/**",
"r/**",
"tools/**",
"python/paddle/[!f]**",
"python/paddle/fluid/tests/unittests/[t-z]**",
"python/paddle/fluid/tests/unittests/dygraph_to_static/test_error.py",
"python/paddle/fluid/tests/unittests/dygraph_to_static/**",
"python/paddle/fluid/tests/unittests/ipu/test_dy2static_ipu.py",
]
9 changes: 6 additions & 3 deletions python/paddle/fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
# limitations under the License.

from typing import Sequence

import numpy as np

import paddle
from .tensor.attribute import is_floating_point, is_integer
from .tensor.creation import _real_to_complex_dtype, _complex_to_real_dtype
from .fluid.framework import _in_legacy_dygraph, in_dygraph_mode

from . import _C_ops, _legacy_C_ops
from .fluid.data_feeder import check_variable_and_dtype
from .fluid.framework import _in_legacy_dygraph, in_dygraph_mode
from .fluid.layer_helper import LayerHelper
from .tensor.attribute import is_floating_point, is_integer
from .tensor.creation import _complex_to_real_dtype, _real_to_complex_dtype

__all__ = [
'fft',
Expand Down
12 changes: 7 additions & 5 deletions python/paddle/fluid/tests/book/notest_understand_sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import paddle.fluid as fluid
import paddle
import contextlib
import math
import numpy as np
import sys
import os
import sys
import unittest

import numpy as np

import paddle
import paddle.fluid as fluid


def convolution_net(
Expand Down
15 changes: 8 additions & 7 deletions python/paddle/fluid/tests/book/test_fit_a_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import paddle
import paddle.fluid as fluid
import paddle.static.amp as amp

import contextlib
import numpy
import unittest
import math
import sys
import os
import struct
import sys
import tempfile
import unittest

import numpy

import paddle
import paddle.fluid as fluid
import paddle.static.amp as amp

paddle.enable_static()

Expand Down
12 changes: 7 additions & 5 deletions python/paddle/fluid/tests/book/test_image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import paddle
import paddle.fluid as fluid
import contextlib
import math
import sys
import numpy
import unittest
import os
import sys
import tempfile
import unittest

import numpy

import paddle
import paddle.fluid as fluid

paddle.enable_static()

Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/book/test_label_semantic_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# limitations under the License.

import contextlib
import numpy as np
import os
import tempfile
import time
import unittest
import tempfile

import numpy as np

import paddle
import paddle.dataset.conll05 as conll05
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/book/test_machine_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
# limitations under the License.

import contextlib
import os
import unittest

import numpy as np

import paddle
import paddle.fluid as fluid
import paddle.fluid.framework as framework
import paddle.fluid.layers as pd
from paddle.fluid.executor import Executor
import unittest
import os

paddle.enable_static()

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/book/test_recognize_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import paddle.fluid.core as core
import math
import os
import sys
Expand All @@ -22,6 +21,7 @@

import paddle
import paddle.fluid as fluid
import paddle.fluid.core as core

paddle.enable_static()

Expand Down
6 changes: 4 additions & 2 deletions python/paddle/fluid/tests/book/test_recommender_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
# limitations under the License.

import math
import sys
import os
import sys
import tempfile

import numpy as np

import paddle
import paddle.fluid as fluid
import paddle.fluid.framework as framework
import paddle.fluid.layers as layers
import paddle.fluid.nets as nets
import tempfile
from paddle.fluid.executor import Executor
from paddle.fluid.optimizer import SGDOptimizer

Expand Down
15 changes: 8 additions & 7 deletions python/paddle/fluid/tests/book/test_rnn_encoder_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import paddle
import paddle.fluid as fluid
import paddle.fluid.framework as framework
import contextlib
import math
import sys
import os
import unittest
import sys
import tempfile
from paddle.fluid.executor import Executor
import unittest

import numpy as np

import paddle
import paddle.fluid as fluid
import paddle.fluid.framework as framework
from paddle.fluid.executor import Executor

paddle.enable_static()

Expand Down
12 changes: 7 additions & 5 deletions python/paddle/fluid/tests/book/test_word2vec_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import paddle
import paddle.fluid as fluid
import unittest
import os
import numpy as np
import math
import os
import sys
import tempfile
import unittest

import numpy as np

import paddle
import paddle.fluid as fluid

paddle.enable_static()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
# limitations under the License.

import os
from paddle.fluid import core
from distutils.core import Extension, setup
from distutils.sysconfig import get_python_lib
from distutils.core import setup, Extension

from setuptools.command.build_ext import build_ext

from paddle.fluid import core


# refer: https://note.qidong.name/2018/03/setup-warning-strict-prototypes
# Avoid a gcc warning below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import os
import site
from paddle.fluid import core
from distutils.core import setup, Extension
from distutils.core import Extension, setup

from setuptools.command.build_ext import build_ext

from paddle.fluid import core


# refer: https://note.qidong.name/2018/03/setup-warning-strict-prototypes
# Avoid a gcc warning below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import sys
import unittest

import numpy as np


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
# limitations under the License.

import os
import sys
import site
import sys
import unittest

import numpy as np


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# limitations under the License.

import os

from utils import extra_compile_args, paddle_includes

import paddle
import paddle.fluid.core as core
from paddle.utils.cpp_extension import CppExtension, CUDAExtension, setup
from utils import paddle_includes, extra_compile_args

if paddle.is_compiled_with_cuda():
sources = ['custom_raw_op_kernel_op.cc', 'custom_raw_op_kernel_op.cu']
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/custom_op/custom_relu_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from utils import paddle_includes, extra_compile_args, IS_MAC
from paddle.utils.cpp_extension import CUDAExtension, setup, CppExtension
from utils import IS_MAC, extra_compile_args, paddle_includes

from paddle.utils.cpp_extension import CppExtension, CUDAExtension, setup

# Mac-CI don't support GPU
Extension = CppExtension if IS_MAC else CUDAExtension
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/custom_op/test_check_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import os
import unittest
import warnings

import paddle.utils.cpp_extension.extension_utils as utils
Expand Down
7 changes: 4 additions & 3 deletions python/paddle/fluid/tests/custom_op/test_context_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

import os
import unittest

import numpy as np
from utils import extra_cc_args, extra_nvcc_args, paddle_includes

import paddle
from paddle.utils.cpp_extension import load, get_build_directory
from utils import paddle_includes, extra_cc_args, extra_nvcc_args
from paddle.utils.cpp_extension.extension_utils import run_cmd
from paddle.fluid.framework import _test_eager_guard
from paddle.utils.cpp_extension import get_build_directory, load
from paddle.utils.cpp_extension.extension_utils import run_cmd

# Because Windows don't use docker, the shared lib already exists in the
# cache dir, it will not be compiled again unless the shared lib is removed.
Expand Down
7 changes: 4 additions & 3 deletions python/paddle/fluid/tests/custom_op/test_custom_attrs_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

import os
import unittest

import numpy as np
from utils import extra_cc_args, extra_nvcc_args, paddle_includes

import paddle
from paddle.utils.cpp_extension import load, get_build_directory
from utils import paddle_includes, extra_cc_args, extra_nvcc_args
from paddle.utils.cpp_extension.extension_utils import run_cmd
from paddle.fluid.framework import _test_eager_guard
from paddle.utils.cpp_extension import get_build_directory, load
from paddle.utils.cpp_extension.extension_utils import run_cmd

# Because Windows don't use docker, the shared lib already exists in the
# cache dir, it will not be compiled again unless the shared lib is removed.
Expand Down
7 changes: 4 additions & 3 deletions python/paddle/fluid/tests/custom_op/test_custom_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

import os
import unittest

import numpy as np
from utils import extra_cc_args, extra_nvcc_args, paddle_includes

import paddle
import paddle.static as static
from paddle.utils.cpp_extension import load, get_build_directory
from paddle.utils.cpp_extension.extension_utils import run_cmd
from utils import paddle_includes, extra_cc_args, extra_nvcc_args
from paddle.fluid.framework import _test_eager_guard
from paddle.utils.cpp_extension import get_build_directory, load
from paddle.utils.cpp_extension.extension_utils import run_cmd

# Because Windows don't use docker, the shared lib already exists in the
# cache dir, it will not be compiled again unless the shared lib is removed.
Expand Down
Loading

0 comments on commit cfd7ff8

Please sign in to comment.