Skip to content

Commit

Permalink
Modify isort config to prepare for black formatting (pantsbuild#8332)
Browse files Browse the repository at this point in the history
### Problem

Currently, the formatting situation in the python code is quite painful as it involves manual formatting of code.
I would like to replace our current workflow with one involving Black in a subsequent PR (see motivations for the choice over there).
Black is opinionated about code layout, so with our current settings, Black and isort would be having minor opinion differences.

### Solution

Modify the isort configuration to bend to Black's taste.

### Result

Once we run Black on the codebase with a minimal configuration, isort will be happy with the results.
  • Loading branch information
pierrechevalier83 authored and illicitonion committed Sep 27, 2019
1 parent d68fa73 commit 44d4ab5
Show file tree
Hide file tree
Showing 103 changed files with 742 additions and 278 deletions.
4 changes: 4 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

[settings]
line_length=100
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=true
indent=2
lines_after_imports=2
known_first_party=internal_backend,pants,pants_test
Expand Down
3 changes: 2 additions & 1 deletion examples/src/python/example/tensorflow_custom_op/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from setuptools import setup, find_packages
from setuptools import find_packages, setup


setup(
name='tensorflow_custom_op',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

import os

from pants.backend.jvm.ossrh_publication_metadata import (Developer, License,
OSSRHPublicationMetadata, Scm)
from pants.backend.jvm.ossrh_publication_metadata import (
Developer,
License,
OSSRHPublicationMetadata,
Scm,
)
from pants.backend.jvm.repository import Repository
from pants.build_graph.build_file_aliases import BuildFileAliases

Expand Down
5 changes: 3 additions & 2 deletions src/python/pants/backend/codegen/thrift/python/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from pants.backend.codegen.thrift.python.apache_thrift_py_gen import ApacheThriftPyGen
from pants.backend.codegen.thrift.python.py_thrift_namespace_clash_check import \
PyThriftNamespaceClashCheck
from pants.backend.codegen.thrift.python.py_thrift_namespace_clash_check import (
PyThriftNamespaceClashCheck,
)
from pants.backend.codegen.thrift.python.python_thrift_library import PythonThriftLibrary
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.goal.task_registrar import TaskRegistrar as task
Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/jvm/ivy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

from twitter.common.collections import OrderedSet

from pants.backend.jvm.subsystems.jar_dependency_management import (JarDependencyManagement,
PinnedJarArtifactSet)
from pants.backend.jvm.subsystems.jar_dependency_management import (
JarDependencyManagement,
PinnedJarArtifactSet,
)
from pants.backend.jvm.targets.exportable_jvm_library import ExportableJvmLibrary
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.base.generator import Generator, TemplateData
Expand Down
22 changes: 15 additions & 7 deletions src/python/pants/backend/jvm/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from pants.backend.jvm.artifact import Artifact
from pants.backend.jvm.ossrh_publication_metadata import (Developer, License,
OSSRHPublicationMetadata, Scm)
from pants.backend.jvm.ossrh_publication_metadata import (
Developer,
License,
OSSRHPublicationMetadata,
Scm,
)
from pants.backend.jvm.repository import Repository as repo
from pants.backend.jvm.scala_artifact import ScalaArtifact
from pants.backend.jvm.subsystems.jar_dependency_management import JarDependencyManagementSetup
Expand All @@ -21,8 +25,10 @@
from pants.backend.jvm.targets.jvm_app import JvmApp
from pants.backend.jvm.targets.jvm_binary import Duplicate, JarRules, JvmBinary, Skip
from pants.backend.jvm.targets.jvm_prep_command import JvmPrepCommand
from pants.backend.jvm.targets.managed_jar_dependencies import (ManagedJarDependencies,
ManagedJarLibraries)
from pants.backend.jvm.targets.managed_jar_dependencies import (
ManagedJarDependencies,
ManagedJarLibraries,
)
from pants.backend.jvm.targets.scala_exclude import ScalaExclude
from pants.backend.jvm.targets.scala_jar_dependency import ScalaJarDependency
from pants.backend.jvm.targets.scala_library import ScalaLibrary
Expand Down Expand Up @@ -57,9 +63,11 @@
from pants.backend.jvm.tasks.prepare_resources import PrepareResources
from pants.backend.jvm.tasks.prepare_services import PrepareServices
from pants.backend.jvm.tasks.provide_tools_jar import ProvideToolsJar
from pants.backend.jvm.tasks.run_jvm_prep_command import (RunBinaryJvmPrepCommand,
RunCompileJvmPrepCommand,
RunTestJvmPrepCommand)
from pants.backend.jvm.tasks.run_jvm_prep_command import (
RunBinaryJvmPrepCommand,
RunCompileJvmPrepCommand,
RunTestJvmPrepCommand,
)
from pants.backend.jvm.tasks.scala_repl import ScalaRepl
from pants.backend.jvm.tasks.scaladoc_gen import ScaladocGen
from pants.backend.jvm.tasks.scalafix import ScalaFixCheck, ScalaFixFix
Expand Down
8 changes: 6 additions & 2 deletions src/python/pants/backend/jvm/targets/jvm_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
from pants.backend.jvm.targets.jvm_target import JvmTarget
from pants.base.exceptions import TargetDefinitionException
from pants.base.payload import Payload
from pants.base.payload_field import (ExcludesField, FingerprintedField, FingerprintedMixin,
PrimitiveField)
from pants.base.payload_field import (
ExcludesField,
FingerprintedField,
FingerprintedMixin,
PrimitiveField,
)
from pants.base.validation import assert_list
from pants.java.jar.exclude import Exclude

Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/jvm/tasks/coursier_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
from urllib import parse

from pants.backend.jvm.ivy_utils import IvyUtils
from pants.backend.jvm.subsystems.jar_dependency_management import (JarDependencyManagement,
PinnedJarArtifactSet)
from pants.backend.jvm.subsystems.jar_dependency_management import (
JarDependencyManagement,
PinnedJarArtifactSet,
)
from pants.backend.jvm.subsystems.resolve_subsystem import JvmResolveSubsystem
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.backend.jvm.targets.jvm_target import JvmTarget
Expand Down
28 changes: 20 additions & 8 deletions src/python/pants/backend/jvm/tasks/jvm_compile/jvm_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
from pants.backend.jvm.targets.javac_plugin import JavacPlugin
from pants.backend.jvm.targets.scalac_plugin import ScalacPlugin
from pants.backend.jvm.tasks.classpath_products import ClasspathEntry
from pants.backend.jvm.tasks.jvm_compile.class_not_found_error_patterns import \
CLASS_NOT_FOUND_ERROR_PATTERNS
from pants.backend.jvm.tasks.jvm_compile.class_not_found_error_patterns import (
CLASS_NOT_FOUND_ERROR_PATTERNS,
)
from pants.backend.jvm.tasks.jvm_compile.compile_context import CompileContext
from pants.backend.jvm.tasks.jvm_compile.execution_graph import (ExecutionFailure, ExecutionGraph,
Job)
from pants.backend.jvm.tasks.jvm_compile.missing_dependency_finder import (CompileErrorExtractor,
MissingDependencyFinder)
from pants.backend.jvm.tasks.jvm_compile.execution_graph import (
ExecutionFailure,
ExecutionGraph,
Job,
)
from pants.backend.jvm.tasks.jvm_compile.missing_dependency_finder import (
CompileErrorExtractor,
MissingDependencyFinder,
)
from pants.backend.jvm.tasks.jvm_dependency_analyzer import JvmDependencyAnalyzer
from pants.backend.jvm.tasks.nailgun_task import NailgunTaskBase
from pants.base.build_environment import get_buildroot
Expand All @@ -34,8 +40,14 @@
from pants.option.ranked_value import RankedValue
from pants.reporting.reporting_utils import items_to_report_element
from pants.util.contextutil import Timer, temporary_dir
from pants.util.dirutil import (fast_relpath, read_file, safe_delete, safe_file_dump, safe_mkdir,
safe_rmtree)
from pants.util.dirutil import (
fast_relpath,
read_file,
safe_delete,
safe_file_dump,
safe_mkdir,
safe_rmtree,
)
from pants.util.fileutil import create_size_estimators
from pants.util.memo import memoized_method, memoized_property

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
from pants.base.exceptions import TaskError
from pants.base.workunit import WorkUnitLabel
from pants.build_graph.mirrored_target_option_mixin import MirroredTargetOptionMixin
from pants.engine.fs import (EMPTY_DIRECTORY_DIGEST, DirectoryToMaterialize, PathGlobs,
PathGlobsAndRoot)
from pants.engine.fs import (
EMPTY_DIRECTORY_DIGEST,
DirectoryToMaterialize,
PathGlobs,
PathGlobsAndRoot,
)
from pants.engine.isolated_process import ExecuteProcessRequest, FallibleExecuteProcessResult
from pants.java.jar.jar_dependency import JarDependency
from pants.reporting.reporting_utils import items_to_report_element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
from pants.base.exceptions import TaskError
from pants.base.hash_utils import hash_file
from pants.base.workunit import WorkUnitLabel
from pants.engine.fs import (EMPTY_DIRECTORY_DIGEST, DirectoryToMaterialize, PathGlobs,
PathGlobsAndRoot)
from pants.engine.fs import (
EMPTY_DIRECTORY_DIGEST,
DirectoryToMaterialize,
PathGlobs,
PathGlobsAndRoot,
)
from pants.engine.isolated_process import ExecuteProcessRequest
from pants.util.contextutil import open_zip
from pants.util.dirutil import fast_relpath
Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/jvm/tasks/jvmdoc_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
from pants.backend.jvm.tasks.jvm_task import JvmTask
from pants.base.exceptions import TaskError
from pants.build_graph.target_scopes import Scopes
from pants.task.target_restriction_mixins import (HasSkipAndTransitiveOptionsMixin,
SkipAndTransitiveOptionsRegistrar)
from pants.task.target_restriction_mixins import (
HasSkipAndTransitiveOptionsMixin,
SkipAndTransitiveOptionsRegistrar,
)
from pants.util import desktop
from pants.util.dirutil import safe_mkdir, safe_walk
from pants.util.memo import memoized_property
Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/native/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from pants.backend.native.subsystems.native_build_settings import NativeBuildSettings
from pants.backend.native.subsystems.native_toolchain import create_native_toolchain_rules
from pants.backend.native.subsystems.xcode_cli_tools import create_xcode_cli_tools_rules
from pants.backend.native.targets.external_native_library import (ConanRequirement,
ExternalNativeLibrary)
from pants.backend.native.targets.external_native_library import (
ConanRequirement,
ExternalNativeLibrary,
)
from pants.backend.native.targets.native_artifact import NativeArtifact
from pants.backend.native.targets.native_library import CLibrary, CppLibrary
from pants.backend.native.targets.packaged_native_library import PackagedNativeLibrary
Expand Down
11 changes: 9 additions & 2 deletions src/python/pants/backend/native/subsystems/native_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).


from pants.backend.native.config.environment import (Assembler, CCompiler, CppCompiler,
CppToolchain, CToolchain, Linker, Platform)
from pants.backend.native.config.environment import (
Assembler,
CCompiler,
CppCompiler,
CppToolchain,
CToolchain,
Linker,
Platform,
)
from pants.backend.native.subsystems.binaries.binutils import Binutils
from pants.backend.native.subsystems.binaries.gcc import GCC
from pants.backend.native.subsystems.binaries.llvm import LLVM
Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/native/tasks/native_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from pants.backend.native.config.environment import CppToolchain, CToolchain
from pants.backend.native.subsystems.native_build_settings import NativeBuildSettings
from pants.backend.native.subsystems.native_build_step import NativeBuildStep
from pants.backend.native.subsystems.native_toolchain import (NativeToolchain,
ToolchainVariantRequest)
from pants.backend.native.subsystems.native_toolchain import (
NativeToolchain,
ToolchainVariantRequest,
)
from pants.backend.native.targets.native_library import NativeLibrary
from pants.backend.native.targets.packaged_native_library import PackagedNativeLibrary
from pants.build_graph.dependency_context import DependencyContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import textwrap
import unittest

from pants.backend.project_info.rules.source_file_validator import (Matcher, MultiMatcher,
RegexMatchResult)
from pants.backend.project_info.rules.source_file_validator import (
Matcher,
MultiMatcher,
RegexMatchResult,
)


# Note that some parts of these tests are just exercising various capabilities of the regex engine.
Expand Down
23 changes: 15 additions & 8 deletions src/python/pants/backend/python/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,34 @@
from pants.backend.python.python_artifact import PythonArtifact
from pants.backend.python.python_requirement import PythonRequirement
from pants.backend.python.python_requirements import PythonRequirements
from pants.backend.python.rules import (create_requirements_pex, download_pex_bin, inject_init,
python_test_runner)
from pants.backend.python.rules import (
create_requirements_pex,
download_pex_bin,
inject_init,
python_test_runner,
)
from pants.backend.python.subsystems.python_native_code import PythonNativeCode
from pants.backend.python.subsystems.python_native_code import rules as python_native_code_rules
from pants.backend.python.subsystems.subprocess_environment import SubprocessEnvironment
from pants.backend.python.subsystems.subprocess_environment import \
rules as subprocess_environment_rules
from pants.backend.python.subsystems.subprocess_environment import (
rules as subprocess_environment_rules,
)
from pants.backend.python.targets.python_app import PythonApp
from pants.backend.python.targets.python_binary import PythonBinary
from pants.backend.python.targets.python_distribution import PythonDistribution
from pants.backend.python.targets.python_library import PythonLibrary
from pants.backend.python.targets.python_requirement_library import PythonRequirementLibrary
from pants.backend.python.targets.python_tests import PythonTests
from pants.backend.python.targets.unpacked_whls import UnpackedWheels
from pants.backend.python.tasks.build_local_python_distributions import \
BuildLocalPythonDistributions
from pants.backend.python.tasks.build_local_python_distributions import (
BuildLocalPythonDistributions,
)
from pants.backend.python.tasks.gather_sources import GatherSources
from pants.backend.python.tasks.isort_prep import IsortPrep
from pants.backend.python.tasks.isort_run import IsortRun
from pants.backend.python.tasks.local_python_distribution_artifact import \
LocalPythonDistributionArtifact
from pants.backend.python.tasks.local_python_distribution_artifact import (
LocalPythonDistributionArtifact,
)
from pants.backend.python.tasks.pytest_prep import PytestPrep
from pants.backend.python.tasks.pytest_run import PytestRun
from pants.backend.python.tasks.python_binary_create import PythonBinaryCreate
Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/python/rules/python_test_runner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from pants.backend.python.rules.create_requirements_pex import (RequirementsPex,
RequirementsPexRequest)
from pants.backend.python.rules.create_requirements_pex import (
RequirementsPex,
RequirementsPexRequest,
)
from pants.backend.python.rules.inject_init import InjectedInitDigest
from pants.backend.python.subsystems.pytest import PyTest
from pants.backend.python.subsystems.python_setup import PythonSetup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from pants.backend.native.tasks.link_shared_libraries import SharedLibrary
from pants.backend.python.python_requirement import PythonRequirement
from pants.backend.python.subsystems.pex_build_util import is_local_python_dist
from pants.backend.python.subsystems.python_native_code import (BuildSetupRequiresPex,
PythonNativeCode)
from pants.backend.python.subsystems.python_native_code import (
BuildSetupRequiresPex,
PythonNativeCode,
)
from pants.backend.python.targets.python_requirement_library import PythonRequirementLibrary
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TargetDefinitionException, TaskError
Expand Down
7 changes: 5 additions & 2 deletions src/python/pants/backend/python/tasks/coverage/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from __future__ import absolute_import, division, print_function, unicode_literals

# NB: This file must keep Python 2 support because it is a resource that may be run with Python 2.

import json
import os

Expand All @@ -16,6 +14,11 @@
from coverage.python import PythonFileReporter


# NB: This file must keep Python 2 support because it is a resource that may be run with Python 2.




class SimpleFileTracer(FileTracer):
def __init__(self, filename):
super(SimpleFileTracer, self).__init__()
Expand Down
8 changes: 6 additions & 2 deletions src/python/pants/backend/python/tasks/gather_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
from pex.pex_builder import PEXBuilder
from twitter.common.collections import OrderedSet

from pants.backend.python.subsystems.pex_build_util import (PexBuilderWrapper, has_python_sources,
has_resources, is_python_target)
from pants.backend.python.subsystems.pex_build_util import (
PexBuilderWrapper,
has_python_sources,
has_resources,
is_python_target,
)
from pants.base.exceptions import TaskError
from pants.invalidation.cache_manager import VersionedTargetSet
from pants.task.task import Task
Expand Down
Loading

0 comments on commit 44d4ab5

Please sign in to comment.