Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate formatting and linting to ruff #3816

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .flake8

This file was deleted.

19 changes: 0 additions & 19 deletions .isort.cfg

This file was deleted.

1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ asgiref==3.7.2
psutil==5.9.6
GitPython==3.1.41
flaky==3.7.0
ruff==0.3.4
aabmass marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 2 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# -- Project information -----------------------------------------------------

project = "OpenTelemetry Python"
copyright = "OpenTelemetry Authors" # pylint: disable=redefined-builtin
copyright = "OpenTelemetry Authors"
author = "OpenTelemetry Authors"


Expand Down Expand Up @@ -169,9 +169,7 @@
.. |SCM_WEB| replace:: {s}
.. |SCM_RAW_WEB| replace:: {sr}
.. |SCM_BRANCH| replace:: {b}
""".format(
s=scm_web, sr=scm_raw_web, b=branch
)
""".format(s=scm_web, sr=scm_raw_web, b=branch)

# used to have links to repo files
extlinks = {
Expand Down
1 change: 0 additions & 1 deletion docs/examples/auto-instrumentation/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
assert len(argv) == 2

with tracer.start_as_current_span("client"):

with tracer.start_as_current_span("client-server"):
headers = {}
inject(headers)
Expand Down
1 change: 0 additions & 1 deletion docs/examples/django/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@


with tracer.start_as_current_span("client"):

with tracer.start_as_current_span("client-server"):
headers = {}
inject(headers)
Expand Down
1 change: 1 addition & 0 deletions docs/examples/django/instrumentation_example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path("blog/", include("blog.urls"))
"""

from django.contrib import admin
from django.urls import include, path

Expand Down
1 change: 1 addition & 0 deletions docs/examples/django/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

"""Django"s command-line utility for administrative tasks."""

import os
import sys

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@

class ErrorHandler0(ErrorHandler, ZeroDivisionError):
def _handle(self, error: Exception, *args, **kwargs):

logger.exception("ErrorHandler0 handling a ZeroDivisionError")
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
logger = getLogger(__name__)


# pylint: disable=too-many-ancestors
class ErrorHandler1(ErrorHandler, IndexError, KeyError):
def _handle(self, error: Exception, *args, **kwargs):

if isinstance(error, IndexError):
logger.exception("ErrorHandler1 handling an IndexError")

Expand Down
10 changes: 6 additions & 4 deletions docs/examples/opentracing/rediscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# FIXME The pylint disablings are needed here because the code of this
# example is being executed against the tox.ini of the main
# opentelemetry-python project. Find a way to separate the two.
import redis # pylint: disable=import-error
import redis_opentracing # pylint: disable=import-error
import redis
import redis_opentracing


class RedisCache:
Expand All @@ -30,7 +30,6 @@ def __call__(self, func):
@wraps(func)
def inner(*args, **kwargs):
with self.tracer.start_active_span("Caching decorator") as scope1:

# Pickle the call args to get a canonical key. Don't do this in
# prod!
key = pickle.dumps((func.__qualname__, args, kwargs))
Expand All @@ -39,7 +38,10 @@ def inner(*args, **kwargs):
if pval is not None:
val = pickle.loads(pval)
scope1.span.log_kv(
{"msg": "Found cached value", "val": val}
{
"msg": "Found cached value",
"val": val,
}
)
return val

Expand Down
5 changes: 4 additions & 1 deletion docs/getting_started/tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def test_basic_tracer(self):
dirpath = os.path.dirname(os.path.realpath(__file__))
test_script = f"{dirpath}/../tracing_example.py"
output = subprocess.check_output(
(sys.executable, test_script)
(
sys.executable,
test_script,
)
).decode()

self.assertIn('"name": "foo"', output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
from typing import Sequence

import grpc

import opentelemetry.exporter.opencensus.util as utils
from opencensus.proto.agent.trace.v1 import (
trace_service_pb2,
trace_service_pb2_grpc,
)
from opencensus.proto.trace.v1 import trace_pb2

import opentelemetry.exporter.opencensus.util as utils
from opentelemetry import trace
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import ReadableSpan
Expand All @@ -35,7 +35,6 @@
logger = logging.getLogger(__name__)


# pylint: disable=no-member
class OpenCensusSpanExporter(SpanExporter):
"""OpenCensus Collector span exporter.

Expand Down Expand Up @@ -105,8 +104,7 @@ def force_flush(self, timeout_millis: int = 30000) -> bool:
return True


# pylint: disable=too-many-branches
def translate_to_collector(spans: Sequence[ReadableSpan]):
def translate_to_collector(spans: Sequence[ReadableSpan]): # noqa: PLR0912
collector_spans = []
for span in spans:
status = None
Expand All @@ -133,24 +131,23 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
collector_span.parent_span_id = parent_id.to_bytes(8, "big")

if span.context.trace_state is not None:
for (key, value) in span.context.trace_state.items():
for key, value in span.context.trace_state.items():
collector_span.tracestate.entries.add(key=key, value=value)

if span.attributes:
for (key, value) in span.attributes.items():
for key, value in span.attributes.items():
utils.add_proto_attribute_value(
collector_span.attributes, key, value
)

if span.events:
for event in span.events:

collector_annotation = trace_pb2.Span.TimeEvent.Annotation(
description=trace_pb2.TruncatableString(value=event.name)
)

if event.attributes:
for (key, value) in event.attributes.items():
for key, value in event.attributes.items():
utils.add_proto_attribute_value(
collector_annotation.attributes, key, value
)
Expand Down Expand Up @@ -183,7 +180,7 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):
)

if link.attributes:
for (key, value) in link.attributes.items():
for key, value in link.attributes.items():
utils.add_proto_attribute_value(
collector_span_link.attributes, key, value
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
from socket import gethostname
from time import time

# pylint: disable=wrong-import-position
from google.protobuf.timestamp_pb2 import Timestamp

from opencensus.proto.agent.common.v1 import common_pb2
from opencensus.proto.trace.v1 import trace_pb2

from opentelemetry.exporter.opencensus.version import (
__version__ as opencensusexporter_exporter_version,
)
Expand All @@ -41,12 +40,10 @@ def proto_timestamp_from_time_ns(time_ns):
"""
ts = Timestamp()
if time_ns is not None:
# pylint: disable=no-member
ts.FromNanoseconds(time_ns)
return ts


# pylint: disable=no-member
def get_collector_span_kind(kind: SpanKind):
if kind is SpanKind.SERVER:
return trace_pb2.Span.SpanKind.SERVER
Expand Down Expand Up @@ -77,7 +74,6 @@ def add_proto_attribute_value(pb_attributes, key, value):
pb_attributes.attribute_map[key].string_value.value = str(value)


# pylint: disable=no-member
def get_node(service_name, host_name):
"""Generates Node message from params and system information.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from opentelemetry.trace import TraceFlags


# pylint: disable=no-member
class TestCollectorSpanExporter(TraceGlobalsTest, unittest.TestCase):
def test_constructor(self):
mock_get_node = mock.Mock()
Expand Down Expand Up @@ -78,9 +77,7 @@ def test_proto_timestamp_from_time_ns(self):
self.assertIsInstance(result, Timestamp)
self.assertEqual(result.nanos, 12345)

# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
def test_translate_to_collector(self):
def test_translate_to_collector(self): # noqa: PLR0915
trace_id = 0x6E0C63257DE34C926F9EFCD03927272E
span_id = 0x34BF92DEEFC58C92
parent_id = 0x1111111111111111
Expand Down Expand Up @@ -313,7 +310,6 @@ def test_export(self):
result_status = collector_exporter.export(otel_spans)
self.assertEqual(SpanExportResult.SUCCESS, result_status)

# pylint: disable=unsubscriptable-object
export_arg = mock_export.call_args[0]
service_request = next(export_arg[0])
output_spans = getattr(service_request, "spans")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@
from itertools import count
from typing import (
Any,
Mapping,
Optional,
List,
Callable,
TypeVar,
Dict,
Iterator,
List,
Mapping,
Optional,
TypeVar,
)

from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.proto.common.v1.common_pb2 import AnyValue as PB2AnyValue
from opentelemetry.proto.common.v1.common_pb2 import (
InstrumentationScope as PB2InstrumentationScope,
ArrayValue as PB2ArrayValue,
)
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as PB2Resource,
from opentelemetry.proto.common.v1.common_pb2 import (
InstrumentationScope as PB2InstrumentationScope,
)
from opentelemetry.proto.common.v1.common_pb2 import AnyValue as PB2AnyValue
from opentelemetry.proto.common.v1.common_pb2 import KeyValue as PB2KeyValue
from opentelemetry.proto.common.v1.common_pb2 import (
KeyValueList as PB2KeyValueList,
)
from opentelemetry.proto.common.v1.common_pb2 import (
ArrayValue as PB2ArrayValue,
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as PB2Resource,
)
from opentelemetry.sdk.trace import Resource
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.util.types import Attributes

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -108,7 +108,7 @@ def _encode_attributes(
for key, value in attributes.items():
try:
pb2_attributes.append(_encode_key_value(key, value))
except Exception as error: # pylint: disable=broad-except
except Exception as error:
_logger.exception(error)
else:
pb2_attributes = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from collections import defaultdict
from typing import Sequence, List
from typing import List, Sequence

from opentelemetry.exporter.otlp.proto.common._internal import (
_encode_attributes,
_encode_instrumentation_scope,
_encode_resource,
_encode_span_id,
_encode_trace_id,
_encode_value,
_encode_attributes,
)
from opentelemetry.proto.collector.logs.v1.logs_service_pb2 import (
ExportLogsServiceRequest,
)
from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord
from opentelemetry.proto.logs.v1.logs_pb2 import (
ScopeLogs,
ResourceLogs,
ScopeLogs,
)
from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord

from opentelemetry.sdk._logs import LogData


Expand Down
Loading
Loading