Skip to content

Commit

Permalink
Upgraded black and isort (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
owais committed Apr 16, 2021
1 parent 371eaa8 commit 77c9867
Show file tree
Hide file tree
Showing 40 changed files with 215 additions and 90 deletions.
4 changes: 2 additions & 2 deletions dev-requirements.txt
@@ -1,7 +1,7 @@
pylint==2.6.0
flake8~=3.7
isort~=5.6
black>=19.3b0,==19.*
isort~=5.8
black~=20.8b1
httpretty~=1.0
mypy==0.812
sphinx~=2.1
Expand Down
25 changes: 20 additions & 5 deletions docs/conf.py
Expand Up @@ -101,12 +101,27 @@
# Even if wrapt is added to intersphinx_mapping, sphinx keeps failing
# with "class reference target not found: ObjectProxy".
("py:class", "ObjectProxy"),
("py:class", "opentelemetry.trace._LinkBase",),
(
"py:class",
"opentelemetry.trace._LinkBase",
),
# TODO: Understand why sphinx is not able to find this local class
("py:class", "opentelemetry.propagators.textmap.TextMapPropagator",),
("py:class", "opentelemetry.propagators.textmap.DefaultGetter",),
("any", "opentelemetry.propagators.textmap.TextMapPropagator.extract",),
("any", "opentelemetry.propagators.textmap.TextMapPropagator.inject",),
(
"py:class",
"opentelemetry.propagators.textmap.TextMapPropagator",
),
(
"py:class",
"opentelemetry.propagators.textmap.DefaultGetter",
),
(
"any",
"opentelemetry.propagators.textmap.TextMapPropagator.extract",
),
(
"any",
"opentelemetry.propagators.textmap.TextMapPropagator.inject",
),
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
5 changes: 4 additions & 1 deletion docs/examples/opentracing/main.py
Expand Up @@ -13,7 +13,10 @@
tracer_provider = trace.get_tracer_provider()

# Configure the tracer to export traces to Jaeger
jaeger_exporter = JaegerExporter(agent_host_name="localhost", agent_port=6831,)
jaeger_exporter = JaegerExporter(
agent_host_name="localhost",
agent_port=6831,
)
span_processor = SimpleSpanProcessor(jaeger_exporter)
tracer_provider.add_span_processor(span_processor)

Expand Down
5 changes: 4 additions & 1 deletion docs/getting_started/jaeger_example.py
Expand Up @@ -25,7 +25,10 @@
)
)

jaeger_exporter = JaegerExporter(agent_host_name="localhost", agent_port=6831,)
jaeger_exporter = JaegerExporter(
agent_host_name="localhost",
agent_port=6831,
)

trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(jaeger_exporter)
Expand Down
3 changes: 2 additions & 1 deletion docs/getting_started/tests/test_flask.py
Expand Up @@ -27,7 +27,8 @@ def test_flask(self):
dirpath = os.path.dirname(os.path.realpath(__file__))
server_script = "{}/../flask_example.py".format(dirpath)
server = subprocess.Popen(
[sys.executable, server_script], stdout=subprocess.PIPE,
[sys.executable, server_script],
stdout=subprocess.PIPE,
)
retry_strategy = Retry(total=10, backoff_factor=1)
adapter = HTTPAdapter(max_retries=retry_strategy)
Expand Down
Expand Up @@ -15,7 +15,8 @@
# `EXPORTER_JAEGER_CERTIFICATE` with file containing creds.

jaeger_exporter = grpc.JaegerExporter(
collector_endpoint="localhost:14250", insecure=True,
collector_endpoint="localhost:14250",
insecure=True,
)

