Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update lint deps and configs #3533

Merged
merged 8 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ limit-inference-results=100

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
load-plugins=pylint.extensions.no_self_use

# Pickle collected data for later comparisons.
persistent=yes
Expand Down Expand Up @@ -68,14 +68,14 @@ disable=missing-docstring,
duplicate-code,
ungrouped-imports, # Leave this up to isort
wrong-import-order, # Leave this up to isort
bad-continuation, # Leave this up to black
line-too-long, # Leave this up to black
exec-used,
super-with-arguments, # temp-pylint-upgrade
isinstance-second-argument-not-valid-type, # temp-pylint-upgrade
raise-missing-from, # temp-pylint-upgrade
unused-argument, # temp-pylint-upgrade
redefined-builtin,
cyclic-import,
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -263,13 +263,6 @@ max-line-length=79
# Maximum number of lines in a module.
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down
30 changes: 14 additions & 16 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
pylint==2.11.0
flake8~=3.7
isort~=5.8
black~=22.3.0
httpretty~=1.0
pylint==3.0.2
flake8==6.1.0
isort==5.12.0
black==22.3.0
httpretty==1.1.4
mypy==0.931
sphinx~=3.5.4
sphinx-rtd-theme~=0.5
sphinx-autodoc-typehints~=1.12.0
sphinx==7.1.2
sphinx-rtd-theme==2.0.0rc4
sphinx-autodoc-typehints==1.25.2
pytest==7.1.3
pytest-cov>=2.8
readme-renderer~=24.0
# This version of grpcio-tools ships with protoc 3.19.4 which appears to be compatible with
# both protobuf 3.19.x and 4.x (see https://github.com/protocolbuffers/protobuf/issues/11123).
# Bump this version with caution to preserve compatibility with protobuf 3.
# https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-proto/pyproject.toml#L28
grpcio-tools==1.48.1
mypy-protobuf~=3.0.0
pytest-cov==4.1.0
readme-renderer==42.0
# temporary fix. we should update the jinja, flask deps
# See https://github.com/pallets/markupsafe/issues/282
# breaking change introduced in markupsafe causes jinja, flask to break
Expand All @@ -24,3 +18,7 @@ bleach==4.1.0 # This dependency was updated to a breaking version.
codespell==2.1.0
requests==2.31.0
ruamel.yaml==0.17.21
asgiref==3.7.2
psutil==5.9.6
GitPython==3.1.40
flaky==3.7.0
17 changes: 9 additions & 8 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
sphinx~=3.5.4
sphinx-rtd-theme~=0.5
sphinx-autodoc-typehints
sphinx==7.1.2
sphinx-rtd-theme==2.0.0rc4
sphinx-autodoc-typehints==1.25.2
# used to generate docs for the website
sphinx-jekyll-builder
sphinx-jekyll-builder==0.3.0

# Need to install the api/sdk in the venv for autodoc. Modifying sys.path
# doesn't work for pkg_resources.
./opentelemetry-api
./opentelemetry-semantic-conventions
./opentelemetry-sdk
./shim/opentelemetry-opencensus-shim
./shim/opentelemetry-opentracing-shim

# Required by instrumentation and exporter packages
ddtrace>=0.34.0
grpcio~=1.27
Deprecated>=1.2.6
django>=2.2
Deprecated~=1.2
django~=4.2
flask~=1.0
opentracing~=2.2.0
thrift>=0.10.0
thrift~=0.10
wrapt>=1.0.0,<2.0.0
# temporary fix. we should update the jinja, flask deps
# See https://github.com/pallets/markupsafe/issues/282
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(self, thrift_url="", auth=None, timeout_in_millis=None):
if auth is not None:
auth_header = f"{auth[0]}:{auth[1]}"
decoded = base64.b64encode(auth_header.encode()).decode("ascii")
basic_auth = dict(Authorization=f"Basic {decoded}")
basic_auth = {"Authorization": f"Basic {decoded}"}
self.http_transport.setCustomHeaders(basic_auth)

def submit(self, batch: jaeger.Batch):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ dependencies = [
"backoff >= 1.10.0, < 3.0.0; python_version>='3.7'",
]

[project.optional-dependencies]
test = []

[project.urls]
Homepage = "https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-common"

Expand Down
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions exporter/opentelemetry-exporter-otlp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ dependencies = [
"opentelemetry-exporter-otlp-proto-http == 1.22.0.dev",
]

[project.optional-dependencies]
test = []

[project.entry-points.opentelemetry_logs_exporter]
otlp = "opentelemetry.exporter.otlp.proto.grpc._log_exporter:OTLPLogExporter"

