From 08bc416b2d82f132b2ace233aa8e48feeeba754a Mon Sep 17 00:00:00 2001 From: dinesh Date: Fri, 4 Oct 2019 20:28:24 +0400 Subject: [PATCH] added isort support --- .isort.cfg | 17 ++++++++++ .../opencensus-context/examples/async_span.py | 1 + .../examples/explicit_threading.py | 1 + .../examples/thread_pool.py | 5 +-- context/opencensus-context/setup.py | 4 +-- .../tests/test_runtime_context.py | 1 + .../common/correlationcontext/__init__.py | 6 ++-- contrib/opencensus-correlation/setup.py | 4 +-- .../tests/test_correlation_context.py | 1 + .../examples/metrics/standard.py | 2 +- .../examples/traces/client.py | 1 - .../examples/traces/server.py | 3 +- .../opencensus/ext/azure/common/exporter.py | 3 +- .../opencensus/ext/azure/common/storage.py | 2 +- .../opencensus/ext/azure/common/transport.py | 1 + .../opencensus/ext/azure/common/utils.py | 8 ++--- .../ext/azure/log_exporter/__init__.py | 17 +++++----- .../ext/azure/metrics_exporter/__init__.py | 15 ++++----- .../standard_metrics/__init__.py | 31 ++++++++++--------- .../metrics_exporter/standard_metrics/cpu.py | 1 - .../standard_metrics/http_dependency.py | 2 +- .../standard_metrics/http_requests.py | 1 + .../standard_metrics/memory.py | 1 - .../standard_metrics/process.py | 8 +++-- .../ext/azure/trace_exporter/__init__.py | 13 ++++---- contrib/opencensus-ext-azure/setup.py | 4 +-- .../tests/test_azure_log_exporter.py | 3 +- .../tests/test_azure_metrics_exporter.py | 21 +++++++------ .../tests/test_azure_standard_metrics.py | 6 ++-- .../tests/test_azure_trace_exporter.py | 3 +- .../tests/test_azure_utils.py | 1 + .../tests/test_protocol.py | 1 + .../tests/test_storage.py | 13 +++++--- .../examples/datadog.py | 4 +-- .../opencensus/ext/datadog/traces.py | 4 +-- .../opencensus/ext/datadog/transport.py | 1 + contrib/opencensus-ext-datadog/setup.py | 4 +-- .../tests/traces_test.py | 16 ++++++---- contrib/opencensus-ext-dbapi/setup.py | 4 +-- .../examples/app/urls.py | 4 +-- .../examples/app/views.py | 15 +++++---- .../opencensus/ext/django/middleware.py | 19 +++++++----- contrib/opencensus-ext-django/setup.py | 4 +-- .../tests/test_django_db_middleware.py | 4 +-- .../tests/test_django_middleware.py | 8 ++--- .../opencensus-ext-flask/examples/custom.py | 13 ++++---- .../opencensus/ext/flask/flask_middleware.py | 18 ++++++----- contrib/opencensus-ext-flask/setup.py | 4 +-- .../tests/test_flask_middleware.py | 17 ++++------ .../ext/gevent/geventcompatibility.py | 1 + contrib/opencensus-ext-gevent/setup.py | 4 +-- .../tests/test_patching.py | 6 ++-- .../ext/google_cloud_clientlibs/trace.py | 12 +++---- .../setup.py | 4 +-- .../test_google_cloud_clientlibs_trace.py | 2 +- .../examples/hello_world_client.py | 4 +-- .../examples/hello_world_pb2.py | 6 ++-- .../examples/hello_world_pb2_grpc.py | 1 - .../examples/hello_world_server.py | 4 +-- .../opencensus/ext/grpc/client_interceptor.py | 7 ++--- .../opencensus/ext/grpc/server_interceptor.py | 8 ++--- .../opencensus/ext/grpc/utils.py | 3 +- contrib/opencensus-ext-grpc/setup.py | 4 +-- .../tests/test_client_interceptor.py | 6 ++-- .../opencensus/ext/httplib/trace.py | 3 +- contrib/opencensus-ext-httplib/setup.py | 4 +-- .../ext/jaeger/trace_exporter/__init__.py | 5 ++- .../jaeger/trace_exporter/gen/jaeger/agent.py | 10 ++++-- .../trace_exporter/gen/jaeger/jaeger.py | 13 +++++--- contrib/opencensus-ext-jaeger/setup.py | 4 +-- .../tests/test_jaeger_exporter.py | 10 ++++-- contrib/opencensus-ext-logging/setup.py | 4 +-- .../opencensus/ext/mysql/trace.py | 2 +- contrib/opencensus-ext-mysql/setup.py | 4 +-- .../ext/ocagent/stats_exporter/__init__.py | 12 ++++--- .../ext/ocagent/trace_exporter/__init__.py | 8 +++-- .../ext/ocagent/trace_exporter/utils.py | 1 + .../opencensus/ext/ocagent/utils/__init__.py | 1 + contrib/opencensus-ext-ocagent/setup.py | 4 +-- .../tests/test_ocagent_utils.py | 2 +- .../tests/test_stats_exporter.py | 30 ++++++++++-------- .../tests/test_trace_exporter.py | 6 ++-- .../tests/test_trace_exporter_utils.py | 3 +- .../opencensus/ext/postgresql/trace.py | 6 ++-- contrib/opencensus-ext-postgresql/setup.py | 4 +-- .../examples/prometheus.py | 2 +- .../ext/prometheus/stats_exporter/__init__.py | 19 ++++++------ contrib/opencensus-ext-prometheus/setup.py | 4 +-- .../tests/test_prometheus_stats.py | 6 ++-- .../opencensus/ext/pymongo/trace.py | 4 +-- contrib/opencensus-ext-pymongo/setup.py | 4 +-- .../opencensus/ext/pymysql/trace.py | 1 + contrib/opencensus-ext-pymysql/setup.py | 4 +-- .../examples/app/__init__.py | 1 - .../opencensus-ext-pyramid/examples/simple.py | 6 +--- .../opencensus/ext/pyramid/config.py | 3 +- .../ext/pyramid/pyramid_middleware.py | 3 +- contrib/opencensus-ext-pyramid/setup.py | 4 +-- .../tests/test_pyramid_config.py | 3 +- .../tests/test_pyramid_middleware.py | 10 +++--- .../opencensus/ext/requests/trace.py | 14 ++++++--- contrib/opencensus-ext-requests/setup.py | 4 +-- .../tests/test_requests_trace.py | 7 +++-- .../opencensus/ext/sqlalchemy/trace.py | 4 +-- contrib/opencensus-ext-sqlalchemy/setup.py | 4 +-- .../tests/test_sqlalchemy_trace.py | 2 +- .../stackdriver/stats_exporter/__init__.py | 19 ++++++------ .../stackdriver/trace_exporter/__init__.py | 17 +++++----- contrib/opencensus-ext-stackdriver/setup.py | 4 +-- .../tests/test_stackdriver_stats.py | 21 +++++++------ .../opencensus/ext/threading/trace.py | 5 ++- contrib/opencensus-ext-threading/setup.py | 4 +-- .../tests/test_threading_trace.py | 7 +++-- .../ext/zipkin/trace_exporter/__init__.py | 4 +-- contrib/opencensus-ext-zipkin/setup.py | 4 +-- .../tests/test_zipkin_exporter.py | 3 +- examples/stats/helloworld/main.py | 2 +- examples/trace/helloworld/main.py | 4 +-- noxfile.py | 3 +- opencensus/common/backports/__init__.py | 1 + .../aws_identity_doc_utils.py | 3 +- .../monitored_resource/monitored_resource.py | 9 +++--- opencensus/common/resource/__init__.py | 3 +- opencensus/common/schedule/__init__.py | 4 +-- opencensus/common/transports/async_.py | 5 ++- opencensus/log/__init__.py | 3 +- opencensus/metrics/export/cumulative.py | 3 +- opencensus/metrics/export/gauge.py | 13 +++++--- opencensus/metrics/transport.py | 1 - opencensus/stats/aggregation.py | 3 +- opencensus/stats/aggregation_data.py | 4 +-- opencensus/stats/measure_to_view_map.py | 2 +- opencensus/stats/measurement_map.py | 1 - opencensus/stats/metric_utils.py | 4 +-- opencensus/stats/stats_recorder.py | 4 +-- opencensus/stats/view_manager.py | 2 +- opencensus/tags/__init__.py | 2 +- .../tags/propagation/binary_serializer.py | 3 +- opencensus/tags/tag.py | 1 + opencensus/trace/__init__.py | 1 - opencensus/trace/exceptions_status.py | 1 + opencensus/trace/file_exporter.py | 3 +- opencensus/trace/logging_exporter.py | 3 +- opencensus/trace/propagation/b3_format.py | 2 +- .../trace_context_http_header_format.py | 5 +-- .../propagation/tracestate_string_format.py | 5 ++- opencensus/trace/span.py | 6 ++-- opencensus/trace/span_context.py | 5 +-- opencensus/trace/tracer.py | 7 ++--- opencensus/trace/tracers/context_tracer.py | 5 ++- opencensus/trace/tracers/noop_tracer.py | 4 +-- opencensus/trace/tracestate.py | 2 +- opencensus/trace/utils.py | 1 + setup.py | 3 +- .../stackdriver/stackdriver_stats_test.py | 2 +- tests/system/trace/django/app/urls.py | 4 +-- tests/system/trace/django/app/views.py | 15 +++++---- .../system/trace/django/django_system_test.py | 5 ++- tests/system/trace/flask/flask_system_test.py | 5 ++- tests/system/trace/flask/main.py | 4 +-- .../test_aws_identity_doc_utils.py | 3 +- .../test_gcp_metadata_config.py | 3 +- .../test_monitored_resource.py | 2 +- tests/unit/common/test_http_handler.py | 5 +-- tests/unit/common/test_schedule.py | 4 +-- tests/unit/common/test_utils.py | 3 +- tests/unit/common/transports/test_sync.py | 2 ++ tests/unit/log/test_log.py | 2 +- tests/unit/metrics/export/test_cumulative.py | 4 +-- tests/unit/metrics/export/test_gauge.py | 3 +- tests/unit/metrics/export/test_metric.py | 4 +-- .../metrics/export/test_metric_descriptor.py | 3 +- tests/unit/metrics/export/test_point.py | 1 + tests/unit/metrics/export/test_summary.py | 1 + tests/unit/metrics/export/test_time_series.py | 4 +-- tests/unit/metrics/test_label_key.py | 1 + tests/unit/metrics/test_label_value.py | 1 + tests/unit/stats/test_aggregation.py | 5 +-- tests/unit/stats/test_aggregation_data.py | 2 +- tests/unit/stats/test_base_stats.py | 2 ++ tests/unit/stats/test_measure_to_view_map.py | 4 +-- tests/unit/stats/test_measurement.py | 4 +-- tests/unit/stats/test_measurement_map.py | 7 ++--- tests/unit/stats/test_metric_utils.py | 21 ++++++------- tests/unit/stats/test_stats.py | 6 ++-- tests/unit/stats/test_stats_recorder.py | 4 ++- tests/unit/stats/test_view.py | 5 ++- tests/unit/stats/test_view_data.py | 5 +-- tests/unit/stats/test_view_manager.py | 4 ++- tests/unit/tags/test_tag.py | 1 + tests/unit/tags/test_tag_value.py | 1 + .../trace/exporters/test_logging_exporter.py | 3 +- .../unit/trace/propagation/test_b3_format.py | 3 +- tests/unit/trace/test_base_span.py | 2 ++ tests/unit/trace/test_blank_span.py | 5 +-- tests/unit/trace/test_exceptions_status.py | 1 + tests/unit/trace/test_execution_context.py | 3 +- tests/unit/trace/test_ext_utils.py | 2 +- tests/unit/trace/test_span.py | 9 ++---- tests/unit/trace/test_span_context.py | 1 + tests/unit/trace/test_span_data.py | 7 ++--- tests/unit/trace/test_time_event.py | 2 +- tests/unit/trace/test_tracer.py | 3 +- tests/unit/trace/test_tracestate.py | 5 +-- .../unit/trace/tracers/test_context_tracer.py | 3 +- tox.ini | 2 ++ 206 files changed, 552 insertions(+), 529 deletions(-) create mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 000000000..b608ac6d2 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,17 @@ +[settings] +include_trailing_comma=True +force_grid_wrap=0 +use_parentheses=True +line_length=79 + +; 3 stands for Vertical Hanging Indent, e.g. +; from third_party import ( +; lib1, +; lib2, +; lib3, +; ) +; docs: https://github.com/timothycrosley/isort#multi-line-output-modes +multi_line_output=3 +known_future_library = six,six.moves,__future__ +known_third_party=google,mock,pymysql,sqlalchemy,psycopg2 +known_first_party=opencensus diff --git a/context/opencensus-context/examples/async_span.py b/context/opencensus-context/examples/async_span.py index a91460689..3abcc0db2 100644 --- a/context/opencensus-context/examples/async_span.py +++ b/context/opencensus-context/examples/async_span.py @@ -13,6 +13,7 @@ # limitations under the License. import asyncio + from opencensus.common.runtime_context import RuntimeContext RuntimeContext.register_slot('current_span', None) diff --git a/context/opencensus-context/examples/explicit_threading.py b/context/opencensus-context/examples/explicit_threading.py index ad6af8841..aad6a48c3 100644 --- a/context/opencensus-context/examples/explicit_threading.py +++ b/context/opencensus-context/examples/explicit_threading.py @@ -13,6 +13,7 @@ # limitations under the License. from threading import Thread + from opencensus.common.runtime_context import RuntimeContext RuntimeContext.register_slot('operation_id', '') diff --git a/context/opencensus-context/examples/thread_pool.py b/context/opencensus-context/examples/thread_pool.py index c36d5a304..0f06ea785 100644 --- a/context/opencensus-context/examples/thread_pool.py +++ b/context/opencensus-context/examples/thread_pool.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from multiprocessing.dummy import Pool as ThreadPool -import time import threading +import time +from multiprocessing.dummy import Pool as ThreadPool + from opencensus.common.runtime_context import RuntimeContext RuntimeContext.register_slot('operation_id', '') diff --git a/context/opencensus-context/setup.py b/context/opencensus-context/setup.py index 1397ed4fe..0746bd3e2 100644 --- a/context/opencensus-context/setup.py +++ b/context/opencensus-context/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/context/opencensus-context/tests/test_runtime_context.py b/context/opencensus-context/tests/test_runtime_context.py index 795a165a5..2f26d7b21 100644 --- a/context/opencensus-context/tests/test_runtime_context.py +++ b/context/opencensus-context/tests/test_runtime_context.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest + from opencensus.common.runtime_context import RuntimeContext diff --git a/contrib/opencensus-correlation/opencensus/common/correlationcontext/__init__.py b/contrib/opencensus-correlation/opencensus/common/correlationcontext/__init__.py index 145a780e0..053ce3981 100644 --- a/contrib/opencensus-correlation/opencensus/common/correlationcontext/__init__.py +++ b/contrib/opencensus-correlation/opencensus/common/correlationcontext/__init__.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opencensus.common.correlationcontext.correlationcontext \ - import CorrelationContext - +from opencensus.common.correlationcontext.correlationcontext import ( + CorrelationContext, +) __all__ = ['CorrelationContext'] diff --git a/contrib/opencensus-correlation/setup.py b/contrib/opencensus-correlation/setup.py index 4f9271017..567a39ef4 100644 --- a/contrib/opencensus-correlation/setup.py +++ b/contrib/opencensus-correlation/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-correlation/tests/test_correlation_context.py b/contrib/opencensus-correlation/tests/test_correlation_context.py index 98864ba1d..aa0eb0eb8 100644 --- a/contrib/opencensus-correlation/tests/test_correlation_context.py +++ b/contrib/opencensus-correlation/tests/test_correlation_context.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest + from opencensus.common.correlationcontext import CorrelationContext diff --git a/contrib/opencensus-ext-azure/examples/metrics/standard.py b/contrib/opencensus-ext-azure/examples/metrics/standard.py index 3c4627765..526b3e737 100644 --- a/contrib/opencensus-ext-azure/examples/metrics/standard.py +++ b/contrib/opencensus-ext-azure/examples/metrics/standard.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import psutil import time +import psutil from opencensus.ext.azure import metrics_exporter diff --git a/contrib/opencensus-ext-azure/examples/traces/client.py b/contrib/opencensus-ext-azure/examples/traces/client.py index 004c79ab2..9adeff89f 100644 --- a/contrib/opencensus-ext-azure/examples/traces/client.py +++ b/contrib/opencensus-ext-azure/examples/traces/client.py @@ -13,7 +13,6 @@ # limitations under the License. import requests - from opencensus.ext.azure.trace_exporter import AzureExporter from opencensus.trace import config_integration from opencensus.trace.samplers import ProbabilitySampler diff --git a/contrib/opencensus-ext-azure/examples/traces/server.py b/contrib/opencensus-ext-azure/examples/traces/server.py index 3702e7ef3..9ffbd7790 100644 --- a/contrib/opencensus-ext-azure/examples/traces/server.py +++ b/contrib/opencensus-ext-azure/examples/traces/server.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flask import Flask import requests - +from flask import Flask from opencensus.ext.azure.trace_exporter import AzureExporter from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.trace import config_integration diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/exporter.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/exporter.py index b6eaed7e6..969568087 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/exporter.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/exporter.py @@ -16,8 +16,7 @@ import threading import time -from opencensus.common.schedule import Queue -from opencensus.common.schedule import QueueEvent +from opencensus.common.schedule import Queue, QueueEvent from opencensus.ext.azure.common import Options from opencensus.trace import execution_context diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/storage.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/storage.py index a7fce53d7..55f375fb4 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/storage.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/storage.py @@ -1,7 +1,7 @@ import datetime import json -import random import os +import random from opencensus.common.schedule import PeriodicTask diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py index 2b2d24a57..661a57dd9 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py @@ -14,6 +14,7 @@ import json import logging + import requests logger = logging.getLogger(__name__) diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py index 97c6148e3..bb3550e89 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py @@ -18,15 +18,15 @@ import platform import sys +from opencensus.common.utils import timestamp_to_microseconds, to_iso_str +from opencensus.common.version import __version__ as opencensus_version +from opencensus.ext.azure.common.version import __version__ as ext_version + try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse -from opencensus.common.version import __version__ as opencensus_version -from opencensus.common.utils import timestamp_to_microseconds -from opencensus.common.utils import to_iso_str -from opencensus.ext.azure.common.version import __version__ as ext_version azure_monitor_context = { 'ai.cloud.role': os.path.basename(sys.argv[0]) or 'Python Application', diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py index 57f258e2a..eccaa9372 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py @@ -17,15 +17,14 @@ import time import traceback -from opencensus.common.schedule import Queue -from opencensus.common.schedule import QueueExitEvent -from opencensus.common.schedule import QueueEvent -from opencensus.ext.azure.common import Options -from opencensus.ext.azure.common import utils -from opencensus.ext.azure.common.protocol import Data -from opencensus.ext.azure.common.protocol import Envelope -from opencensus.ext.azure.common.protocol import ExceptionData -from opencensus.ext.azure.common.protocol import Message +from opencensus.common.schedule import Queue, QueueEvent, QueueExitEvent +from opencensus.ext.azure.common import Options, utils +from opencensus.ext.azure.common.protocol import ( + Data, + Envelope, + ExceptionData, + Message, +) from opencensus.ext.azure.common.storage import LocalFileStorage from opencensus.ext.azure.common.transport import TransportMixin from opencensus.trace import execution_context diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/__init__.py index 80e1b4ba2..3cedbf2f5 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/__init__.py @@ -14,15 +14,16 @@ import json import logging -import requests +import requests from opencensus.common import utils as common_utils -from opencensus.ext.azure.common import Options -from opencensus.ext.azure.common import utils -from opencensus.ext.azure.common.protocol import Data -from opencensus.ext.azure.common.protocol import DataPoint -from opencensus.ext.azure.common.protocol import Envelope -from opencensus.ext.azure.common.protocol import MetricData +from opencensus.ext.azure.common import Options, utils +from opencensus.ext.azure.common.protocol import ( + Data, + DataPoint, + Envelope, + MetricData, +) from opencensus.ext.azure.metrics_exporter import standard_metrics from opencensus.metrics import transport from opencensus.metrics.export.metric_descriptor import MetricDescriptorType diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/__init__.py index fc6a1c235..cf4104ad3 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/__init__.py @@ -12,22 +12,25 @@ # See the License for the specific language governing permissions and # limitations under the License. +from opencensus.ext.azure.metrics_exporter.standard_metrics.cpu import ( + ProcessorTimeMetric, +) +from opencensus.ext.azure.metrics_exporter.standard_metrics.http_dependency import ( + DependencyRateMetric, +) +from opencensus.ext.azure.metrics_exporter.standard_metrics.http_requests import ( + RequestsAvgExecutionMetric, + RequestsRateMetric, +) +from opencensus.ext.azure.metrics_exporter.standard_metrics.memory import ( + AvailableMemoryMetric, +) +from opencensus.ext.azure.metrics_exporter.standard_metrics.process import ( + ProcessCPUMetric, + ProcessMemoryMetric, +) from opencensus.metrics.export.gauge import Registry from opencensus.metrics.export.metric_producer import MetricProducer -from opencensus.ext.azure.metrics_exporter.standard_metrics.cpu \ - import ProcessorTimeMetric -from opencensus.ext.azure.metrics_exporter.standard_metrics.http_dependency \ - import DependencyRateMetric -from opencensus.ext.azure.metrics_exporter.standard_metrics.memory \ - import AvailableMemoryMetric -from opencensus.ext.azure.metrics_exporter.standard_metrics.process \ - import ProcessCPUMetric -from opencensus.ext.azure.metrics_exporter.standard_metrics.process \ - import ProcessMemoryMetric -from opencensus.ext.azure.metrics_exporter.standard_metrics.http_requests \ - import RequestsAvgExecutionMetric -from opencensus.ext.azure.metrics_exporter.standard_metrics.http_requests \ - import RequestsRateMetric # List of standard metrics to track STANDARD_METRICS = [AvailableMemoryMetric, diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/cpu.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/cpu.py index 307a019d6..ead1ac20e 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/cpu.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/cpu.py @@ -13,7 +13,6 @@ # limitations under the License. import psutil - from opencensus.metrics.export.gauge import DerivedDoubleGauge diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_dependency.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_dependency.py index 4a00a4f5f..e944b722e 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_dependency.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_dependency.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import requests import threading import time +import requests from opencensus.metrics.export.gauge import DerivedDoubleGauge from opencensus.trace import execution_context diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_requests.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_requests.py index b19f77b55..629161dea 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_requests.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_requests.py @@ -17,6 +17,7 @@ import time from opencensus.metrics.export.gauge import DerivedDoubleGauge + if sys.version_info < (3,): from BaseHTTPServer import HTTPServer else: diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/memory.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/memory.py index ccf80dda6..4e547214a 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/memory.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/memory.py @@ -13,7 +13,6 @@ # limitations under the License. import psutil - from opencensus.metrics.export.gauge import DerivedLongGauge diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/process.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/process.py index 454f82f8d..30b86a05c 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/process.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/process.py @@ -13,10 +13,12 @@ # limitations under the License. import logging -import psutil -from opencensus.metrics.export.gauge import DerivedLongGauge -from opencensus.metrics.export.gauge import DerivedDoubleGauge +import psutil +from opencensus.metrics.export.gauge import ( + DerivedDoubleGauge, + DerivedLongGauge, +) logger = logging.getLogger(__name__) PROCESS = psutil.Process() diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py index 6ab356880..41f2a06aa 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py @@ -15,13 +15,14 @@ import logging from opencensus.common.schedule import QueueExitEvent -from opencensus.ext.azure.common import Options -from opencensus.ext.azure.common import utils +from opencensus.ext.azure.common import Options, utils from opencensus.ext.azure.common.exporter import BaseExporter -from opencensus.ext.azure.common.protocol import Data -from opencensus.ext.azure.common.protocol import Envelope -from opencensus.ext.azure.common.protocol import RemoteDependency -from opencensus.ext.azure.common.protocol import Request +from opencensus.ext.azure.common.protocol import ( + Data, + Envelope, + RemoteDependency, + Request, +) from opencensus.ext.azure.common.storage import LocalFileStorage from opencensus.ext.azure.common.transport import TransportMixin from opencensus.trace.span import SpanKind diff --git a/contrib/opencensus-ext-azure/setup.py b/contrib/opencensus-ext-azure/setup.py index a5efc1676..d4f228478 100644 --- a/contrib/opencensus-ext-azure/setup.py +++ b/contrib/opencensus-ext-azure/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from opencensus.ext.azure.common.version import __version__ setup( diff --git a/contrib/opencensus-ext-azure/tests/test_azure_log_exporter.py b/contrib/opencensus-ext-azure/tests/test_azure_log_exporter.py index 2707c9775..15c361cbd 100644 --- a/contrib/opencensus-ext-azure/tests/test_azure_log_exporter.py +++ b/contrib/opencensus-ext-azure/tests/test_azure_log_exporter.py @@ -13,11 +13,12 @@ # limitations under the License. import logging -import mock import os import shutil import unittest +import mock + from opencensus.ext.azure import log_exporter TEST_FOLDER = os.path.abspath('.test.logs') diff --git a/contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py b/contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py index 466f017ce..63c802e0d 100644 --- a/contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py +++ b/contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py @@ -12,23 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import unittest from datetime import datetime +import mock + from opencensus.common import utils from opencensus.ext.azure import metrics_exporter from opencensus.ext.azure.common import Options -from opencensus.ext.azure.common.protocol import DataPoint -from opencensus.ext.azure.common.protocol import Envelope +from opencensus.ext.azure.common.protocol import DataPoint, Envelope from opencensus.ext.azure.metrics_exporter import standard_metrics -from opencensus.metrics import label_key -from opencensus.metrics import label_value -from opencensus.metrics.export import metric -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import point -from opencensus.metrics.export import time_series -from opencensus.metrics.export import value +from opencensus.metrics import label_key, label_value +from opencensus.metrics.export import ( + metric, + metric_descriptor, + point, + time_series, + value, +) from opencensus.metrics.export.metric_descriptor import MetricDescriptorType diff --git a/contrib/opencensus-ext-azure/tests/test_azure_standard_metrics.py b/contrib/opencensus-ext-azure/tests/test_azure_standard_metrics.py index 70aaf4e30..2a01ca90b 100644 --- a/contrib/opencensus-ext-azure/tests/test_azure_standard_metrics.py +++ b/contrib/opencensus-ext-azure/tests/test_azure_standard_metrics.py @@ -13,13 +13,15 @@ # limitations under the License. import collections -import mock -import requests import sys import unittest +import mock + +import requests from opencensus.ext.azure.metrics_exporter import standard_metrics from opencensus.trace import execution_context + if sys.version_info < (3,): from BaseHTTPServer import HTTPServer else: diff --git a/contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py b/contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py index d884383f7..935a52a7e 100644 --- a/contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py +++ b/contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py @@ -13,11 +13,12 @@ # limitations under the License. import json -import mock import os import shutil import unittest +import mock + from opencensus.ext.azure import trace_exporter TEST_FOLDER = os.path.abspath('.test.exporter') diff --git a/contrib/opencensus-ext-azure/tests/test_azure_utils.py b/contrib/opencensus-ext-azure/tests/test_azure_utils.py index 79c7bfdb3..213a7fe0a 100644 --- a/contrib/opencensus-ext-azure/tests/test_azure_utils.py +++ b/contrib/opencensus-ext-azure/tests/test_azure_utils.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest + from opencensus.ext.azure.common import utils diff --git a/contrib/opencensus-ext-azure/tests/test_protocol.py b/contrib/opencensus-ext-azure/tests/test_protocol.py index 7d7a9f2cd..dcfc830e6 100644 --- a/contrib/opencensus-ext-azure/tests/test_protocol.py +++ b/contrib/opencensus-ext-azure/tests/test_protocol.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest + from opencensus.ext.azure.common import protocol diff --git a/contrib/opencensus-ext-azure/tests/test_storage.py b/contrib/opencensus-ext-azure/tests/test_storage.py index 9b9b2e12b..b5776926d 100644 --- a/contrib/opencensus-ext-azure/tests/test_storage.py +++ b/contrib/opencensus-ext-azure/tests/test_storage.py @@ -12,15 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import os import shutil import unittest -from opencensus.ext.azure.common.storage import _now -from opencensus.ext.azure.common.storage import _seconds -from opencensus.ext.azure.common.storage import LocalFileBlob -from opencensus.ext.azure.common.storage import LocalFileStorage +import mock + +from opencensus.ext.azure.common.storage import ( + LocalFileBlob, + LocalFileStorage, + _now, + _seconds, +) TEST_FOLDER = os.path.abspath('.test') diff --git a/contrib/opencensus-ext-datadog/examples/datadog.py b/contrib/opencensus-ext-datadog/examples/datadog.py index 7e1a6e0d0..aa3c12528 100644 --- a/contrib/opencensus-ext-datadog/examples/datadog.py +++ b/contrib/opencensus-ext-datadog/examples/datadog.py @@ -1,9 +1,7 @@ from flask import Flask - from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.trace.samplers import AlwaysOnSampler -from traces import DatadogTraceExporter -from traces import Options +from traces import DatadogTraceExporter, Options app = Flask(__name__) middleware = FlaskMiddleware(app, diff --git a/contrib/opencensus-ext-datadog/opencensus/ext/datadog/traces.py b/contrib/opencensus-ext-datadog/opencensus/ext/datadog/traces.py index ebeee9b84..b2576d45a 100644 --- a/contrib/opencensus-ext-datadog/opencensus/ext/datadog/traces.py +++ b/contrib/opencensus-ext-datadog/opencensus/ext/datadog/traces.py @@ -16,12 +16,10 @@ from datetime import datetime import bitarray - from opencensus.common.transports import sync from opencensus.common.utils import ISO_DATETIME_REGEX from opencensus.ext.datadog.transport import DDTransport -from opencensus.trace import base_exporter -from opencensus.trace import span_data +from opencensus.trace import base_exporter, span_data class Options(object): diff --git a/contrib/opencensus-ext-datadog/opencensus/ext/datadog/transport.py b/contrib/opencensus-ext-datadog/opencensus/ext/datadog/transport.py index 72a598a77..58c23fc6a 100644 --- a/contrib/opencensus-ext-datadog/opencensus/ext/datadog/transport.py +++ b/contrib/opencensus-ext-datadog/opencensus/ext/datadog/transport.py @@ -1,4 +1,5 @@ import platform + import requests diff --git a/contrib/opencensus-ext-datadog/setup.py b/contrib/opencensus-ext-datadog/setup.py index 48aa39367..804bbdcba 100644 --- a/contrib/opencensus-ext-datadog/setup.py +++ b/contrib/opencensus-ext-datadog/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-datadog/tests/traces_test.py b/contrib/opencensus-ext-datadog/tests/traces_test.py index 46f7e757b..cc3799694 100644 --- a/contrib/opencensus-ext-datadog/tests/traces_test.py +++ b/contrib/opencensus-ext-datadog/tests/traces_test.py @@ -2,13 +2,17 @@ import mock -from opencensus.ext.datadog.traces import (convert_id, to_dd_type, - value_from_atts_elem, - atts_to_metadata, - new_trace_exporter, - DatadogTraceExporter, Options) -from opencensus.trace import span_data as span_data_module +from opencensus.ext.datadog.traces import ( + DatadogTraceExporter, + Options, + atts_to_metadata, + convert_id, + new_trace_exporter, + to_dd_type, + value_from_atts_elem, +) from opencensus.trace import span_context +from opencensus.trace import span_data as span_data_module class TestTraces(unittest.TestCase): diff --git a/contrib/opencensus-ext-dbapi/setup.py b/contrib/opencensus-ext-dbapi/setup.py index bd5a8469e..f55daf5d6 100644 --- a/contrib/opencensus-ext-dbapi/setup.py +++ b/contrib/opencensus-ext-dbapi/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-django/examples/app/urls.py b/contrib/opencensus-ext-django/examples/app/urls.py index cbe75510d..faeb4fa5b 100644 --- a/contrib/opencensus-ext-django/examples/app/urls.py +++ b/contrib/opencensus-ext-django/examples/app/urls.py @@ -27,12 +27,10 @@ 1. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) """ +import app.views from django.conf.urls import url from django.contrib import admin -import app.views - - urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', app.views.home), diff --git a/contrib/opencensus-ext-django/examples/app/views.py b/contrib/opencensus-ext-django/examples/app/views.py index d8ea57037..7ce641f5e 100644 --- a/contrib/opencensus-ext-django/examples/app/views.py +++ b/contrib/opencensus-ext-django/examples/app/views.py @@ -12,19 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -from django.http import HttpResponse -from django.shortcuts import render - -from .forms import HelloForm - -from opencensus.trace import config_integration +import os -import mysql.connector import psycopg2 import sqlalchemy -import os +import mysql.connector import requests +from django.http import HttpResponse +from django.shortcuts import render +from opencensus.trace import config_integration + +from .forms import HelloForm DB_HOST = 'localhost' diff --git a/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py b/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py index 6ba6a80a9..706b9c7a1 100644 --- a/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py +++ b/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py @@ -13,20 +13,23 @@ # limitations under the License. """Django middleware helper to capture and trace a request.""" -import django -import logging import six +import logging + +from google.rpc import code_pb2 + +import django import django.conf from django.db import connection from django.utils.deprecation import MiddlewareMixin -from google.rpc import code_pb2 - from opencensus.common import configuration -from opencensus.trace import attributes_helper -from opencensus.trace import execution_context -from opencensus.trace import print_exporter -from opencensus.trace import samplers +from opencensus.trace import ( + attributes_helper, + execution_context, + print_exporter, + samplers, +) from opencensus.trace import span as span_module from opencensus.trace import status as status_module from opencensus.trace import tracer as tracer_module diff --git a/contrib/opencensus-ext-django/setup.py b/contrib/opencensus-ext-django/setup.py index 699dd62e8..b2acf735e 100644 --- a/contrib/opencensus-ext-django/setup.py +++ b/contrib/opencensus-ext-django/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-django/tests/test_django_db_middleware.py b/contrib/opencensus-ext-django/tests/test_django_db_middleware.py index 18bf385c9..553f2c5e8 100644 --- a/contrib/opencensus-ext-django/tests/test_django_db_middleware.py +++ b/contrib/opencensus-ext-django/tests/test_django_db_middleware.py @@ -15,11 +15,11 @@ import unittest from collections import namedtuple -import django import mock + +import django import pytest from django.test.utils import teardown_test_environment - from opencensus.trace import execution_context diff --git a/contrib/opencensus-ext-django/tests/test_django_middleware.py b/contrib/opencensus-ext-django/tests/test_django_middleware.py index cbd992d4a..57e0d98f8 100644 --- a/contrib/opencensus-ext-django/tests/test_django_middleware.py +++ b/contrib/opencensus-ext-django/tests/test_django_middleware.py @@ -12,15 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import unittest +import mock + from django.test import RequestFactory from django.test.utils import teardown_test_environment - -from opencensus.trace import execution_context -from opencensus.trace import print_exporter -from opencensus.trace import samplers +from opencensus.trace import execution_context, print_exporter, samplers from opencensus.trace import span as span_module from opencensus.trace import utils from opencensus.trace.blank_span import BlankSpan diff --git a/contrib/opencensus-ext-flask/examples/custom.py b/contrib/opencensus-ext-flask/examples/custom.py index c310958a4..066421c6a 100644 --- a/contrib/opencensus-ext-flask/examples/custom.py +++ b/contrib/opencensus-ext-flask/examples/custom.py @@ -14,20 +14,19 @@ import os +import psycopg2 +import sqlalchemy + import flask import grpc +import hello_world_pb2 +import hello_world_pb2_grpc import mysql.connector -import psycopg2 import requests -import sqlalchemy - from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.ext.grpc import client_interceptor from opencensus.ext.stackdriver import trace_exporter as stackdriver_exporter -from opencensus.trace import config_integration -from opencensus.trace import samplers -import hello_world_pb2 -import hello_world_pb2_grpc +from opencensus.trace import config_integration, samplers INTEGRATIONS = ['mysql', 'postgresql', 'sqlalchemy', 'requests'] diff --git a/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py b/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py index fcbdc41e7..614c723be 100644 --- a/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py +++ b/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py @@ -12,21 +12,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging import six + +import logging import sys -import flask from google.rpc import code_pb2 +import flask from opencensus.common import configuration -from opencensus.trace import attributes_helper -from opencensus.trace import execution_context -from opencensus.trace import print_exporter -from opencensus.trace import samplers +from opencensus.trace import ( + attributes_helper, + execution_context, + print_exporter, + samplers, +) from opencensus.trace import span as span_module -from opencensus.trace import stack_trace -from opencensus.trace import status +from opencensus.trace import stack_trace, status from opencensus.trace import tracer as tracer_module from opencensus.trace import utils from opencensus.trace.propagation import trace_context_http_header_format diff --git a/contrib/opencensus-ext-flask/setup.py b/contrib/opencensus-ext-flask/setup.py index f05797d62..e3fc3a640 100644 --- a/contrib/opencensus-ext-flask/setup.py +++ b/contrib/opencensus-ext-flask/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-flask/tests/test_flask_middleware.py b/contrib/opencensus-ext-flask/tests/test_flask_middleware.py index bcd11a506..fb0021638 100644 --- a/contrib/opencensus-ext-flask/tests/test_flask_middleware.py +++ b/contrib/opencensus-ext-flask/tests/test_flask_middleware.py @@ -17,25 +17,20 @@ import unittest -from google.rpc import code_pb2 -import flask -from werkzeug.exceptions import NotFound import mock +from google.rpc import code_pb2 +import flask from opencensus.ext.flask import flask_middleware -from opencensus.trace import execution_context -from opencensus.trace import print_exporter -from opencensus.trace import samplers +from opencensus.trace import execution_context, print_exporter, samplers from opencensus.trace import span as span_module -from opencensus.trace import span_data -from opencensus.trace import stack_trace -from opencensus.trace import status +from opencensus.trace import span_data, stack_trace, status from opencensus.trace.blank_span import BlankSpan from opencensus.trace.propagation import trace_context_http_header_format from opencensus.trace.span_context import SpanContext from opencensus.trace.trace_options import TraceOptions -from opencensus.trace.tracers import base -from opencensus.trace.tracers import noop_tracer +from opencensus.trace.tracers import base, noop_tracer +from werkzeug.exceptions import NotFound class FlaskTestException(Exception): diff --git a/contrib/opencensus-ext-gevent/opencensus/ext/gevent/geventcompatibility.py b/contrib/opencensus-ext-gevent/opencensus/ext/gevent/geventcompatibility.py index f1f662c48..d59633573 100644 --- a/contrib/opencensus-ext-gevent/opencensus/ext/gevent/geventcompatibility.py +++ b/contrib/opencensus-ext-gevent/opencensus/ext/gevent/geventcompatibility.py @@ -1,4 +1,5 @@ import logging + import gevent.monkey diff --git a/contrib/opencensus-ext-gevent/setup.py b/contrib/opencensus-ext-gevent/setup.py index 03b666db6..022df4a14 100644 --- a/contrib/opencensus-ext-gevent/setup.py +++ b/contrib/opencensus-ext-gevent/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-gevent/tests/test_patching.py b/contrib/opencensus-ext-gevent/tests/test_patching.py index 08955fdd8..76e711c6c 100644 --- a/contrib/opencensus-ext-gevent/tests/test_patching.py +++ b/contrib/opencensus-ext-gevent/tests/test_patching.py @@ -14,11 +14,11 @@ import unittest -import opencensus.common.runtime_context as runtime_context -import gevent.monkey - import mock +import gevent.monkey +import opencensus.common.runtime_context as runtime_context + class TestPatching(unittest.TestCase): def setUp(self): diff --git a/contrib/opencensus-ext-google-cloud-clientlibs/opencensus/ext/google_cloud_clientlibs/trace.py b/contrib/opencensus-ext-google-cloud-clientlibs/opencensus/ext/google_cloud_clientlibs/trace.py index 3bc9f8e71..1bd096f24 100644 --- a/contrib/opencensus-ext-google-cloud-clientlibs/opencensus/ext/google_cloud_clientlibs/trace.py +++ b/contrib/opencensus-ext-google-cloud-clientlibs/opencensus/ext/google_cloud_clientlibs/trace.py @@ -14,16 +14,12 @@ import logging -import grpc - -from google.cloud import _helpers from google.api_core import grpc_helpers +from google.cloud import _helpers -from opencensus.ext.grpc.client_interceptor import ( - OpenCensusClientInterceptor) - -from opencensus.ext.requests.trace import ( - trace_integration as trace_requests) +import grpc +from opencensus.ext.grpc.client_interceptor import OpenCensusClientInterceptor +from opencensus.ext.requests.trace import trace_integration as trace_requests log = logging.getLogger(__name__) diff --git a/contrib/opencensus-ext-google-cloud-clientlibs/setup.py b/contrib/opencensus-ext-google-cloud-clientlibs/setup.py index 005deedfc..a66b4c683 100644 --- a/contrib/opencensus-ext-google-cloud-clientlibs/setup.py +++ b/contrib/opencensus-ext-google-cloud-clientlibs/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-google-cloud-clientlibs/tests/test_google_cloud_clientlibs_trace.py b/contrib/opencensus-ext-google-cloud-clientlibs/tests/test_google_cloud_clientlibs_trace.py index fa10ba9f5..20b0836e3 100644 --- a/contrib/opencensus-ext-google-cloud-clientlibs/tests/test_google_cloud_clientlibs_trace.py +++ b/contrib/opencensus-ext-google-cloud-clientlibs/tests/test_google_cloud_clientlibs_trace.py @@ -15,8 +15,8 @@ import unittest import mock -import grpc +import grpc from opencensus.ext.google_cloud_clientlibs import trace diff --git a/contrib/opencensus-ext-grpc/examples/hello_world_client.py b/contrib/opencensus-ext-grpc/examples/hello_world_client.py index 48e662118..216a04b2c 100644 --- a/contrib/opencensus-ext-grpc/examples/hello_world_client.py +++ b/contrib/opencensus-ext-grpc/examples/hello_world_client.py @@ -15,13 +15,11 @@ from __future__ import print_function import grpc - import hello_world_pb2 import hello_world_pb2_grpc - -from opencensus.trace.tracer import Tracer from opencensus.ext.grpc import client_interceptor from opencensus.ext.stackdriver import trace_exporter as stackdriver_exporter +from opencensus.trace.tracer import Tracer HOST_PORT = 'localhost:50051' diff --git a/contrib/opencensus-ext-grpc/examples/hello_world_pb2.py b/contrib/opencensus-ext-grpc/examples/hello_world_pb2.py index 5927b2a1a..b67e7f718 100644 --- a/contrib/opencensus-ext-grpc/examples/hello_world_pb2.py +++ b/contrib/opencensus-ext-grpc/examples/hello_world_pb2.py @@ -3,12 +3,14 @@ # source: hello_world.proto import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) + from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pb2 from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database -from google.protobuf import descriptor_pb2 + +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() diff --git a/contrib/opencensus-ext-grpc/examples/hello_world_pb2_grpc.py b/contrib/opencensus-ext-grpc/examples/hello_world_pb2_grpc.py index 66108f48e..e1fbfdb29 100644 --- a/contrib/opencensus-ext-grpc/examples/hello_world_pb2_grpc.py +++ b/contrib/opencensus-ext-grpc/examples/hello_world_pb2_grpc.py @@ -1,6 +1,5 @@ # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc - import hello_world_pb2 as hello__world__pb2 diff --git a/contrib/opencensus-ext-grpc/examples/hello_world_server.py b/contrib/opencensus-ext-grpc/examples/hello_world_server.py index 4698e3569..cd9bc1b6e 100644 --- a/contrib/opencensus-ext-grpc/examples/hello_world_server.py +++ b/contrib/opencensus-ext-grpc/examples/hello_world_server.py @@ -12,14 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from concurrent import futures import time +from concurrent import futures import grpc - import hello_world_pb2 import hello_world_pb2_grpc - from opencensus.ext.grpc import server_interceptor from opencensus.ext.stackdriver import trace_exporter as stackdriver_exporter from opencensus.trace import samplers diff --git a/contrib/opencensus-ext-grpc/opencensus/ext/grpc/client_interceptor.py b/contrib/opencensus-ext-grpc/opencensus/ext/grpc/client_interceptor.py index 4fa9ccdf5..4169b6060 100644 --- a/contrib/opencensus-ext-grpc/opencensus/ext/grpc/client_interceptor.py +++ b/contrib/opencensus-ext-grpc/opencensus/ext/grpc/client_interceptor.py @@ -12,16 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +import six + import collections import logging import grpc -import six - from opencensus.ext import grpc as oc_grpc from opencensus.ext.grpc import utils as grpc_utils -from opencensus.trace import attributes_helper -from opencensus.trace import execution_context +from opencensus.trace import attributes_helper, execution_context from opencensus.trace import span as span_module from opencensus.trace import time_event from opencensus.trace.propagation import binary_format diff --git a/contrib/opencensus-ext-grpc/opencensus/ext/grpc/server_interceptor.py b/contrib/opencensus-ext-grpc/opencensus/ext/grpc/server_interceptor.py index 2308e3dea..9816cfe25 100644 --- a/contrib/opencensus-ext-grpc/opencensus/ext/grpc/server_interceptor.py +++ b/contrib/opencensus-ext-grpc/opencensus/ext/grpc/server_interceptor.py @@ -13,17 +13,15 @@ # limitations under the License. import sys -import grpc from google.rpc import code_pb2 +import grpc from opencensus.ext import grpc as oc_grpc from opencensus.ext.grpc import utils as grpc_utils -from opencensus.trace import attributes_helper -from opencensus.trace import execution_context +from opencensus.trace import attributes_helper, execution_context from opencensus.trace import span as span_module from opencensus.trace import stack_trace as stack_trace -from opencensus.trace import status -from opencensus.trace import time_event +from opencensus.trace import status, time_event from opencensus.trace import tracer as tracer_module from opencensus.trace.propagation import binary_format diff --git a/contrib/opencensus-ext-grpc/opencensus/ext/grpc/utils.py b/contrib/opencensus-ext-grpc/opencensus/ext/grpc/utils.py index 222bceca8..1c93e44eb 100644 --- a/contrib/opencensus-ext-grpc/opencensus/ext/grpc/utils.py +++ b/contrib/opencensus-ext-grpc/opencensus/ext/grpc/utils.py @@ -2,8 +2,7 @@ from grpc.framework.foundation import future from grpc.framework.interfaces.face import face -from opencensus.trace import execution_context -from opencensus.trace import time_event +from opencensus.trace import execution_context, time_event def add_message_event(proto_message, span, message_event_type, message_id=1): diff --git a/contrib/opencensus-ext-grpc/setup.py b/contrib/opencensus-ext-grpc/setup.py index 9674d4ff1..31b96b390 100644 --- a/contrib/opencensus-ext-grpc/setup.py +++ b/contrib/opencensus-ext-grpc/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-grpc/tests/test_client_interceptor.py b/contrib/opencensus-ext-grpc/tests/test_client_interceptor.py index e45096bb5..0c1a22bdd 100644 --- a/contrib/opencensus-ext-grpc/tests/test_client_interceptor.py +++ b/contrib/opencensus-ext-grpc/tests/test_client_interceptor.py @@ -13,15 +13,15 @@ # limitations under the License. import collections -import mock import threading import unittest +import mock from google.api_core import bidi from google.protobuf import proto_builder -from grpc.framework.foundation import logging_pool -import grpc +import grpc +from grpc.framework.foundation import logging_pool from opencensus.ext.grpc import client_interceptor from opencensus.trace import execution_context from opencensus.trace.tracers.noop_tracer import NoopTracer diff --git a/contrib/opencensus-ext-httplib/opencensus/ext/httplib/trace.py b/contrib/opencensus-ext-httplib/opencensus/ext/httplib/trace.py index 54ed0653d..ed75e326b 100644 --- a/contrib/opencensus-ext-httplib/opencensus/ext/httplib/trace.py +++ b/contrib/opencensus-ext-httplib/opencensus/ext/httplib/trace.py @@ -15,8 +15,7 @@ import logging import sys -from opencensus.trace import attributes_helper -from opencensus.trace import execution_context +from opencensus.trace import attributes_helper, execution_context from opencensus.trace import span as span_module from opencensus.trace import utils diff --git a/contrib/opencensus-ext-httplib/setup.py b/contrib/opencensus-ext-httplib/setup.py index f8a1cbc83..340b43406 100644 --- a/contrib/opencensus-ext-httplib/setup.py +++ b/contrib/opencensus-ext-httplib/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/__init__.py b/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/__init__.py index e738573ed..7b1efeb6a 100644 --- a/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/__init__.py +++ b/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/__init__.py @@ -17,14 +17,13 @@ import logging import socket -from thrift.protocol import TBinaryProtocol, TCompactProtocol -from thrift.transport import THttpClient, TTransport - from opencensus.common.transports import sync from opencensus.common.utils import timestamp_to_microseconds from opencensus.ext.jaeger.trace_exporter.gen.jaeger import agent, jaeger from opencensus.trace import base_exporter from opencensus.trace import link as link_module +from thrift.protocol import TBinaryProtocol, TCompactProtocol +from thrift.transport import THttpClient, TTransport DEFAULT_HOST_NAME = 'localhost' DEFAULT_AGENT_PORT = 6831 diff --git a/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/gen/jaeger/agent.py b/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/gen/jaeger/agent.py index 176264a67..c9531a5e3 100644 --- a/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/gen/jaeger/agent.py +++ b/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/gen/jaeger/agent.py @@ -6,10 +6,14 @@ # options string: py:new_style # -from thrift.Thrift import TType, TMessageType, TApplicationException -from thrift.Thrift import TProcessor -from thrift.transport import TTransport from opencensus.ext.jaeger.trace_exporter.gen.jaeger import jaeger +from thrift.Thrift import ( + TApplicationException, + TMessageType, + TProcessor, + TType, +) +from thrift.transport import TTransport class Iface(object): diff --git a/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/gen/jaeger/jaeger.py b/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/gen/jaeger/jaeger.py index 51c0ac617..e9fa4830b 100644 --- a/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/gen/jaeger/jaeger.py +++ b/contrib/opencensus-ext-jaeger/opencensus/ext/jaeger/trace_exporter/gen/jaeger/jaeger.py @@ -6,11 +6,16 @@ # options string: py:new_style # -from thrift.Thrift import TType, TMessageType, TApplicationException -from thrift.protocol.TProtocol import TProtocolException -import sys import logging -from thrift.Thrift import TProcessor +import sys + +from thrift.protocol.TProtocol import TProtocolException +from thrift.Thrift import ( + TApplicationException, + TMessageType, + TProcessor, + TType, +) from thrift.transport import TTransport diff --git a/contrib/opencensus-ext-jaeger/setup.py b/contrib/opencensus-ext-jaeger/setup.py index d345a92b1..688958f73 100644 --- a/contrib/opencensus-ext-jaeger/setup.py +++ b/contrib/opencensus-ext-jaeger/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-jaeger/tests/test_jaeger_exporter.py b/contrib/opencensus-ext-jaeger/tests/test_jaeger_exporter.py index 67892058c..85c4b924f 100644 --- a/contrib/opencensus-ext-jaeger/tests/test_jaeger_exporter.py +++ b/contrib/opencensus-ext-jaeger/tests/test_jaeger_exporter.py @@ -18,8 +18,14 @@ from opencensus.ext.jaeger import trace_exporter from opencensus.ext.jaeger.trace_exporter.gen.jaeger import jaeger -from opencensus.trace import (attributes, link, span_context, span_data, - status, time_event) +from opencensus.trace import ( + attributes, + link, + span_context, + span_data, + status, + time_event, +) class TestJaegerExporter(unittest.TestCase): diff --git a/contrib/opencensus-ext-logging/setup.py b/contrib/opencensus-ext-logging/setup.py index ab09453c9..76cf383d3 100644 --- a/contrib/opencensus-ext-logging/setup.py +++ b/contrib/opencensus-ext-logging/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-mysql/opencensus/ext/mysql/trace.py b/contrib/opencensus-ext-mysql/opencensus/ext/mysql/trace.py index a988a9214..c192170c5 100644 --- a/contrib/opencensus-ext-mysql/opencensus/ext/mysql/trace.py +++ b/contrib/opencensus-ext-mysql/opencensus/ext/mysql/trace.py @@ -14,8 +14,8 @@ import inspect import logging -import mysql.connector +import mysql.connector from opencensus.ext.dbapi import trace MODULE_NAME = 'mysql' diff --git a/contrib/opencensus-ext-mysql/setup.py b/contrib/opencensus-ext-mysql/setup.py index 4d481e91e..3456658f3 100644 --- a/contrib/opencensus-ext-mysql/setup.py +++ b/contrib/opencensus-ext-mysql/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/stats_exporter/__init__.py b/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/stats_exporter/__init__.py index 5b8c0b7de..7fe5a207c 100644 --- a/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/stats_exporter/__init__.py +++ b/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/stats_exporter/__init__.py @@ -15,17 +15,19 @@ import logging from google.api_core import bidi + +import grpc from opencensus.common.monitored_resource import monitored_resource from opencensus.ext.ocagent import utils from opencensus.metrics import transport -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import value -from opencensus.proto.agent.metrics.v1 import metrics_service_pb2 -from opencensus.proto.agent.metrics.v1 import metrics_service_pb2_grpc +from opencensus.metrics.export import metric_descriptor, value +from opencensus.proto.agent.metrics.v1 import ( + metrics_service_pb2, + metrics_service_pb2_grpc, +) from opencensus.proto.metrics.v1 import metrics_pb2 from opencensus.proto.resource.v1 import resource_pb2 from opencensus.stats import stats -import grpc class StatsExporter(object): diff --git a/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/trace_exporter/__init__.py b/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/trace_exporter/__init__.py index afb3f9bd3..cbcdabca0 100644 --- a/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/trace_exporter/__init__.py +++ b/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/trace_exporter/__init__.py @@ -14,13 +14,15 @@ """Export opencensus spans to ocagent""" from threading import Lock -import grpc +import grpc from opencensus.common.transports import sync from opencensus.ext.ocagent import utils as ocagent_utils from opencensus.ext.ocagent.trace_exporter import utils -from opencensus.proto.agent.trace.v1 import trace_service_pb2 -from opencensus.proto.agent.trace.v1 import trace_service_pb2_grpc +from opencensus.proto.agent.trace.v1 import ( + trace_service_pb2, + trace_service_pb2_grpc, +) from opencensus.trace import base_exporter # Default agent endpoint diff --git a/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/trace_exporter/utils.py b/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/trace_exporter/utils.py index f92a9fce7..305347a3f 100644 --- a/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/trace_exporter/utils.py +++ b/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/trace_exporter/utils.py @@ -15,6 +15,7 @@ """Translates opencensus span data to trace proto""" from google.protobuf.wrappers_pb2 import BoolValue, UInt32Value + from opencensus.ext.ocagent import utils as ocagent_utils from opencensus.proto.trace.v1 import trace_pb2 diff --git a/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/utils/__init__.py b/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/utils/__init__.py index 17347e3df..2196bc79b 100644 --- a/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/utils/__init__.py +++ b/contrib/opencensus-ext-ocagent/opencensus/ext/ocagent/utils/__init__.py @@ -3,6 +3,7 @@ import socket from google.protobuf.timestamp_pb2 import Timestamp + from opencensus.common.version import __version__ as opencensus_version from opencensus.proto.agent.common.v1 import common_pb2 diff --git a/contrib/opencensus-ext-ocagent/setup.py b/contrib/opencensus-ext-ocagent/setup.py index d8f24e8ee..4ac94a067 100644 --- a/contrib/opencensus-ext-ocagent/setup.py +++ b/contrib/opencensus-ext-ocagent/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-ocagent/tests/test_ocagent_utils.py b/contrib/opencensus-ext-ocagent/tests/test_ocagent_utils.py index 2ce995651..ec28ffdbf 100644 --- a/contrib/opencensus-ext-ocagent/tests/test_ocagent_utils.py +++ b/contrib/opencensus-ext-ocagent/tests/test_ocagent_utils.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime import unittest +from datetime import datetime from opencensus.common import utils as common_utils from opencensus.ext.ocagent import utils diff --git a/contrib/opencensus-ext-ocagent/tests/test_stats_exporter.py b/contrib/opencensus-ext-ocagent/tests/test_stats_exporter.py index 907a8628d..f7f395149 100644 --- a/contrib/opencensus-ext-ocagent/tests/test_stats_exporter.py +++ b/contrib/opencensus-ext-ocagent/tests/test_stats_exporter.py @@ -12,30 +12,34 @@ # See the License for the specific language governing permissions and # limitations under the License. -from concurrent import futures -from datetime import datetime -import grpc -import mock import os import socket import threading import time import unittest +from concurrent import futures +from datetime import datetime +import mock from google.protobuf import timestamp_pb2 -from opencensus.common import resource -from opencensus.common import utils + +import grpc +from opencensus.common import resource, utils from opencensus.common.version import __version__ as opencensus_version from opencensus.ext.ocagent import stats_exporter as ocagent from opencensus.metrics import label_value -from opencensus.metrics.export import metric -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import point -from opencensus.metrics.export import time_series -from opencensus.metrics.export import value +from opencensus.metrics.export import ( + metric, + metric_descriptor, + point, + time_series, + value, +) from opencensus.proto.agent.common.v1 import common_pb2 -from opencensus.proto.agent.metrics.v1 import metrics_service_pb2 -from opencensus.proto.agent.metrics.v1 import metrics_service_pb2_grpc +from opencensus.proto.agent.metrics.v1 import ( + metrics_service_pb2, + metrics_service_pb2_grpc, +) from opencensus.proto.metrics.v1 import metrics_pb2 from opencensus.proto.resource.v1 import resource_pb2 from opencensus.stats import aggregation as aggregation_module diff --git a/contrib/opencensus-ext-ocagent/tests/test_trace_exporter.py b/contrib/opencensus-ext-ocagent/tests/test_trace_exporter.py index fbd584dc8..a1c665633 100644 --- a/contrib/opencensus-ext-ocagent/tests/test_trace_exporter.py +++ b/contrib/opencensus-ext-ocagent/tests/test_trace_exporter.py @@ -13,19 +13,19 @@ # limitations under the License. import codecs -import grpc -import mock import os import socket import unittest +import mock + +import grpc from opencensus.common.version import __version__ from opencensus.ext.ocagent.trace_exporter import TraceExporter from opencensus.proto.trace.v1 import trace_config_pb2 from opencensus.trace import span_context as span_context_module from opencensus.trace import span_data as span_data_module - SERVICE_NAME = 'my-service' diff --git a/contrib/opencensus-ext-ocagent/tests/test_trace_exporter_utils.py b/contrib/opencensus-ext-ocagent/tests/test_trace_exporter_utils.py index 3c23e17c5..439114e1d 100644 --- a/contrib/opencensus-ext-ocagent/tests/test_trace_exporter_utils.py +++ b/contrib/opencensus-ext-ocagent/tests/test_trace_exporter_utils.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime -from datetime import timedelta import codecs import unittest +from datetime import datetime, timedelta from opencensus.ext.ocagent.trace_exporter import utils from opencensus.proto.trace.v1 import trace_pb2 diff --git a/contrib/opencensus-ext-postgresql/opencensus/ext/postgresql/trace.py b/contrib/opencensus-ext-postgresql/opencensus/ext/postgresql/trace.py index 4c948af23..5ae2ce9fc 100644 --- a/contrib/opencensus-ext-postgresql/opencensus/ext/postgresql/trace.py +++ b/contrib/opencensus-ext-postgresql/opencensus/ext/postgresql/trace.py @@ -15,13 +15,13 @@ import inspect import logging -from opencensus.trace import execution_context -from opencensus.trace import span as span_module - import psycopg2 from psycopg2 import connect as pg_connect from psycopg2.extensions import cursor as pgcursor +from opencensus.trace import execution_context +from opencensus.trace import span as span_module + log = logging.getLogger(__name__) MODULE_NAME = 'postgresql' diff --git a/contrib/opencensus-ext-postgresql/setup.py b/contrib/opencensus-ext-postgresql/setup.py index c26c5e143..41bd59806 100644 --- a/contrib/opencensus-ext-postgresql/setup.py +++ b/contrib/opencensus-ext-postgresql/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-prometheus/examples/prometheus.py b/contrib/opencensus-ext-prometheus/examples/prometheus.py index 5e808d007..99912f90e 100644 --- a/contrib/opencensus-ext-prometheus/examples/prometheus.py +++ b/contrib/opencensus-ext-prometheus/examples/prometheus.py @@ -16,6 +16,7 @@ import random import time +from pprint import pprint from opencensus.ext.prometheus import stats_exporter as prometheus from opencensus.stats import aggregation as aggregation_module @@ -25,7 +26,6 @@ from opencensus.tags import tag_key as tag_key_module from opencensus.tags import tag_map as tag_map_module from opencensus.tags import tag_value as tag_value_module -from pprint import pprint MiB = 1 << 20 FRONTEND_KEY = tag_key_module.TagKey("myorg_keys_frontend") diff --git a/contrib/opencensus-ext-prometheus/opencensus/ext/prometheus/stats_exporter/__init__.py b/contrib/opencensus-ext-prometheus/opencensus/ext/prometheus/stats_exporter/__init__.py index ec07781cc..785a199b7 100644 --- a/contrib/opencensus-ext-prometheus/opencensus/ext/prometheus/stats_exporter/__init__.py +++ b/contrib/opencensus-ext-prometheus/opencensus/ext/prometheus/stats_exporter/__init__.py @@ -12,19 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -from prometheus_client import start_http_server -from prometheus_client.core import CollectorRegistry -from prometheus_client.core import CounterMetricFamily -from prometheus_client.core import GaugeMetricFamily -from prometheus_client.core import HistogramMetricFamily -from prometheus_client.core import REGISTRY -from prometheus_client.core import UnknownMetricFamily +import re from opencensus.common.transports import sync from opencensus.stats import aggregation_data as aggregation_data_module from opencensus.stats import base_exporter - -import re +from prometheus_client import start_http_server +from prometheus_client.core import ( + REGISTRY, + CollectorRegistry, + CounterMetricFamily, + GaugeMetricFamily, + HistogramMetricFamily, + UnknownMetricFamily, +) class Options(object): diff --git a/contrib/opencensus-ext-prometheus/setup.py b/contrib/opencensus-ext-prometheus/setup.py index ff5271744..2fca7c76f 100644 --- a/contrib/opencensus-ext-prometheus/setup.py +++ b/contrib/opencensus-ext-prometheus/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-prometheus/tests/test_prometheus_stats.py b/contrib/opencensus-ext-prometheus/tests/test_prometheus_stats.py index 7dcf46db5..7746792e8 100644 --- a/contrib/opencensus-ext-prometheus/tests/test_prometheus_stats.py +++ b/contrib/opencensus-ext-prometheus/tests/test_prometheus_stats.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime -import mock import unittest +from datetime import datetime -from prometheus_client.core import Sample +import mock from opencensus.ext.prometheus import stats_exporter as prometheus from opencensus.stats import aggregation as aggregation_module @@ -27,6 +26,7 @@ from opencensus.tags import tag_key as tag_key_module from opencensus.tags import tag_map as tag_map_module from opencensus.tags import tag_value as tag_value_module +from prometheus_client.core import Sample MiB = 1 << 20 FRONTEND_KEY = tag_key_module.TagKey("myorg_keys_frontend") diff --git a/contrib/opencensus-ext-pymongo/opencensus/ext/pymongo/trace.py b/contrib/opencensus-ext-pymongo/opencensus/ext/pymongo/trace.py index 425580b8e..3dc548fa8 100644 --- a/contrib/opencensus-ext-pymongo/opencensus/ext/pymongo/trace.py +++ b/contrib/opencensus-ext-pymongo/opencensus/ext/pymongo/trace.py @@ -14,14 +14,12 @@ import logging -from pymongo import monitoring - from google.rpc import code_pb2 from opencensus.trace import execution_context from opencensus.trace import span as span_module from opencensus.trace import status as status_module - +from pymongo import monitoring log = logging.getLogger(__name__) diff --git a/contrib/opencensus-ext-pymongo/setup.py b/contrib/opencensus-ext-pymongo/setup.py index 7cc54d5c5..63adca99e 100644 --- a/contrib/opencensus-ext-pymongo/setup.py +++ b/contrib/opencensus-ext-pymongo/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-pymysql/opencensus/ext/pymysql/trace.py b/contrib/opencensus-ext-pymysql/opencensus/ext/pymysql/trace.py index 8f52ce901..3fbd7db31 100644 --- a/contrib/opencensus-ext-pymysql/opencensus/ext/pymysql/trace.py +++ b/contrib/opencensus-ext-pymysql/opencensus/ext/pymysql/trace.py @@ -14,6 +14,7 @@ import inspect import logging + import pymysql from opencensus.ext.dbapi import trace diff --git a/contrib/opencensus-ext-pymysql/setup.py b/contrib/opencensus-ext-pymysql/setup.py index 8a88d3da0..f8502034d 100644 --- a/contrib/opencensus-ext-pymysql/setup.py +++ b/contrib/opencensus-ext-pymysql/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-pyramid/examples/app/__init__.py b/contrib/opencensus-ext-pyramid/examples/app/__init__.py index 24dcc1b82..7aae18fc5 100644 --- a/contrib/opencensus-ext-pyramid/examples/app/__init__.py +++ b/contrib/opencensus-ext-pyramid/examples/app/__init__.py @@ -13,7 +13,6 @@ # limitations under the License. import requests - from pyramid.config import Configurator from pyramid.response import Response from pyramid.tweens import MAIN diff --git a/contrib/opencensus-ext-pyramid/examples/simple.py b/contrib/opencensus-ext-pyramid/examples/simple.py index 4de1a3487..001743831 100644 --- a/contrib/opencensus-ext-pyramid/examples/simple.py +++ b/contrib/opencensus-ext-pyramid/examples/simple.py @@ -14,12 +14,8 @@ from wsgiref.simple_server import make_server -from opencensus.trace import config_integration -from opencensus.trace import print_exporter -from opencensus.trace import samplers - from app import main - +from opencensus.trace import config_integration, print_exporter, samplers config_integration.trace_integrations(['requests']) diff --git a/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/config.py b/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/config.py index ec2267677..2a119cfb2 100644 --- a/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/config.py +++ b/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/config.py @@ -12,8 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opencensus.trace import print_exporter -from opencensus.trace import samplers +from opencensus.trace import print_exporter, samplers from opencensus.trace.propagation import trace_context_http_header_format DEFAULT_PYRAMID_TRACER_CONFIG = { diff --git a/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/pyramid_middleware.py b/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/pyramid_middleware.py index e2ce58c6d..3b853ddc5 100644 --- a/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/pyramid_middleware.py +++ b/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/pyramid_middleware.py @@ -15,8 +15,7 @@ import logging from opencensus.ext.pyramid.config import PyramidTraceSettings -from opencensus.trace import attributes_helper -from opencensus.trace import execution_context +from opencensus.trace import attributes_helper, execution_context from opencensus.trace import span as span_module from opencensus.trace import tracer as tracer_module from opencensus.trace import utils diff --git a/contrib/opencensus-ext-pyramid/setup.py b/contrib/opencensus-ext-pyramid/setup.py index 189e42d68..7fcd90ef3 100644 --- a/contrib/opencensus-ext-pyramid/setup.py +++ b/contrib/opencensus-ext-pyramid/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-pyramid/tests/test_pyramid_config.py b/contrib/opencensus-ext-pyramid/tests/test_pyramid_config.py index d8fc35f1d..f31ad66e9 100644 --- a/contrib/opencensus-ext-pyramid/tests/test_pyramid_config.py +++ b/contrib/opencensus-ext-pyramid/tests/test_pyramid_config.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import unittest +import mock + from opencensus.ext.pyramid import config diff --git a/contrib/opencensus-ext-pyramid/tests/test_pyramid_middleware.py b/contrib/opencensus-ext-pyramid/tests/test_pyramid_middleware.py index 13df75ddd..deb58e4b5 100644 --- a/contrib/opencensus-ext-pyramid/tests/test_pyramid_middleware.py +++ b/contrib/opencensus-ext-pyramid/tests/test_pyramid_middleware.py @@ -18,20 +18,18 @@ import unittest import mock -from pyramid.registry import Registry -from pyramid.response import Response -from pyramid.testing import DummyRequest from opencensus.common.transports import sync from opencensus.ext.pyramid import pyramid_middleware from opencensus.ext.zipkin import trace_exporter as zipkin_exporter -from opencensus.trace import execution_context -from opencensus.trace import print_exporter -from opencensus.trace import samplers +from opencensus.trace import execution_context, print_exporter, samplers from opencensus.trace import span as span_module from opencensus.trace.blank_span import BlankSpan from opencensus.trace.propagation import trace_context_http_header_format from opencensus.trace.tracers import noop_tracer +from pyramid.registry import Registry +from pyramid.response import Response +from pyramid.testing import DummyRequest class TestPyramidMiddleware(unittest.TestCase): diff --git a/contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py b/contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py index 1118f57d6..1b04d4de1 100644 --- a/contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py +++ b/contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py @@ -13,18 +13,22 @@ # limitations under the License. import logging + import requests import wrapt +from opencensus.trace import ( + attributes_helper, + exceptions_status, + execution_context, +) +from opencensus.trace import span as span_module +from opencensus.trace import utils + try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse -from opencensus.trace import attributes_helper -from opencensus.trace import exceptions_status -from opencensus.trace import execution_context -from opencensus.trace import span as span_module -from opencensus.trace import utils log = logging.getLogger(__name__) diff --git a/contrib/opencensus-ext-requests/setup.py b/contrib/opencensus-ext-requests/setup.py index 3ee29bb18..37aca2d26 100644 --- a/contrib/opencensus-ext-requests/setup.py +++ b/contrib/opencensus-ext-requests/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-requests/tests/test_requests_trace.py b/contrib/opencensus-ext-requests/tests/test_requests_trace.py index 10554dfa5..8747e0ebe 100644 --- a/contrib/opencensus-ext-requests/tests/test_requests_trace.py +++ b/contrib/opencensus-ext-requests/tests/test_requests_trace.py @@ -15,12 +15,13 @@ import unittest import mock -import requests -from opencensus.trace.tracers import noop_tracer +import requests from opencensus.ext.requests import trace -from opencensus.trace import span as span_module, execution_context +from opencensus.trace import execution_context +from opencensus.trace import span as span_module from opencensus.trace import status as status_module +from opencensus.trace.tracers import noop_tracer class Test_requests_trace(unittest.TestCase): diff --git a/contrib/opencensus-ext-sqlalchemy/opencensus/ext/sqlalchemy/trace.py b/contrib/opencensus-ext-sqlalchemy/opencensus/ext/sqlalchemy/trace.py index 100170fe1..bba541106 100644 --- a/contrib/opencensus-ext-sqlalchemy/opencensus/ext/sqlalchemy/trace.py +++ b/contrib/opencensus-ext-sqlalchemy/opencensus/ext/sqlalchemy/trace.py @@ -14,9 +14,7 @@ import logging -from sqlalchemy import engine -from sqlalchemy import event - +from sqlalchemy import engine, event from opencensus.trace import execution_context from opencensus.trace import span as span_module diff --git a/contrib/opencensus-ext-sqlalchemy/setup.py b/contrib/opencensus-ext-sqlalchemy/setup.py index 3ac55a79e..30090c4f4 100644 --- a/contrib/opencensus-ext-sqlalchemy/setup.py +++ b/contrib/opencensus-ext-sqlalchemy/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-sqlalchemy/tests/test_sqlalchemy_trace.py b/contrib/opencensus-ext-sqlalchemy/tests/test_sqlalchemy_trace.py index 3f8f9ba06..9df47e415 100644 --- a/contrib/opencensus-ext-sqlalchemy/tests/test_sqlalchemy_trace.py +++ b/contrib/opencensus-ext-sqlalchemy/tests/test_sqlalchemy_trace.py @@ -16,8 +16,8 @@ import mock -from opencensus.trace import span as span_module from opencensus.ext.sqlalchemy import trace +from opencensus.trace import span as span_module class Test_sqlalchemy_trace(unittest.TestCase): diff --git a/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/stats_exporter/__init__.py b/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/stats_exporter/__init__.py index 7dee30e24..9249294ff 100644 --- a/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/stats_exporter/__init__.py +++ b/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/stats_exporter/__init__.py @@ -12,32 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime import itertools import os import platform import re import string import threading +from datetime import datetime +import google.auth from google.api_core.gapic_v1 import client_info from google.cloud import monitoring_v3 -import google.auth from opencensus.common import utils -from opencensus.common.monitored_resource import aws_identity_doc_utils -from opencensus.common.monitored_resource import gcp_metadata_config -from opencensus.common.monitored_resource import k8s_utils -from opencensus.common.monitored_resource import monitored_resource +from opencensus.common.monitored_resource import ( + aws_identity_doc_utils, + gcp_metadata_config, + k8s_utils, + monitored_resource, +) from opencensus.common.version import __version__ -from opencensus.metrics import label_key -from opencensus.metrics import label_value -from opencensus.metrics import transport +from opencensus.metrics import label_key, label_value, transport from opencensus.metrics.export import metric as metric_module from opencensus.metrics.export import metric_descriptor from opencensus.stats import stats - MAX_TIME_SERIES_PER_UPLOAD = 200 OPENCENSUS_TASK = "opencensus_task" OPENCENSUS_TASK_DESCRIPTION = "Opencensus task identifier" diff --git a/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py b/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py index b5dc999d7..8e07756cc 100644 --- a/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py +++ b/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py @@ -12,23 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -from collections import defaultdict import os +from collections import defaultdict from google.cloud.trace.client import Client -from opencensus.common.monitored_resource import aws_identity_doc_utils -from opencensus.common.monitored_resource import gcp_metadata_config -from opencensus.common.monitored_resource import k8s_utils -from opencensus.common.monitored_resource import monitored_resource +from opencensus.common.monitored_resource import ( + aws_identity_doc_utils, + gcp_metadata_config, + k8s_utils, + monitored_resource, +) from opencensus.common.transports import sync from opencensus.common.version import __version__ -from opencensus.trace import attributes_helper -from opencensus.trace import base_exporter -from opencensus.trace import span_data +from opencensus.trace import attributes_helper, base_exporter, span_data from opencensus.trace.attributes import Attributes - # Agent AGENT = 'opencensus-python [{}]'.format(__version__) diff --git a/contrib/opencensus-ext-stackdriver/setup.py b/contrib/opencensus-ext-stackdriver/setup.py index 808badb1f..7c4c8c926 100644 --- a/contrib/opencensus-ext-stackdriver/setup.py +++ b/contrib/opencensus-ext-stackdriver/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-stackdriver/tests/test_stackdriver_stats.py b/contrib/opencensus-ext-stackdriver/tests/test_stackdriver_stats.py index e7819ad54..fd3b517c6 100644 --- a/contrib/opencensus-ext-stackdriver/tests/test_stackdriver_stats.py +++ b/contrib/opencensus-ext-stackdriver/tests/test_stackdriver_stats.py @@ -12,24 +12,25 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime -import mock import unittest +from datetime import datetime -from google.cloud import monitoring_v3 import google.auth +import mock +from google.cloud import monitoring_v3 from opencensus.common import utils from opencensus.common.version import __version__ from opencensus.ext.stackdriver import stats_exporter as stackdriver -from opencensus.metrics import label_key -from opencensus.metrics import label_value +from opencensus.metrics import label_key, label_value from opencensus.metrics import transport as transport_module -from opencensus.metrics.export import metric -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import point -from opencensus.metrics.export import time_series -from opencensus.metrics.export import value +from opencensus.metrics.export import ( + metric, + metric_descriptor, + point, + time_series, + value, +) from opencensus.stats import aggregation as aggregation_module from opencensus.stats import aggregation_data as aggregation_data_module from opencensus.stats import execution_context diff --git a/contrib/opencensus-ext-threading/opencensus/ext/threading/trace.py b/contrib/opencensus-ext-threading/opencensus/ext/threading/trace.py index 33d0e7522..c2824aa4f 100644 --- a/contrib/opencensus-ext-threading/opencensus/ext/threading/trace.py +++ b/contrib/opencensus-ext-threading/opencensus/ext/threading/trace.py @@ -14,11 +14,10 @@ import logging import threading -from multiprocessing import pool from concurrent import futures +from multiprocessing import pool -from opencensus.trace import execution_context -from opencensus.trace import tracer +from opencensus.trace import execution_context, tracer from opencensus.trace.propagation import binary_format log = logging.getLogger(__name__) diff --git a/contrib/opencensus-ext-threading/setup.py b/contrib/opencensus-ext-threading/setup.py index 4d2e579df..963e01e89 100644 --- a/contrib/opencensus-ext-threading/setup.py +++ b/contrib/opencensus-ext-threading/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-threading/tests/test_threading_trace.py b/contrib/opencensus-ext-threading/tests/test_threading_trace.py index 47bd19b0f..6985f7b8b 100644 --- a/contrib/opencensus-ext-threading/tests/test_threading_trace.py +++ b/contrib/opencensus-ext-threading/tests/test_threading_trace.py @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest import threading -import mock -from multiprocessing.pool import Pool +import unittest from concurrent.futures import ThreadPoolExecutor +from multiprocessing.pool import Pool + +import mock from opencensus.ext.threading import trace from opencensus.trace import execution_context, tracer diff --git a/contrib/opencensus-ext-zipkin/opencensus/ext/zipkin/trace_exporter/__init__.py b/contrib/opencensus-ext-zipkin/opencensus/ext/zipkin/trace_exporter/__init__.py index 2333e0e0f..70c5cd56d 100644 --- a/contrib/opencensus-ext-zipkin/opencensus/ext/zipkin/trace_exporter/__init__.py +++ b/contrib/opencensus-ext-zipkin/opencensus/ext/zipkin/trace_exporter/__init__.py @@ -18,10 +18,8 @@ import logging import requests - from opencensus.common.transports import sync -from opencensus.common.utils import check_str_length -from opencensus.common.utils import timestamp_to_microseconds +from opencensus.common.utils import check_str_length, timestamp_to_microseconds from opencensus.trace import base_exporter DEFAULT_ENDPOINT = '/api/v2/spans' diff --git a/contrib/opencensus-ext-zipkin/setup.py b/contrib/opencensus-ext-zipkin/setup.py index e6f790eed..b9d24c277 100644 --- a/contrib/opencensus-ext-zipkin/setup.py +++ b/contrib/opencensus-ext-zipkin/setup.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup + from version import __version__ setup( diff --git a/contrib/opencensus-ext-zipkin/tests/test_zipkin_exporter.py b/contrib/opencensus-ext-zipkin/tests/test_zipkin_exporter.py index a7032532c..607d13c3c 100644 --- a/contrib/opencensus-ext-zipkin/tests/test_zipkin_exporter.py +++ b/contrib/opencensus-ext-zipkin/tests/test_zipkin_exporter.py @@ -13,9 +13,10 @@ # limitations under the License. import unittest +from datetime import datetime import mock -from datetime import datetime + from opencensus.ext.zipkin import trace_exporter from opencensus.trace import span_context from opencensus.trace import span_data as span_data_module diff --git a/examples/stats/helloworld/main.py b/examples/stats/helloworld/main.py index 5f65696ca..0d806cb41 100644 --- a/examples/stats/helloworld/main.py +++ b/examples/stats/helloworld/main.py @@ -16,6 +16,7 @@ import random import time +from pprint import pprint from opencensus.stats import aggregation as aggregation_module from opencensus.stats import measure as measure_module @@ -24,7 +25,6 @@ from opencensus.tags import tag_key as tag_key_module from opencensus.tags import tag_map as tag_map_module from opencensus.tags import tag_value as tag_value_module -from pprint import pprint MiB = 1 << 20 FRONTEND_KEY = tag_key_module.TagKey("my.org/keys/frontend") diff --git a/examples/trace/helloworld/main.py b/examples/trace/helloworld/main.py index 3336fb133..25732a357 100644 --- a/examples/trace/helloworld/main.py +++ b/examples/trace/helloworld/main.py @@ -14,9 +14,7 @@ import time -from opencensus.trace import execution_context -from opencensus.trace import print_exporter -from opencensus.trace import samplers +from opencensus.trace import execution_context, print_exporter, samplers from opencensus.trace.tracer import Tracer diff --git a/noxfile.py b/noxfile.py index e419f2f89..48e63b47b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -14,9 +14,10 @@ from __future__ import absolute_import -import nox import os +import nox + def _install_dev_packages(session): session.install('-e', 'context/opencensus-context') diff --git a/opencensus/common/backports/__init__.py b/opencensus/common/backports/__init__.py index 02c648c81..46fcc7d3a 100644 --- a/opencensus/common/backports/__init__.py +++ b/opencensus/common/backports/__init__.py @@ -13,6 +13,7 @@ # limitations under the License. import six + import weakref diff --git a/opencensus/common/monitored_resource/aws_identity_doc_utils.py b/opencensus/common/monitored_resource/aws_identity_doc_utils.py index 0b2b7ab98..bfa99c205 100644 --- a/opencensus/common/monitored_resource/aws_identity_doc_utils.py +++ b/opencensus/common/monitored_resource/aws_identity_doc_utils.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opencensus.common.http_handler import get_request import json +from opencensus.common.http_handler import get_request + REGION_KEY = 'region' ACCOUNT_ID_KEY = 'aws_account' INSTANCE_ID_KEY = 'instance_id' diff --git a/opencensus/common/monitored_resource/monitored_resource.py b/opencensus/common/monitored_resource/monitored_resource.py index c11b9996d..99e166804 100644 --- a/opencensus/common/monitored_resource/monitored_resource.py +++ b/opencensus/common/monitored_resource/monitored_resource.py @@ -13,10 +13,11 @@ # limitations under the License. from opencensus.common import resource -from opencensus.common.monitored_resource import aws_identity_doc_utils -from opencensus.common.monitored_resource import gcp_metadata_config -from opencensus.common.monitored_resource import k8s_utils - +from opencensus.common.monitored_resource import ( + aws_identity_doc_utils, + gcp_metadata_config, + k8s_utils, +) # Supported environments (resource types) _GCE_INSTANCE = "gce_instance" diff --git a/opencensus/common/resource/__init__.py b/opencensus/common/resource/__init__.py index 0b9507bc1..1a44a82ad 100644 --- a/opencensus/common/resource/__init__.py +++ b/opencensus/common/resource/__init__.py @@ -13,11 +13,10 @@ # limitations under the License. -from copy import copy import logging import os import re - +from copy import copy logger = logging.getLogger(__name__) diff --git a/opencensus/common/schedule/__init__.py b/opencensus/common/schedule/__init__.py index 580f229bd..719d89c25 100644 --- a/opencensus/common/schedule/__init__.py +++ b/opencensus/common/schedule/__init__.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from six.moves import queue + import threading import time -from six.moves import queue - class PeriodicTask(threading.Thread): """Thread that periodically calls a given function. diff --git a/opencensus/common/transports/async_.py b/opencensus/common/transports/async_.py index 61f3ea020..c5fe6a395 100644 --- a/opencensus/common/transports/async_.py +++ b/opencensus/common/transports/async_.py @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +from six.moves import queue, range + import atexit import logging import threading -from six.moves import queue -from six.moves import range - from opencensus.common.transports import base from opencensus.trace import execution_context diff --git a/opencensus/log/__init__.py b/opencensus/log/__init__.py index ddf84f83b..ce4ce5f57 100644 --- a/opencensus/log/__init__.py +++ b/opencensus/log/__init__.py @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging from collections import namedtuple from copy import copy -import logging from opencensus.trace import execution_context - _meta_logger = logging.getLogger(__name__) TRACE_ID_KEY = 'traceId' diff --git a/opencensus/metrics/export/cumulative.py b/opencensus/metrics/export/cumulative.py index 921dd3593..5c2a45aeb 100644 --- a/opencensus/metrics/export/cumulative.py +++ b/opencensus/metrics/export/cumulative.py @@ -14,8 +14,7 @@ import six -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import gauge +from opencensus.metrics.export import gauge, metric_descriptor class CumulativePointLong(gauge.GaugePointLong): diff --git a/opencensus/metrics/export/gauge.py b/opencensus/metrics/export/gauge.py index ff5520809..10b35419e 100644 --- a/opencensus/metrics/export/gauge.py +++ b/opencensus/metrics/export/gauge.py @@ -12,15 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -from collections import OrderedDict -from datetime import datetime import six + import threading +from collections import OrderedDict +from datetime import datetime from opencensus.common import utils -from opencensus.metrics.export import metric -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import metric_producer +from opencensus.metrics.export import ( + metric, + metric_descriptor, + metric_producer, +) from opencensus.metrics.export import point as point_module from opencensus.metrics.export import time_series from opencensus.metrics.export import value as value_module diff --git a/opencensus/metrics/transport.py b/opencensus/metrics/transport.py index 02579b279..77728246a 100644 --- a/opencensus/metrics/transport.py +++ b/opencensus/metrics/transport.py @@ -19,7 +19,6 @@ from opencensus.common.schedule import PeriodicTask from opencensus.trace import execution_context - logger = logging.getLogger(__name__) DEFAULT_INTERVAL = 60 diff --git a/opencensus/stats/aggregation.py b/opencensus/stats/aggregation.py index d6a6fd4d8..acaa564f7 100644 --- a/opencensus/stats/aggregation.py +++ b/opencensus/stats/aggregation.py @@ -14,10 +14,9 @@ import logging +from opencensus.metrics.export.metric_descriptor import MetricDescriptorType from opencensus.stats import aggregation_data from opencensus.stats import measure as measure_module -from opencensus.metrics.export.metric_descriptor import MetricDescriptorType - logger = logging.getLogger(__name__) diff --git a/opencensus/stats/aggregation_data.py b/opencensus/stats/aggregation_data.py index 2f54fae33..7fa3f9ac5 100644 --- a/opencensus/stats/aggregation_data.py +++ b/opencensus/stats/aggregation_data.py @@ -15,11 +15,9 @@ import copy import logging -from opencensus.metrics.export import point -from opencensus.metrics.export import value +from opencensus.metrics.export import point, value from opencensus.stats import bucket_boundaries - logger = logging.getLogger(__name__) diff --git a/opencensus/stats/measure_to_view_map.py b/opencensus/stats/measure_to_view_map.py index e127272b5..47863e328 100644 --- a/opencensus/stats/measure_to_view_map.py +++ b/opencensus/stats/measure_to_view_map.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from collections import defaultdict import copy import logging +from collections import defaultdict from opencensus.stats import metric_utils from opencensus.stats import view_data as view_data_module diff --git a/opencensus/stats/measurement_map.py b/opencensus/stats/measurement_map.py index 0df811f37..c41ab5ce4 100644 --- a/opencensus/stats/measurement_map.py +++ b/opencensus/stats/measurement_map.py @@ -17,7 +17,6 @@ from opencensus.common import utils from opencensus.tags import TagContext - logger = logging.getLogger(__name__) diff --git a/opencensus/stats/metric_utils.py b/opencensus/stats/metric_utils.py index 912083e52..4cd8ec6a7 100644 --- a/opencensus/stats/metric_utils.py +++ b/opencensus/stats/metric_utils.py @@ -16,9 +16,7 @@ """ from opencensus.metrics import label_value -from opencensus.metrics.export import metric -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import time_series +from opencensus.metrics.export import metric, metric_descriptor, time_series def is_gauge(md_type): diff --git a/opencensus/stats/stats_recorder.py b/opencensus/stats/stats_recorder.py index 8ea04daf8..f74b6d3b7 100644 --- a/opencensus/stats/stats_recorder.py +++ b/opencensus/stats/stats_recorder.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opencensus.stats.measurement_map import MeasurementMap -from opencensus.stats.measure_to_view_map import MeasureToViewMap from opencensus.stats import execution_context +from opencensus.stats.measure_to_view_map import MeasureToViewMap +from opencensus.stats.measurement_map import MeasurementMap class StatsRecorder(object): diff --git a/opencensus/stats/view_manager.py b/opencensus/stats/view_manager.py index 2afaea22c..3b118a11d 100644 --- a/opencensus/stats/view_manager.py +++ b/opencensus/stats/view_manager.py @@ -13,8 +13,8 @@ # limitations under the License. from opencensus.common import utils -from opencensus.stats.measure_to_view_map import MeasureToViewMap from opencensus.stats import execution_context +from opencensus.stats.measure_to_view_map import MeasureToViewMap class ViewManager(object): diff --git a/opencensus/tags/__init__.py b/opencensus/tags/__init__.py index 771d4c255..e4a064695 100644 --- a/opencensus/tags/__init__.py +++ b/opencensus/tags/__init__.py @@ -15,8 +15,8 @@ from opencensus.common.runtime_context import RuntimeContext from opencensus.tags.tag import Tag from opencensus.tags.tag_key import TagKey -from opencensus.tags.tag_value import TagValue from opencensus.tags.tag_map import TagMap +from opencensus.tags.tag_value import TagValue __all__ = ['Tag', 'TagContext', 'TagKey', 'TagValue', 'TagMap'] diff --git a/opencensus/tags/propagation/binary_serializer.py b/opencensus/tags/propagation/binary_serializer.py index 01ed717f2..49c84925a 100644 --- a/opencensus/tags/propagation/binary_serializer.py +++ b/opencensus/tags/propagation/binary_serializer.py @@ -14,9 +14,10 @@ # -*- coding: utf-8 -*- -import logging import six +import logging + from google.protobuf.internal.encoder import _VarintBytes from opencensus.tags import tag_map as tag_map_module diff --git a/opencensus/tags/tag.py b/opencensus/tags/tag.py index e5044c04d..4f78ac833 100644 --- a/opencensus/tags/tag.py +++ b/opencensus/tags/tag.py @@ -13,6 +13,7 @@ # limitations under the License. from collections import namedtuple + from opencensus.tags.tag_key import TagKey from opencensus.tags.tag_value import TagValue diff --git a/opencensus/trace/__init__.py b/opencensus/trace/__init__.py index b1bbded81..a55903b90 100644 --- a/opencensus/trace/__init__.py +++ b/opencensus/trace/__init__.py @@ -14,5 +14,4 @@ from opencensus.trace.span import Span - __all__ = ['Span'] diff --git a/opencensus/trace/exceptions_status.py b/opencensus/trace/exceptions_status.py index a57bdec60..00542d0c6 100644 --- a/opencensus/trace/exceptions_status.py +++ b/opencensus/trace/exceptions_status.py @@ -13,6 +13,7 @@ # limitations under the License. from google.rpc import code_pb2 + from opencensus.trace.status import Status CANCELLED = Status(code_pb2.CANCELLED) diff --git a/opencensus/trace/file_exporter.py b/opencensus/trace/file_exporter.py index 22eb9b738..baaeaddfc 100644 --- a/opencensus/trace/file_exporter.py +++ b/opencensus/trace/file_exporter.py @@ -17,8 +17,7 @@ import json from opencensus.common.transports import sync -from opencensus.trace import base_exporter -from opencensus.trace import span_data +from opencensus.trace import base_exporter, span_data DEFAULT_FILENAME = 'opencensus-traces.json' diff --git a/opencensus/trace/logging_exporter.py b/opencensus/trace/logging_exporter.py index f232e3512..e727f602c 100644 --- a/opencensus/trace/logging_exporter.py +++ b/opencensus/trace/logging_exporter.py @@ -17,8 +17,7 @@ import logging from opencensus.common.transports import sync -from opencensus.trace import base_exporter -from opencensus.trace import span_data +from opencensus.trace import base_exporter, span_data class LoggingExporter(base_exporter.Exporter): diff --git a/opencensus/trace/propagation/b3_format.py b/opencensus/trace/propagation/b3_format.py index cd175efa5..b60dcd8a1 100644 --- a/opencensus/trace/propagation/b3_format.py +++ b/opencensus/trace/propagation/b3_format.py @@ -13,7 +13,7 @@ # limitations under the License. -from opencensus.trace.span_context import SpanContext, INVALID_SPAN_ID +from opencensus.trace.span_context import INVALID_SPAN_ID, SpanContext from opencensus.trace.trace_options import TraceOptions _STATE_HEADER_KEY = 'b3' diff --git a/opencensus/trace/propagation/trace_context_http_header_format.py b/opencensus/trace/propagation/trace_context_http_header_format.py index 4b7afa100..095935a2e 100644 --- a/opencensus/trace/propagation/trace_context_http_header_format.py +++ b/opencensus/trace/propagation/trace_context_http_header_format.py @@ -14,10 +14,11 @@ import re +from opencensus.trace.propagation.tracestate_string_format import ( + TracestateStringFormatter, +) from opencensus.trace.span_context import SpanContext from opencensus.trace.trace_options import TraceOptions -from opencensus.trace.propagation.tracestate_string_format \ - import TracestateStringFormatter _TRACEPARENT_HEADER_NAME = 'traceparent' _TRACESTATE_HEADER_NAME = 'tracestate' diff --git a/opencensus/trace/propagation/tracestate_string_format.py b/opencensus/trace/propagation/tracestate_string_format.py index da2882880..9a7af86a5 100644 --- a/opencensus/trace/propagation/tracestate_string_format.py +++ b/opencensus/trace/propagation/tracestate_string_format.py @@ -13,9 +13,8 @@ # limitations under the License. import re -from opencensus.trace.tracestate import Tracestate -from opencensus.trace.tracestate import _KEY_FORMAT -from opencensus.trace.tracestate import _VALUE_FORMAT + +from opencensus.trace.tracestate import _KEY_FORMAT, _VALUE_FORMAT, Tracestate _DELIMITER_FORMAT = '[ \t]*,[ \t]*' _MEMBER_FORMAT = '(%s)(=)(%s)' % (_KEY_FORMAT, _VALUE_FORMAT) diff --git a/opencensus/trace/span.py b/opencensus/trace/span.py index cb8e42dae..04aa376e7 100644 --- a/opencensus/trace/span.py +++ b/opencensus/trace/span.py @@ -19,11 +19,10 @@ from collections import MutableMapping from collections import Sequence -from collections import OrderedDict -from collections import deque +import threading +from collections import OrderedDict, deque from datetime import datetime from itertools import chain -import threading from opencensus.common import utils from opencensus.trace import attributes as attributes_module @@ -35,7 +34,6 @@ from opencensus.trace.span_context import generate_span_id from opencensus.trace.tracers import base - # https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/TraceConfig.md # noqa MAX_NUM_ATTRIBUTES = 32 MAX_NUM_ANNOTATIONS = 32 diff --git a/opencensus/trace/span_context.py b/opencensus/trace/span_context.py index 3bd501fd9..24fc216f1 100644 --- a/opencensus/trace/span_context.py +++ b/opencensus/trace/span_context.py @@ -14,10 +14,11 @@ """SpanContext encapsulates the current context within the request's trace.""" -import logging -import re import six + +import logging import random +import re from opencensus.trace import trace_options as trace_options_module diff --git a/opencensus/trace/tracer.py b/opencensus/trace/tracer.py index 3981b3db7..71b7a4646 100644 --- a/opencensus/trace/tracer.py +++ b/opencensus/trace/tracer.py @@ -12,13 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opencensus.trace import execution_context -from opencensus.trace import print_exporter -from opencensus.trace import samplers +from opencensus.trace import execution_context, print_exporter, samplers from opencensus.trace.propagation import trace_context_http_header_format from opencensus.trace.span_context import SpanContext -from opencensus.trace.tracers import context_tracer -from opencensus.trace.tracers import noop_tracer +from opencensus.trace.tracers import context_tracer, noop_tracer class Tracer(object): diff --git a/opencensus/trace/tracers/context_tracer.py b/opencensus/trace/tracers/context_tracer.py index 331a26661..4a6153a92 100644 --- a/opencensus/trace/tracers/context_tracer.py +++ b/opencensus/trace/tracers/context_tracer.py @@ -15,11 +15,10 @@ import logging import threading -from opencensus.trace import execution_context -from opencensus.trace.span_context import SpanContext -from opencensus.trace import print_exporter +from opencensus.trace import execution_context, print_exporter from opencensus.trace import span as trace_span from opencensus.trace import span_data as span_data_module +from opencensus.trace.span_context import SpanContext from opencensus.trace.tracers import base diff --git a/opencensus/trace/tracers/noop_tracer.py b/opencensus/trace/tracers/noop_tracer.py index 2a4b326ff..b61fab53c 100644 --- a/opencensus/trace/tracers/noop_tracer.py +++ b/opencensus/trace/tracers/noop_tracer.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opencensus.trace.tracers import base from opencensus.trace import blank_span as trace_span -from opencensus.trace.span_context import SpanContext from opencensus.trace import trace_options +from opencensus.trace.span_context import SpanContext +from opencensus.trace.tracers import base class NoopTracer(base.Tracer): diff --git a/opencensus/trace/tracestate.py b/opencensus/trace/tracestate.py index 8e328140e..f9110eec9 100644 --- a/opencensus/trace/tracestate.py +++ b/opencensus/trace/tracestate.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from collections import OrderedDict import re +from collections import OrderedDict _KEY_WITHOUT_VENDOR_FORMAT = r'[a-z][_0-9a-z\-\*\/]{0,255}' _KEY_WITH_VENDOR_FORMAT = \ diff --git a/opencensus/trace/utils.py b/opencensus/trace/utils.py index 93add22d5..7aabf73ab 100644 --- a/opencensus/trace/utils.py +++ b/opencensus/trace/utils.py @@ -15,6 +15,7 @@ import re from google.rpc import code_pb2 + from opencensus.trace import execution_context from opencensus.trace.status import Status diff --git a/setup.py b/setup.py index 0b9761871..c060e343d 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,7 @@ # limitations under the License. """A setup module for OpenCensus Instrumentation Library""" -from setuptools import find_packages -from setuptools import setup +from setuptools import find_packages, setup exec(open('opencensus/common/version/__init__.py').read()) diff --git a/tests/system/stats/stackdriver/stackdriver_stats_test.py b/tests/system/stats/stackdriver/stackdriver_stats_test.py index a18291b37..783a2d252 100644 --- a/tests/system/stats/stackdriver/stackdriver_stats_test.py +++ b/tests/system/stats/stackdriver/stackdriver_stats_test.py @@ -17,8 +17,8 @@ import sys import time -from google.cloud import monitoring_v3 import mock +from google.cloud import monitoring_v3 from opencensus.ext.stackdriver import stats_exporter as stackdriver from opencensus.metrics import transport diff --git a/tests/system/trace/django/app/urls.py b/tests/system/trace/django/app/urls.py index 9eda96a51..474b92037 100644 --- a/tests/system/trace/django/app/urls.py +++ b/tests/system/trace/django/app/urls.py @@ -27,12 +27,10 @@ 1. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) """ +import app.views from django.conf.urls import url from django.contrib import admin -import app.views - - urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', app.views.home), diff --git a/tests/system/trace/django/app/views.py b/tests/system/trace/django/app/views.py index 39873e338..9f03bab30 100644 --- a/tests/system/trace/django/app/views.py +++ b/tests/system/trace/django/app/views.py @@ -12,18 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -from django.http import HttpResponse -from django.shortcuts import render - -from .forms import HelloForm - -from opencensus.trace import config_integration +import os -import mysql.connector import psycopg2 import sqlalchemy -import os +import mysql.connector +from django.http import HttpResponse +from django.shortcuts import render +from opencensus.trace import config_integration + +from .forms import HelloForm DB_HOST = 'localhost' diff --git a/tests/system/trace/django/django_system_test.py b/tests/system/trace/django/django_system_test.py index 4dba05db4..c8a101683 100644 --- a/tests/system/trace/django/django_system_test.py +++ b/tests/system/trace/django/django_system_test.py @@ -13,15 +13,14 @@ # limitations under the License. import os -import requests import signal import subprocess +import unittest import uuid +import requests from retrying import retry -import unittest - PROJECT = os.environ.get('GCLOUD_PROJECT_PYTHON') HOST_PORT = 'localhost:8000' diff --git a/tests/system/trace/flask/flask_system_test.py b/tests/system/trace/flask/flask_system_test.py index e89f66aa5..7cf97ebb9 100644 --- a/tests/system/trace/flask/flask_system_test.py +++ b/tests/system/trace/flask/flask_system_test.py @@ -13,15 +13,14 @@ # limitations under the License. import os -import requests import signal import subprocess +import unittest import uuid +import requests from retrying import retry -import unittest - PROJECT = os.environ.get('GCLOUD_PROJECT_PYTHON') HOST_PORT = 'localhost:8080' diff --git a/tests/system/trace/flask/main.py b/tests/system/trace/flask/main.py index 64f579e85..e6b93af83 100644 --- a/tests/system/trace/flask/main.py +++ b/tests/system/trace/flask/main.py @@ -14,11 +14,11 @@ import os -import flask -import mysql.connector import psycopg2 import sqlalchemy +import flask +import mysql.connector from opencensus.common.transports import async_ from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.ext.stackdriver import trace_exporter as stackdriver_exporter diff --git a/tests/unit/common/monitored_resource_util/test_aws_identity_doc_utils.py b/tests/unit/common/monitored_resource_util/test_aws_identity_doc_utils.py index 73f031f45..5658b862e 100644 --- a/tests/unit/common/monitored_resource_util/test_aws_identity_doc_utils.py +++ b/tests/unit/common/monitored_resource_util/test_aws_identity_doc_utils.py @@ -13,9 +13,10 @@ # limitations under the License. import json -import mock import unittest +import mock + from opencensus.common.monitored_resource import aws_identity_doc_utils diff --git a/tests/unit/common/monitored_resource_util/test_gcp_metadata_config.py b/tests/unit/common/monitored_resource_util/test_gcp_metadata_config.py index 10c97776f..d636bcf77 100644 --- a/tests/unit/common/monitored_resource_util/test_gcp_metadata_config.py +++ b/tests/unit/common/monitored_resource_util/test_gcp_metadata_config.py @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import os import unittest +import mock + from opencensus.common.monitored_resource import gcp_metadata_config diff --git a/tests/unit/common/monitored_resource_util/test_monitored_resource.py b/tests/unit/common/monitored_resource_util/test_monitored_resource.py index 4cbe537d2..38a1fe4b5 100644 --- a/tests/unit/common/monitored_resource_util/test_monitored_resource.py +++ b/tests/unit/common/monitored_resource_util/test_monitored_resource.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from contextlib import contextmanager import os import sys +from contextlib import contextmanager import mock diff --git a/tests/unit/common/test_http_handler.py b/tests/unit/common/test_http_handler.py index 83f86b66f..cfabbc066 100644 --- a/tests/unit/common/test_http_handler.py +++ b/tests/unit/common/test_http_handler.py @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +import json import socket +import unittest + import mock -import json from opencensus.common.http_handler import get_request diff --git a/tests/unit/common/test_schedule.py b/tests/unit/common/test_schedule.py index a6d69b075..4fd85be0a 100644 --- a/tests/unit/common/test_schedule.py +++ b/tests/unit/common/test_schedule.py @@ -14,9 +14,7 @@ import unittest -from opencensus.common.schedule import PeriodicTask -from opencensus.common.schedule import Queue -from opencensus.common.schedule import QueueEvent +from opencensus.common.schedule import PeriodicTask, Queue, QueueEvent TIMEOUT = .1 diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py index 42fc9c57f..49419afa9 100644 --- a/tests/unit/common/test_utils.py +++ b/tests/unit/common/test_utils.py @@ -26,10 +26,11 @@ from opencensus.common.backports import WeakMethod import gc -import mock import unittest import weakref +import mock + from opencensus.common import utils diff --git a/tests/unit/common/transports/test_sync.py b/tests/unit/common/transports/test_sync.py index 71cce563b..c812b025e 100644 --- a/tests/unit/common/transports/test_sync.py +++ b/tests/unit/common/transports/test_sync.py @@ -13,7 +13,9 @@ # limitations under the License. import unittest + import mock + from opencensus.common.transports import sync diff --git a/tests/unit/log/test_log.py b/tests/unit/log/test_log.py index b1cde14eb..528d9e7bd 100644 --- a/tests/unit/log/test_log.py +++ b/tests/unit/log/test_log.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from contextlib import contextmanager import logging import sys +from contextlib import contextmanager import mock diff --git a/tests/unit/metrics/export/test_cumulative.py b/tests/unit/metrics/export/test_cumulative.py index a11b67c45..0a7dc4ebb 100644 --- a/tests/unit/metrics/export/test_cumulative.py +++ b/tests/unit/metrics/export/test_cumulative.py @@ -16,9 +16,7 @@ from mock import Mock -from opencensus.metrics.export import cumulative -from opencensus.metrics.export import gauge -from opencensus.metrics.export import metric_descriptor +from opencensus.metrics.export import cumulative, gauge, metric_descriptor from opencensus.metrics.export import value as value_module diff --git a/tests/unit/metrics/export/test_gauge.py b/tests/unit/metrics/export/test_gauge.py index 2fa1a6afe..59fafd5ef 100644 --- a/tests/unit/metrics/export/test_gauge.py +++ b/tests/unit/metrics/export/test_gauge.py @@ -17,8 +17,7 @@ from mock import Mock -from opencensus.metrics.export import gauge -from opencensus.metrics.export import metric_descriptor +from opencensus.metrics.export import gauge, metric_descriptor from opencensus.metrics.export import value as value_module diff --git a/tests/unit/metrics/export/test_metric.py b/tests/unit/metrics/export/test_metric.py index 610f08a22..730ff1792 100644 --- a/tests/unit/metrics/export/test_metric.py +++ b/tests/unit/metrics/export/test_metric.py @@ -19,9 +19,7 @@ import unittest -from opencensus.metrics.export import metric -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import time_series +from opencensus.metrics.export import metric, metric_descriptor, time_series class TestMetric(unittest.TestCase): diff --git a/tests/unit/metrics/export/test_metric_descriptor.py b/tests/unit/metrics/export/test_metric_descriptor.py index 2a5f7b80c..ff79a3d3c 100644 --- a/tests/unit/metrics/export/test_metric_descriptor.py +++ b/tests/unit/metrics/export/test_metric_descriptor.py @@ -17,8 +17,7 @@ import unittest from opencensus.metrics import label_key -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import value +from opencensus.metrics.export import metric_descriptor, value NAME = 'metric' DESCRIPTION = 'Metric description' diff --git a/tests/unit/metrics/export/test_point.py b/tests/unit/metrics/export/test_point.py index 637c02201..76a937d4f 100644 --- a/tests/unit/metrics/export/test_point.py +++ b/tests/unit/metrics/export/test_point.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest + from opencensus.metrics.export import point as point_module from opencensus.metrics.export import summary as summary_module from opencensus.metrics.export import value as value_module diff --git a/tests/unit/metrics/export/test_summary.py b/tests/unit/metrics/export/test_summary.py index cd7984c58..82c2bdedc 100644 --- a/tests/unit/metrics/export/test_summary.py +++ b/tests/unit/metrics/export/test_summary.py @@ -13,6 +13,7 @@ # limitations under the License. from six import assertRaisesRegex + import unittest from opencensus.metrics.export import summary as summary_module diff --git a/tests/unit/metrics/export/test_time_series.py b/tests/unit/metrics/export/test_time_series.py index b3948361a..57c0ef4aa 100644 --- a/tests/unit/metrics/export/test_time_series.py +++ b/tests/unit/metrics/export/test_time_series.py @@ -17,9 +17,7 @@ import unittest from opencensus.metrics import label_value -from opencensus.metrics.export import point -from opencensus.metrics.export import time_series -from opencensus.metrics.export import value +from opencensus.metrics.export import point, time_series, value START_TIMESTAMP = '2018-10-09T22:33:44.012345Z' LABEL_VALUE1 = label_value.LabelValue('value one') diff --git a/tests/unit/metrics/test_label_key.py b/tests/unit/metrics/test_label_key.py index 5a685e2e2..80c63cace 100644 --- a/tests/unit/metrics/test_label_key.py +++ b/tests/unit/metrics/test_label_key.py @@ -15,6 +15,7 @@ # limitations under the License. import unittest + from opencensus.metrics import label_key as label_key_module diff --git a/tests/unit/metrics/test_label_value.py b/tests/unit/metrics/test_label_value.py index 7af9f2d19..8fe463cd2 100644 --- a/tests/unit/metrics/test_label_value.py +++ b/tests/unit/metrics/test_label_value.py @@ -15,6 +15,7 @@ # limitations under the License. import unittest + from opencensus.metrics import label_value as label_value_module diff --git a/tests/unit/stats/test_aggregation.py b/tests/unit/stats/test_aggregation.py index ca03ced14..671c1910d 100644 --- a/tests/unit/stats/test_aggregation.py +++ b/tests/unit/stats/test_aggregation.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import unittest +import mock + +from opencensus.metrics.export import value from opencensus.stats import aggregation as aggregation_module from opencensus.stats import measure as measure_module -from opencensus.metrics.export import value class TestSumAggregation(unittest.TestCase): diff --git a/tests/unit/stats/test_aggregation_data.py b/tests/unit/stats/test_aggregation_data.py index ceb5f0e4a..d1870f2c9 100644 --- a/tests/unit/stats/test_aggregation_data.py +++ b/tests/unit/stats/test_aggregation_data.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime import time import unittest +from datetime import datetime import mock diff --git a/tests/unit/stats/test_base_stats.py b/tests/unit/stats/test_base_stats.py index 78723f36b..1d403c7dc 100644 --- a/tests/unit/stats/test_base_stats.py +++ b/tests/unit/stats/test_base_stats.py @@ -13,7 +13,9 @@ # limitations under the License. import unittest + import mock + from opencensus.stats import base_exporter diff --git a/tests/unit/stats/test_measure_to_view_map.py b/tests/unit/stats/test_measure_to_view_map.py index 4beb0cb98..a754baf04 100644 --- a/tests/unit/stats/test_measure_to_view_map.py +++ b/tests/unit/stats/test_measure_to_view_map.py @@ -18,13 +18,11 @@ from opencensus.stats import measure_to_view_map as measure_to_view_map_module from opencensus.stats.aggregation import CountAggregation -from opencensus.stats.measure import BaseMeasure -from opencensus.stats.measure import MeasureInt +from opencensus.stats.measure import BaseMeasure, MeasureInt from opencensus.stats.view import View from opencensus.stats.view_data import ViewData from opencensus.tags import tag_key as tag_key_module - METHOD_KEY = tag_key_module.TagKey("method") REQUEST_COUNT_MEASURE = MeasureInt( "request_count", "number of requests", "1") diff --git a/tests/unit/stats/test_measurement.py b/tests/unit/stats/test_measurement.py index 431c96863..3780a8657 100644 --- a/tests/unit/stats/test_measurement.py +++ b/tests/unit/stats/test_measurement.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opencensus.stats import measurement as measurement_module - import unittest +from opencensus.stats import measurement as measurement_module + class TestMeasurement(unittest.TestCase): def test_constructor(self): diff --git a/tests/unit/stats/test_measurement_map.py b/tests/unit/stats/test_measurement_map.py index ee103771f..89add276b 100644 --- a/tests/unit/stats/test_measurement_map.py +++ b/tests/unit/stats/test_measurement_map.py @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock import unittest +import mock + from opencensus.stats import measurement_map as measurement_map_module -from opencensus.tags import Tag -from opencensus.tags import TagContext -from opencensus.tags import TagMap +from opencensus.tags import Tag, TagContext, TagMap logger_patch = mock.patch('opencensus.stats.measurement_map.logger') diff --git a/tests/unit/stats/test_metric_utils.py b/tests/unit/stats/test_metric_utils.py index 2ec3e41a0..355f0da2e 100644 --- a/tests/unit/stats/test_metric_utils.py +++ b/tests/unit/stats/test_metric_utils.py @@ -17,17 +17,16 @@ import mock -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import point -from opencensus.metrics.export import value -from opencensus.stats import aggregation -from opencensus.stats import aggregation_data -from opencensus.stats import measure -from opencensus.stats import metric_utils -from opencensus.stats import view -from opencensus.stats import view_data -from opencensus.tags import tag_key -from opencensus.tags import tag_value +from opencensus.metrics.export import metric_descriptor, point, value +from opencensus.stats import ( + aggregation, + aggregation_data, + measure, + metric_utils, + view, + view_data, +) +from opencensus.tags import tag_key, tag_value class TestMetricUtils(unittest.TestCase): diff --git a/tests/unit/stats/test_stats.py b/tests/unit/stats/test_stats.py index e3d3f378a..e120ac499 100644 --- a/tests/unit/stats/test_stats.py +++ b/tests/unit/stats/test_stats.py @@ -19,10 +19,8 @@ import unittest -from opencensus.metrics.export import metric_descriptor -from opencensus.metrics.export import value -from opencensus.stats import aggregation -from opencensus.stats import measure +from opencensus.metrics.export import metric_descriptor, value +from opencensus.stats import aggregation, measure from opencensus.stats import stats as stats_module from opencensus.stats import view from opencensus.tags import tag_map diff --git a/tests/unit/stats/test_stats_recorder.py b/tests/unit/stats/test_stats_recorder.py index e23b1ae82..ce22597e9 100644 --- a/tests/unit/stats/test_stats_recorder.py +++ b/tests/unit/stats/test_stats_recorder.py @@ -13,10 +13,12 @@ # limitations under the License. import unittest + import mock + +from opencensus.stats import execution_context from opencensus.stats import stats_recorder as stats_recorder_module from opencensus.stats.measurement_map import MeasurementMap -from opencensus.stats import execution_context class TestStatsRecorder(unittest.TestCase): diff --git a/tests/unit/stats/test_view.py b/tests/unit/stats/test_view.py index 408580e44..011eb7087 100644 --- a/tests/unit/stats/test_view.py +++ b/tests/unit/stats/test_view.py @@ -13,12 +13,11 @@ # limitations under the License. import unittest + import mock from opencensus.metrics.export import metric_descriptor -from opencensus.stats import aggregation -from opencensus.stats import measure -from opencensus.stats import view +from opencensus.stats import aggregation, measure from opencensus.stats import view as view_module diff --git a/tests/unit/stats/test_view_data.py b/tests/unit/stats/test_view_data.py index 6454c768b..87791802a 100644 --- a/tests/unit/stats/test_view_data.py +++ b/tests/unit/stats/test_view_data.py @@ -12,15 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +import unittest from datetime import datetime + import mock -import unittest from opencensus.common import utils from opencensus.stats import aggregation as aggregation_module from opencensus.stats import measure as measure_module -from opencensus.stats import view_data as view_data_module from opencensus.stats import view as view_module +from opencensus.stats import view_data as view_data_module class TestViewData(unittest.TestCase): diff --git a/tests/unit/stats/test_view_manager.py b/tests/unit/stats/test_view_manager.py index ded2ecc74..b6dea72bc 100644 --- a/tests/unit/stats/test_view_manager.py +++ b/tests/unit/stats/test_view_manager.py @@ -13,9 +13,11 @@ # limitations under the License. import unittest + import mock -from opencensus.stats import view_manager as view_manager_module + from opencensus.stats import execution_context +from opencensus.stats import view_manager as view_manager_module from opencensus.stats.measure_to_view_map import MeasureToViewMap diff --git a/tests/unit/tags/test_tag.py b/tests/unit/tags/test_tag.py index 21c5d0eb3..6deac8fc5 100644 --- a/tests/unit/tags/test_tag.py +++ b/tests/unit/tags/test_tag.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest + from opencensus.tags import Tag diff --git a/tests/unit/tags/test_tag_value.py b/tests/unit/tags/test_tag_value.py index f5aa0b771..dfd10d565 100644 --- a/tests/unit/tags/test_tag_value.py +++ b/tests/unit/tags/test_tag_value.py @@ -15,6 +15,7 @@ # limitations under the License. import unittest + from opencensus.tags import TagValue diff --git a/tests/unit/trace/exporters/test_logging_exporter.py b/tests/unit/trace/exporters/test_logging_exporter.py index 36ca52795..4dd45e938 100644 --- a/tests/unit/trace/exporters/test_logging_exporter.py +++ b/tests/unit/trace/exporters/test_logging_exporter.py @@ -17,8 +17,7 @@ import mock -from opencensus.trace import logging_exporter -from opencensus.trace import span_context +from opencensus.trace import logging_exporter, span_context from opencensus.trace import span_data as span_data_module diff --git a/tests/unit/trace/propagation/test_b3_format.py b/tests/unit/trace/propagation/test_b3_format.py index 75ce604ed..68feb20f0 100644 --- a/tests/unit/trace/propagation/test_b3_format.py +++ b/tests/unit/trace/propagation/test_b3_format.py @@ -13,10 +13,11 @@ # limitations under the License. import unittest + import mock -from opencensus.trace.span_context import INVALID_SPAN_ID from opencensus.trace.propagation import b3_format +from opencensus.trace.span_context import INVALID_SPAN_ID class TestB3FormatPropagator(unittest.TestCase): diff --git a/tests/unit/trace/test_base_span.py b/tests/unit/trace/test_base_span.py index f6477e8a0..d27bc6826 100644 --- a/tests/unit/trace/test_base_span.py +++ b/tests/unit/trace/test_base_span.py @@ -13,7 +13,9 @@ # limitations under the License. import unittest + import mock + from opencensus.trace.base_span import BaseSpan diff --git a/tests/unit/trace/test_blank_span.py b/tests/unit/trace/test_blank_span.py index c0bf333c7..d9d1e1c15 100644 --- a/tests/unit/trace/test_blank_span.py +++ b/tests/unit/trace/test_blank_span.py @@ -13,13 +13,14 @@ # limitations under the License. import datetime -import mock import unittest +import mock + from opencensus.common import utils from opencensus.trace.link import Link -from opencensus.trace.status import Status from opencensus.trace.span import format_span_json +from opencensus.trace.status import Status from opencensus.trace.time_event import MessageEvent diff --git a/tests/unit/trace/test_exceptions_status.py b/tests/unit/trace/test_exceptions_status.py index 1b3f7e963..2d17349db 100644 --- a/tests/unit/trace/test_exceptions_status.py +++ b/tests/unit/trace/test_exceptions_status.py @@ -15,6 +15,7 @@ import unittest from google.rpc import code_pb2 + from opencensus.trace import exceptions_status diff --git a/tests/unit/trace/test_execution_context.py b/tests/unit/trace/test_execution_context.py index 5f884b9fc..9df5e7d1f 100644 --- a/tests/unit/trace/test_execution_context.py +++ b/tests/unit/trace/test_execution_context.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import threading import unittest + import mock -import threading from opencensus.trace import execution_context diff --git a/tests/unit/trace/test_ext_utils.py b/tests/unit/trace/test_ext_utils.py index a7d946e49..0816b2d7e 100644 --- a/tests/unit/trace/test_ext_utils.py +++ b/tests/unit/trace/test_ext_utils.py @@ -15,8 +15,8 @@ import unittest import mock - from google.rpc import code_pb2 + from opencensus.trace import utils diff --git a/tests/unit/trace/test_span.py b/tests/unit/trace/test_span.py index f7ddf5d7b..75637ad88 100644 --- a/tests/unit/trace/test_span.py +++ b/tests/unit/trace/test_span.py @@ -12,21 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -from collections import OrderedDict import datetime import unittest +from collections import OrderedDict import mock - from google.rpc import code_pb2 from opencensus.common import utils -from opencensus.trace.span import BoundedDict -from opencensus.trace.span import BoundedList +from opencensus.trace.span import BoundedDict, BoundedList from opencensus.trace.stack_trace import StackTrace from opencensus.trace.status import Status -from opencensus.trace.time_event import Annotation -from opencensus.trace.time_event import MessageEvent +from opencensus.trace.time_event import Annotation, MessageEvent class TestSpan(unittest.TestCase): diff --git a/tests/unit/trace/test_span_context.py b/tests/unit/trace/test_span_context.py index 13602e3f0..d3d1a279b 100644 --- a/tests/unit/trace/test_span_context.py +++ b/tests/unit/trace/test_span_context.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest + from opencensus.trace import span_context as span_context_module from opencensus.trace.trace_options import TraceOptions from opencensus.trace.tracestate import Tracestate diff --git a/tests/unit/trace/test_span_data.py b/tests/unit/trace/test_span_data.py index eb8109ef6..60b23ba9b 100644 --- a/tests/unit/trace/test_span_data.py +++ b/tests/unit/trace/test_span_data.py @@ -16,12 +16,9 @@ import unittest from opencensus.common import utils -from opencensus.trace import link -from opencensus.trace import span_context +from opencensus.trace import link, span_context from opencensus.trace import span_data as span_data_module -from opencensus.trace import stack_trace -from opencensus.trace import status -from opencensus.trace import time_event +from opencensus.trace import stack_trace, status, time_event class TestSpanData(unittest.TestCase): diff --git a/tests/unit/trace/test_time_event.py b/tests/unit/trace/test_time_event.py index a1e753181..063dfb4ad 100644 --- a/tests/unit/trace/test_time_event.py +++ b/tests/unit/trace/test_time_event.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime import unittest +from datetime import datetime import mock diff --git a/tests/unit/trace/test_tracer.py b/tests/unit/trace/test_tracer.py index a4dbc9f0d..82b9a16a3 100644 --- a/tests/unit/trace/test_tracer.py +++ b/tests/unit/trace/test_tracer.py @@ -16,8 +16,7 @@ import mock -from opencensus.trace import samplers -from opencensus.trace import span_data +from opencensus.trace import samplers, span_data from opencensus.trace import tracer as tracer_module diff --git a/tests/unit/trace/test_tracestate.py b/tests/unit/trace/test_tracestate.py index 2aeac8f64..170f248ef 100644 --- a/tests/unit/trace/test_tracestate.py +++ b/tests/unit/trace/test_tracestate.py @@ -14,9 +14,10 @@ import unittest +from opencensus.trace.propagation.tracestate_string_format import ( + TracestateStringFormatter, +) from opencensus.trace.tracestate import Tracestate -from opencensus.trace.propagation.tracestate_string_format \ - import TracestateStringFormatter formatter = TracestateStringFormatter() diff --git a/tests/unit/trace/tracers/test_context_tracer.py b/tests/unit/trace/tracers/test_context_tracer.py index f05d048ae..1898fb37f 100644 --- a/tests/unit/trace/tracers/test_context_tracer.py +++ b/tests/unit/trace/tracers/test_context_tracer.py @@ -16,9 +16,8 @@ import mock +from opencensus.trace import execution_context, span from opencensus.trace.tracers import context_tracer -from opencensus.trace import span -from opencensus.trace import execution_context class TestContextTracer(unittest.TestCase): diff --git a/tox.ini b/tox.ini index 74a05863f..9ab06d9c5 100644 --- a/tox.ini +++ b/tox.ini @@ -41,6 +41,7 @@ deps = py37-setup: pygments py37-docs: setuptools >= 36.4.0 py37-docs: sphinx >= 1.6.3 + isort commands = py{27,34,35,36,37}-unit: py.test --quiet --cov={envdir}/opencensus --cov=context --cov=contrib --cov-report term-missing --cov-config=.coveragerc --cov-fail-under=97 tests/unit/ context/ contrib/ @@ -50,4 +51,5 @@ commands = py37-setup: python setup.py check --restructuredtext --strict py37-docs: bash ./scripts/update_docs.sh ; TODO deployment + isort -y --recursive .