Skip to content

Commit

Permalink
Upgrade isort and enable black compat mode
Browse files Browse the repository at this point in the history
isort and black can be incompatible. Often isort re-writes files in a
way black doesn't like. It takes quite some time and manual effort to
make changes that satisfy both isort and black.

Fortunately, newer versions of isort support a black compatibility mode by setting
isort profile to "black". This makes isort order imports in a way that
is compatible with how black formats Python code. This PR configures
isort to use the black profile by default.
  • Loading branch information
owais committed Dec 11, 2020
1 parent 3bbc547 commit a0d478c
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=79
profile=black

; 3 stands for Vertical Hanging Indent, e.g.
; from third_party import (
Expand All @@ -13,6 +14,6 @@ line_length=79
; docs: https://github.com/timothycrosley/isort#multi-line-output-modes
multi_line_output=3
skip=target
skip_glob=**/gen/*,.venv*/*,venv*/*,**/proto/*,opentelemetry-python-contrib/*
skip_glob=**/gen/*,.venv*/*,venv*/*,**/proto/*,opentelemetry-python-contrib/*,.tox/*
known_first_party=opentelemetry,opentelemetry_example_app
known_third_party=psutil,pytest,redis,redis_opentracing
6 changes: 5 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ disable=missing-docstring,
wrong-import-order, # Leave this up to isort
bad-continuation, # Leave this up to black
line-too-long, # Leave this up to black
exec-used
exec-used,
super-with-arguments, # temp-pylint-upgrade
isinstance-second-argument-not-valid-type, # temp-pylint-upgrade
raise-missing-from, # temp-pylint-upgrade
unused-argument, # temp-pylint-upgrade

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
5 changes: 3 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pylint==2.4.4
pylint==2.6.0
flake8~=3.7
isort~=4.3
isort~=5.6
black>=19.3b0,==19.*
httpretty~=1.0
mypy==0.790
sphinx~=2.1
sphinx-rtd-theme~=0.4
Expand Down
1 change: 1 addition & 0 deletions docs/examples/django/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.http import HttpResponse

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/opentracing/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python

from rediscache import RedisCache

from opentelemetry import trace
from opentelemetry.exporter.jaeger import JaegerSpanExporter
from opentelemetry.instrumentation import opentracing_shim
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
from rediscache import RedisCache

# Configure the tracer using the default implementation
trace.set_tracer_provider(TracerProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def _get_resource_data(

def _load_credential_from_file(filepath) -> ChannelCredentials:
try:
with open(filepath, "rb") as f:
credential = f.read()
with open(filepath, "rb") as creds_file:
credential = creds_file.read()
return ssl_channel_credentials(credential)
except FileNotFoundError:
logger.exception("Failed to read credential file")
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/src/opentelemetry/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from opentelemetry.configuration import Configuration

if TYPE_CHECKING:
from opentelemetry.trace import TracerProvider
from opentelemetry.metrics import MeterProvider
from opentelemetry.trace import TracerProvider

Provider = Union["TracerProvider", "MeterProvider"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

try:
import contextvars # pylint: disable=unused-import

from opentelemetry.context.contextvars_context import (
ContextVarsRuntimeContext,
)
Expand Down
6 changes: 2 additions & 4 deletions opentelemetry-sdk/src/opentelemetry/sdk/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

try:
# pylint: disable=ungrouped-imports
from collections.abc import MutableMapping
from collections.abc import Sequence
from collections.abc import MutableMapping, Sequence
except ImportError:
# pylint: disable=no-name-in-module,ungrouped-imports
from collections import MutableMapping
from collections import Sequence
from collections import MutableMapping, Sequence


def ns_to_iso_str(nanoseconds):
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-sdk/tests/context/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

try:
import contextvars # pylint: disable=unused-import

from opentelemetry.context.contextvars_context import (
ContextVarsRuntimeContext,
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/eachdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def lint_args(args):
)
runsubprocess(
args.dry_run,
("isort", "--recursive", ".")
("isort", ".")
+ (("--diff", "--check-only") if args.check_only else ()),
cwd=rootdir,
check=True,
Expand Down

0 comments on commit a0d478c

Please sign in to comment.