Skip to content

Commit

Permalink
run ruff for real in entire codebase
Browse files Browse the repository at this point in the history
Signed-off-by: emdneto <[email protected]>
  • Loading branch information
emdneto committed Oct 14, 2024
1 parent 4d3e6ca commit c500ea7
Show file tree
Hide file tree
Showing 133 changed files with 303 additions and 559 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/generate_workflows.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pathlib import Path

from generate_workflows_lib import (
generate_test_workflow,
generate_lint_workflow,
generate_contrib_workflow,
generate_misc_workflow
generate_lint_workflow,
generate_misc_workflow,
generate_test_workflow,
)

tox_ini_path = Path(__file__).parent.parent.parent.joinpath("tox.ini")
Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,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 @@ -22,7 +22,6 @@
# 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
1 change: 0 additions & 1 deletion docs/examples/opentracing/rediscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def translate_to_collector(spans: Sequence[ReadableSpan]):

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

collector_annotation = trace_pb2.Span.TimeEvent.Annotation(
description=trace_pb2.TruncatableString(value=event.name)
)
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,51 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging

from opentelemetry.sdk.metrics.export import (
MetricExporter,
)
from opentelemetry.sdk.metrics.view import Aggregation
from os import environ
from opentelemetry.sdk.metrics import (
Counter,
Histogram,
ObservableCounter,
ObservableGauge,
ObservableUpDownCounter,
UpDownCounter,
)
from typing import Dict

from opentelemetry.exporter.otlp.proto.common._internal import (
_encode_attributes,
_encode_span_id,
_encode_trace_id,
)
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
)
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
)
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import (
ExportMetricsServiceRequest,
)
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope
from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2
from opentelemetry.sdk.metrics.export import (
MetricsData,
Gauge,
Histogram as HistogramType,
Sum,
ExponentialHistogram as ExponentialHistogramType,
)
from typing import Dict
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as PB2Resource,
)
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
)
from opentelemetry.sdk.metrics import (
Counter,
Histogram,
ObservableCounter,
ObservableGauge,
ObservableUpDownCounter,
UpDownCounter,
)
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
Gauge,
MetricExporter,
MetricsData,
Sum,
)
from opentelemetry.sdk.metrics.export import (
ExponentialHistogram as ExponentialHistogramType,
)
from opentelemetry.sdk.metrics.export import (
Histogram as HistogramType,
)
from opentelemetry.sdk.metrics.view import (
ExponentialBucketHistogramAggregation,
Aggregation,
ExplicitBucketHistogramAggregation,
ExponentialBucketHistogramAggregation,
)

_logger = logging.getLogger(__name__)
Expand All @@ -70,7 +68,6 @@ def _common_configuration(
preferred_temporality: Dict[type, AggregationTemporality] = None,
preferred_aggregation: Dict[type, Aggregation] = None,
) -> None:

MetricExporter.__init__(
self,
preferred_temporality=self._get_temporality(preferred_temporality),
Expand All @@ -80,7 +77,6 @@ def _common_configuration(
def _get_temporality(
self, preferred_temporality: Dict[type, AggregationTemporality]
) -> Dict[type, AggregationTemporality]:

otel_exporter_otlp_metrics_temporality_preference = (
environ.get(
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
Expand Down Expand Up @@ -137,7 +133,6 @@ def _get_aggregation(
self,
preferred_aggregation: Dict[type, Aggregation],
) -> Dict[type, Aggregation]:

otel_exporter_otlp_metrics_default_histogram_aggregation = environ.get(
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION,
"explicit_bucket_histogram",
Expand All @@ -146,17 +141,14 @@ def _get_aggregation(
if otel_exporter_otlp_metrics_default_histogram_aggregation == (
"base2_exponential_bucket_histogram"
):

instrument_class_aggregation = {
Histogram: ExponentialBucketHistogramAggregation(),
}

else:

if otel_exporter_otlp_metrics_default_histogram_aggregation != (
"explicit_bucket_histogram"
):

_logger.warning(
(
"Invalid value for %s: %s, using explicit bucket "
Expand Down Expand Up @@ -306,7 +298,6 @@ def _encode_metric(metric, pb2_metric):

elif isinstance(metric.data, ExponentialHistogramType):
for data_point in metric.data.data_points:

if data_point.positive.bucket_counts:
positive = pb2.ExponentialHistogramDataPoint.Buckets(
offset=data_point.positive.offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as OTLPResource,
)
from opentelemetry.sdk.metrics.export import AggregationTemporality, Buckets
from opentelemetry.sdk.metrics.export import (
ExponentialHistogram as ExponentialHistogramType,
)
from opentelemetry.sdk.metrics.export import ExponentialHistogramDataPoint
from opentelemetry.sdk.metrics.export import Histogram as HistogramType
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
Buckets,
ExponentialHistogramDataPoint,
HistogramDataPoint,
Metric,
MetricsData,
ResourceMetrics,
ScopeMetrics,
)
from opentelemetry.sdk.metrics.export import (
ExponentialHistogram as ExponentialHistogramType,
)
from opentelemetry.sdk.metrics.export import Histogram as HistogramType
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.util.instrumentation import (
InstrumentationScope as SDKInstrumentationScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
API
---
"""

from .version import __version__

_USER_AGENT_HEADER_VALUE = "OTel-OTLP-Exporter-Python/" + __version__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# limitations under the License.

from os import environ
from typing import Dict, Optional, Tuple, Union, Sequence
from typing import Dict, Optional, Sequence, Tuple, Union
from typing import Sequence as TypingSequence
from grpc import ChannelCredentials, Compression

from grpc import ChannelCredentials, Compression
from opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs
from opentelemetry.exporter.otlp.proto.grpc.exporter import (
OTLPExporterMixin,
Expand All @@ -28,10 +28,9 @@
from opentelemetry.proto.collector.logs.v1.logs_service_pb2_grpc import (
LogsServiceStub,
)
from opentelemetry.sdk._logs import LogRecord as SDKLogRecord
from opentelemetry.sdk._logs import LogData
from opentelemetry.sdk._logs import LogRecord as SDKLogRecord
from opentelemetry.sdk._logs.export import LogExporter, LogExportResult

from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE,
OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE,
Expand All @@ -48,7 +47,6 @@ class OTLPLogExporter(
LogExporter,
OTLPExporterMixin[SDKLogRecord, ExportLogsServiceRequest, LogExportResult],
):

_result = LogExportResult
_stub = LogsServiceStub

Expand Down
Loading

0 comments on commit c500ea7

Please sign in to comment.