Expand Down
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions gen-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This version of grpcio-tools ships with protoc 3.19.4 which appears to be compatible with
# both protobuf 3.19.x and 4.x (see https://github.com/protocolbuffers/protobuf/issues/11123).
# Bump this version with caution to preserve compatibility with protobuf 3.
# https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-proto/pyproject.toml#L28
grpcio-tools==1.48.1
mypy-protobuf~=3.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def get_logger_provider() -> LoggerProvider:
"""Gets the current global :class:`~.LoggerProvider` object."""
global _LOGGER_PROVIDER # pylint: disable=global-statement
if _LOGGER_PROVIDER is None:
if _OTEL_PYTHON_LOGGER_PROVIDER not in environ.keys():
if _OTEL_PYTHON_LOGGER_PROVIDER not in environ:
# TODO: return proxy
_LOGGER_PROVIDER = NoOpLoggerProvider()
return _LOGGER_PROVIDER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
_logger = getLogger(__name__)


# pylint: disable=invalid-name
_ProxyInstrumentT = Union[
_ProxyCounter,
_ProxyHistogram,
Expand Down Expand Up @@ -760,7 +761,7 @@ def get_meter_provider() -> MeterProvider:
"""Gets the current global :class:`~.MeterProvider` object."""

if _METER_PROVIDER is None:
if OTEL_PYTHON_METER_PROVIDER not in environ.keys():
if OTEL_PYTHON_METER_PROVIDER not in environ:
return _PROXY_METER_PROVIDER

meter_provider: MeterProvider = _load_provider( # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CallbackOptions:


InstrumentT = TypeVar("InstrumentT", bound="Instrument")
# pylint: disable=invalid-name
CallbackT = Union[
Callable[[CallbackOptions], Iterable[Observation]],
Generator[Iterable[Observation], CallbackOptions, None],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from opentelemetry.context.context import Context

CarrierT = typing.TypeVar("CarrierT")
# pylint: disable=invalid-name
CarrierValT = typing.Union[typing.List[str], str]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
from opentelemetry import context
from opentelemetry.context.contextvars_context import ContextVarsRuntimeContext

from .base_context import ContextTestCases
# pylint: disable=import-error,no-name-in-module
from tests.context.base_context import ContextTestCases


class TestContextVarsContext(ContextTestCases.BaseTest):
# pylint: disable=invalid-name
def setUp(self) -> None:
super().setUp()
self.mock_runtime = patch.object(
Expand All @@ -30,6 +32,7 @@ def setUp(self) -> None:
)
self.mock_runtime.start()

# pylint: disable=invalid-name
def tearDown(self) -> None:
super().tearDown()
self.mock_runtime.stop()
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_no_traceparent_header(self):
If no traceparent header is received, the vendor creates a new
trace-id and parent-id that represents the current request.
"""
output = {} # type:typing.Dict[str, typing.List[str]]
output: typing.Dict[str, typing.List[str]] = {}
span = trace.get_current_span(FORMAT.extract(output))
self.assertIsInstance(span.get_span_context(), trace.SpanContext)

Expand All @@ -66,7 +66,7 @@ def test_headers_with_tracestate(self):
span_context.trace_state, {"foo": "1", "bar": "2", "baz": "3"}
)
self.assertTrue(span_context.is_remote)
output = {} # type:typing.Dict[str, str]
output: typing.Dict[str, str] = {}
span = trace.NonRecordingSpan(span_context)

ctx = trace.set_span_in_context(span)
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_no_send_empty_tracestate(self):
Empty and whitespace-only list members are allowed. Vendors MUST accept
empty tracestate headers but SHOULD avoid sending them.
"""
output = {} # type:typing.Dict[str, str]
output: typing.Dict[str, str] = {}
span = trace.NonRecordingSpan(
trace.SpanContext(self.TRACE_ID, self.SPAN_ID, is_remote=False)
)
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_format_not_supported(self):

def test_propagate_invalid_context(self):
"""Do not propagate invalid trace context."""
output = {} # type:typing.Dict[str, str]
output: typing.Dict[str, str] = {}
ctx = trace.set_span_in_context(trace.INVALID_SPAN)
FORMAT.inject(output, context=ctx)
self.assertFalse("traceparent" in output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ class BatchLogRecordProcessor(LogRecordProcessor):
- :envvar:`OTEL_BLRP_EXPORT_TIMEOUT`
"""

_queue: Deque[LogData]
_flush_request: Optional[_FlushRequest]
_log_records: List[Optional[LogData]]

def __init__(
self,
exporter: LogExporter,
Expand Down Expand Up @@ -201,20 +205,16 @@ def __init__(
self._schedule_delay_millis = schedule_delay_millis
self._max_export_batch_size = max_export_batch_size
self._export_timeout_millis = export_timeout_millis
self._queue = collections.deque(
[], max_queue_size
) # type: Deque[LogData]
self._queue = collections.deque([], max_queue_size)
self._worker_thread = threading.Thread(
name="OtelBatchLogRecordProcessor",
target=self.worker,
daemon=True,
)
self._condition = threading.Condition(threading.Lock())
self._shutdown = False
self._flush_request = None # type: Optional[_FlushRequest]
self._log_records = [
None
] * self._max_export_batch_size # type: List[Optional[LogData]]
self._flush_request = None
self._log_records = [None] * self._max_export_batch_size
self._worker_thread.start()
# Only available in *nix since py37.
if hasattr(os, "register_at_fork"):
Expand All @@ -236,7 +236,7 @@ def _at_fork_reinit(self):

def worker(self):
timeout = self._schedule_delay_millis / 1e3
flush_request = None # type: Optional[_FlushRequest]
flush_request: Optional[_FlushRequest] = None
while not self._shutdown:
with self._condition:
if self._shutdown:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@

The :envvar:`OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` is a comma-separated string
of names of resource detectors. These names must be the same as the names of
entry points for the `opentelemetry_resource_detector` entry point. This is an
entry points for the ```opentelemetry_resource_detector``` entry point. This is an
experimental feature and the name of this variable and its behavior can change
in a non-backwards compatible way.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ def aggregate(self, measurement: Measurement) -> None:

# 3. Determine if a change of scale is needed.
is_rescaling_needed = False
low, high = 0, 0

if len(buckets) == 0:
buckets.index_start = index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def to_json(self, indent=4) -> str:
)


# pylint: disable=invalid-name
DataT = Union[Sum, Gauge, Histogram]
DataPointT = Union[NumberDataPoint, HistogramDataPoint]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ def get_aggregated_resources(
futures = [executor.submit(detector.detect) for detector in detectors]
for detector_ind, future in enumerate(futures):
detector = detectors[detector_ind]
detected_resource: Resource = _EMPTY_RESOURCE
try:
detected_resource = future.result(timeout=timeout)
# pylint: disable=broad-except
except Exception as ex:
detected_resource = _EMPTY_RESOURCE
if detector.raise_on_error:
raise ex
logger.warning(
Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ class SynchronousMultiSpanProcessor(SpanProcessor):
added.
"""

_span_processors: Tuple[SpanProcessor, ...]

def __init__(self):
# use a tuple to avoid race conditions when adding a new span and
# iterating through it on "on_start" and "on_end".
self._span_processors = () # type: Tuple[SpanProcessor, ...]
self._span_processors = ()
self._lock = threading.Lock()

def add_span_processor(self, span_processor: SpanProcessor) -> None:
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ def test_record_exception_with_attributes_and_timestamp(self):
self.assertEqual(1604238587112021089, exception_event.timestamp)

def test_record_exception_context_manager(self):
span = None
try:
with self.tracer.start_as_current_span("span") as span:
raise RuntimeError("example error")
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ exclude = '''
/( # generated files
.tox|
venv|
venv.*|
.venv.*|
target.*|
.*/build/lib/.*|
exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/gen|
exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/gen|
Expand Down
2 changes: 1 addition & 1 deletion scripts/proto_codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ echo "Creating temporary virtualenv at $venv_dir using $(python3 --version)"
python3 -m venv $venv_dir
source $venv_dir/bin/activate
python -m pip install \
-c $repo_root/dev-requirements.txt \
-c $repo_root/gen-requirements.txt \
grpcio-tools mypy-protobuf
echo 'python -m grpc_tools.protoc --version'
python -m grpc_tools.protoc --version
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_sha.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

def get_sha(branch):
url = API_URL + branch
response = requests.get(url)
response = requests.get(url, timeout=15)
response.raise_for_status()
return response.json()["sha"]

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def from_context_manager(cls, manager: "ScopeManagerShim", span_cm):
:meth:`opentelemetry.trace.use_span`.
"""

# pylint: disable=unnecessary-dunder-call
otel_span = span_cm.__enter__()
span_context = SpanContextShim(otel_span.get_span_context())
span = SpanShim(manager.tracer, span_context, otel_span)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_main(self):
def task(self, interval, parent_span):
logger.info("Starting task")

scope = None
try:
scope = self.tracer.scope_manager.activate(parent_span, False)
with self.tracer.start_active_span("task"):
Expand Down
Loading
Loading