# create a BatchSpanProcessor and add the exporter to it
Expand Down
Expand Up @@ -195,7 +195,8 @@ def _duration_from_two_time_stamps(
See https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#duration
"""
duration = Duration(
seconds=end.seconds - start.seconds, nanos=end.nanos - start.nanos,
seconds=end.seconds - start.seconds,
nanos=end.nanos - start.nanos,
)
# pylint: disable=chained-comparison
if duration.seconds < 0 and duration.nanos > 0:
Expand Down Expand Up @@ -350,7 +351,10 @@ def _extract_logs(
fields.append(tag)

fields.append(
_get_string_key_value(key="message", value=event.name,)
_get_string_key_value(
key="message",
value=event.name,
)
)
event_ts = _proto_timestamp_from_epoch_nanos(event.timestamp)
logs.append(model_pb2.Log(timestamp=event_ts, fields=fields))
Expand Down
Expand Up @@ -126,8 +126,8 @@ def test_translate_to_jaeger(self):

event_timestamp = base_time + 50 * 10 ** 6
# pylint:disable=protected-access
event_timestamp_proto = pb_translator._proto_timestamp_from_epoch_nanos(
event_timestamp
event_timestamp_proto = (
pb_translator._proto_timestamp_from_epoch_nanos(event_timestamp)
)

event = trace.Event(
Expand Down Expand Up @@ -339,7 +339,9 @@ def test_translate_to_jaeger(self):
duration=span2_duration,
flags=0,
tags=default_tags,
process=model_pb2.Process(service_name="svc",),
process=model_pb2.Process(
service_name="svc",
),
),
model_pb2.Span(
operation_name=span_names[2],
Expand Down Expand Up @@ -370,15 +372,18 @@ def test_translate_to_jaeger(self):
v_str="version",
),
],
process=model_pb2.Process(service_name="svc",),
process=model_pb2.Process(
service_name="svc",
),
),
]

# events are complicated to compare because order of fields
# (attributes) in otel is not important but in jeager it is
# pylint: disable=no-member
self.assertCountEqual(
spans[0].logs[0].fields, expected_spans[0].logs[0].fields,
spans[0].logs[0].fields,
expected_spans[0].logs[0].fields,
)

self.assertEqual(spans, expected_spans)
Expand Down
Expand Up @@ -258,7 +258,9 @@ def test_translate_to_jaeger(self):

default_tags = [
jaeger.Tag(
key="span.kind", vType=jaeger.TagType.STRING, vStr="internal",
key="span.kind",
vType=jaeger.TagType.STRING,
vStr="internal",
),
]

Expand Down Expand Up @@ -522,7 +524,8 @@ def test_agent_client(self):
spans = translate._translate(ThriftTranslator())

batch = jaeger.Batch(
spans=spans, process=jaeger.Process(serviceName="xxx"),
spans=spans,
process=jaeger.Process(serviceName="xxx"),
)

agent_client.emit(batch)
Expand Down
Expand Up @@ -46,7 +46,10 @@ class OpenCensusSpanExporter(SpanExporter):
"""

def __init__(
self, endpoint=DEFAULT_ENDPOINT, host_name=None, client=None,
self,
endpoint=DEFAULT_ENDPOINT,
host_name=None,
client=None,
):
tracer_provider = trace.get_tracer_provider()
service_name = (
Expand Down
Expand Up @@ -51,7 +51,9 @@ def test_constructor(self):
endpoint = "testEndpoint"
with patch:
exporter = OpenCensusSpanExporter(
host_name=host_name, endpoint=endpoint, client=client,
host_name=host_name,
endpoint=endpoint,
client=client,
)

self.assertIs(exporter.client, client)
Expand Down Expand Up @@ -154,7 +156,10 @@ def test_translate_to_collector(self):
otel_spans[0].end(end_time=end_times[0])
otel_spans[1].start(start_time=start_times[1])
otel_spans[1].set_status(
trace_api.Status(trace_api.StatusCode.ERROR, {"test", "val"},)
trace_api.Status(
trace_api.StatusCode.ERROR,
{"test", "val"},
)
)
otel_spans[1].end(end_time=end_times[1])
otel_spans[2].start(start_time=start_times[2])
Expand Down Expand Up @@ -194,7 +199,8 @@ def test_translate_to_collector(self):
output_spans[2].parent_span_id, b"\x11\x11\x11\x11\x11\x11\x11\x11"
)
self.assertEqual(
output_spans[0].status.code, trace_api.StatusCode.OK.value,
output_spans[0].status.code,
trace_api.StatusCode.OK.value,
)
self.assertEqual(len(output_spans[0].tracestate.entries), 1)
self.assertEqual(output_spans[0].tracestate.entries[0].key, "testkey")
Expand Down Expand Up @@ -264,7 +270,8 @@ def test_translate_to_collector(self):
trace_pb2.Span.Link.Type.TYPE_UNSPECIFIED,
)
self.assertEqual(
output_spans[1].status.code, trace_api.StatusCode.ERROR.value,
output_spans[1].status.code,
trace_api.StatusCode.ERROR.value,
)
self.assertEqual(
output_spans[2].links.link[0].type,
Expand Down
Expand Up @@ -241,10 +241,12 @@ def _translate_data(
sdk_resource_instrumentation_library_spans.keys()
):
if sdk_span.instrumentation_info is not None:
instrumentation_library_spans = InstrumentationLibrarySpans(
instrumentation_library=InstrumentationLibrary(
name=sdk_span.instrumentation_info.name,
version=sdk_span.instrumentation_info.version,
instrumentation_library_spans = (
InstrumentationLibrarySpans(
instrumentation_library=InstrumentationLibrary(
name=sdk_span.instrumentation_info.name,
version=sdk_span.instrumentation_info.version,
)
)
)

Expand Down
Expand Up @@ -27,7 +27,8 @@
def get_tracer_with_processor(span_processor_class):
span_processor = span_processor_class(OTLPSpanExporter())
tracer = TracerProvider(
active_span_processor=span_processor, sampler=sampling.DEFAULT_ON,
active_span_processor=span_processor,
sampler=sampling.DEFAULT_ON,
).get_tracer("pipeline_benchmark_tracer")
return tracer

Expand All @@ -45,7 +46,9 @@ def test_simple_span_processor(benchmark):
tracer = get_tracer_with_processor(SimpleSpanProcessor)

def create_spans_to_be_exported():
span = tracer.start_span("benchmarkedSpan",)
span = tracer.start_span(
"benchmarkedSpan",
)
for i in range(10):
span.set_attribute(
"benchmarkAttribute_{}".format(i),
Expand All @@ -71,7 +74,9 @@ def test_batch_span_processor(benchmark):
tracer = get_tracer_with_processor(BatchSpanProcessor)

def create_spans_to_be_exported():
span = tracer.start_span("benchmarkedSpan",)
span = tracer.start_span(
"benchmarkedSpan",
)
for i in range(10):
span.set_attribute(
"benchmarkAttribute_{}".format(i),
Expand Down
Expand Up @@ -42,6 +42,8 @@ def test_environ_to_compression(self):
),
Compression.Gzip,
)
self.assertIsNone(environ_to_compression("missing_key"),)
self.assertIsNone(
environ_to_compression("missing_key"),
)
with self.assertRaises(InvalidCompressionValueException):
environ_to_compression("test_invalid")
Expand Up @@ -271,7 +271,8 @@ def test_otlp_exporter_otlp_compression_unspecified(
# pylint: disable=no-self-use
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel")
@patch.dict(
"os.environ", {OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: "gzip"},
"os.environ",
{OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: "gzip"},
)
def test_otlp_exporter_otlp_compression_precendence(
self, mock_insecure_channel
Expand Down Expand Up @@ -455,10 +456,12 @@ def _check_translated_status(
)

self.assertEqual(
status.code, code_expected,
status.code,
code_expected,
)
self.assertEqual(
status.deprecated_code, deprecated_code_expected,
status.deprecated_code,
deprecated_code_expected,
)

def test_span_status_translate(self):
Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-api/setup.py
Expand Up @@ -22,4 +22,6 @@
with open(VERSION_FILENAME) as f:
exec(f.read(), PACKAGE_INFO)

setuptools.setup(version=PACKAGE_INFO["__version__"],)
setuptools.setup(
version=PACKAGE_INFO["__version__"],
)
7 changes: 5 additions & 2 deletions opentelemetry-api/src/opentelemetry/propagate/__init__.py
Expand Up @@ -127,7 +127,8 @@ def inject(

# Single use variable here to hack black and make lint pass
environ_propagators = environ.get(
OTEL_PROPAGATORS, "tracecontext,baggage",
OTEL_PROPAGATORS,
"tracecontext,baggage",
)

for propagator in environ_propagators.split(","):
Expand All @@ -148,6 +149,8 @@ def get_global_textmap() -> textmap.TextMapPropagator:
return _HTTP_TEXT_FORMAT


def set_global_textmap(http_text_format: textmap.TextMapPropagator,) -> None:
def set_global_textmap(
http_text_format: textmap.TextMapPropagator,
) -> None:
global _HTTP_TEXT_FORMAT # pylint:disable=global-statement
_HTTP_TEXT_FORMAT = http_text_format # type: ignore
8 changes: 4 additions & 4 deletions opentelemetry-api/src/opentelemetry/trace/__init__.py
Expand Up @@ -134,7 +134,9 @@ class Link(_LinkBase):
"""

def __init__(
self, context: "SpanContext", attributes: types.Attributes = None,
self,
context: "SpanContext",
attributes: types.Attributes = None,
) -> None:
super().__init__(context)
self._attributes = attributes
Expand Down Expand Up @@ -393,9 +395,7 @@ def _tracer(self) -> Tracer:
def start_span(self, *args, **kwargs) -> Span: # type: ignore
return self._tracer.start_span(*args, **kwargs) # type: ignore

def start_as_current_span( # type: ignore
self, *args, **kwargs
) -> Span:
def start_as_current_span(self, *args, **kwargs) -> Span: # type: ignore
return self._tracer.start_as_current_span(*args, **kwargs) # type: ignore


Expand Down
5 changes: 4 additions & 1 deletion opentelemetry-api/src/opentelemetry/util/_providers.py
Expand Up @@ -42,7 +42,10 @@ def _load_provider(
),
)
)
return cast(Provider, entry_point.load()(),)
return cast(
Provider,
entry_point.load()(),
)
except Exception: # pylint: disable=broad-except
logger.error("Failed to load configured provider %s", provider)
raise
3 changes: 2 additions & 1 deletion opentelemetry-api/tests/baggage/test_baggage.py
Expand Up @@ -41,7 +41,8 @@ def test_set_multiple_baggage_entries(self):
self.assertEqual(baggage.get_baggage("test", context=ctx), "value")
self.assertEqual(baggage.get_baggage("test2", context=ctx), "value2")
self.assertEqual(
baggage.get_all(context=ctx), {"test": "value", "test2": "value2"},
baggage.get_all(context=ctx),
{"test": "value", "test2": "value2"},
)

def test_modifying_baggage(self):
Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-api/tests/context/test_contextvars_context.py
Expand Up @@ -33,7 +33,9 @@ class TestContextVarsContext(ContextTestCases.BaseTest):
def setUp(self) -> None:
super(TestContextVarsContext, self).setUp()
self.mock_runtime = patch.object(
context, "_RUNTIME_CONTEXT", ContextVarsRuntimeContext(),
context,
"_RUNTIME_CONTEXT",
ContextVarsRuntimeContext(),
)
self.mock_runtime.start()

Expand Down

0 comments on commit 77c9867

Please sign in to comment.