Skip to content

Commit f9301ed

Browse files
committed
fixed lint with autopep8, isort and black
1 parent 3b5afc0 commit f9301ed

File tree

4 files changed

+72
-67
lines changed

4 files changed

+72
-67
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
OpenTelemetry Threading Instrumentation
2-
=======================================
2+
== == == == == == == == == == == == == == == == == == == =
33

44
|pypi|
55

6-
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-threading.svg
7-
:target: https://pypi.org/project/opentelemetry-instrumentation-threading/
6+
.. | pypi | image:: https: // badge.fury.io/py/opentelemetry-instrumentation-threading.svg
7+
: target: https: // pypi.org / project / opentelemetry - instrumentation - threading/
88

99

1010
Installation
1111
------------
1212

1313
::
1414

15-
pip install opentelemetry-instrumentation-threading
15+
pip install opentelemetry - instrumentation - threading
1616

1717
References
1818
----------
1919

20-
* `OpenTelemetry Threading Instrumentation <https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/threading/threading.html>`_
21-
* `OpenTelemetry Project <https://opentelemetry.io/>`_
22-
* `OpenTelemetry Python Examples <https://github.com/open-telemetry/opentelemetry-python/tree/main/docs/examples>`_
20+
* `OpenTelemetry Threading Instrumentation < https: // opentelemetry - python - contrib.readthedocs.io / en / latest / instrumentation / threading / threading.html >`_
21+
* `OpenTelemetry Project < https: // opentelemetry.io / >`_
22+
* `OpenTelemetry Python Examples < https: // github.com / open - telemetry / opentelemetry - python / tree / main / docs / examples >`_

instrumentation/opentelemetry-instrumentation-threading/pyproject.toml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
[build-system]
1+
[build - system]
22
requires = ["hatchling"]
3-
build-backend = "hatchling.build"
3+
build - backend = "hatchling.build"
44

55
[project]
66
name = "opentelemetry-instrumentation-threading"
77
dynamic = ["version"]
88
description = "Threading instrumentation for OpenTelemetry"
99
readme = "README.rst"
1010
license = "Apache-2.0"
11-
requires-python = ">=3.7"
11+
requires - python = ">=3.7"
1212
authors = [
13-
{ name = "OpenTelemetry Authors", email = "[email protected]" },
13+
{name= "OpenTelemetry Authors", email = "[email protected]"},
1414
]
1515
classifiers = [
16-
"Development Status :: 4 - Beta",
17-
"Intended Audience :: Developers",
18-
"License :: OSI Approved :: Apache Software License",
19-
"Programming Language :: Python",
20-
"Programming Language :: Python :: 3",
21-
"Programming Language :: Python :: 3.7",
22-
"Programming Language :: Python :: 3.8",
23-
"Programming Language :: Python :: 3.9",
24-
"Programming Language :: Python :: 3.10",
25-
"Programming Language :: Python :: 3.11",
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Developers",
18+
"License :: OSI Approved :: Apache Software License",
19+
"Programming Language :: Python",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3.7",
22+
"Programming Language :: Python :: 3.8",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
2626
]
2727
dependencies = [
28-
"opentelemetry-api ~= 1.12",
29-
"opentelemetry-instrumentation == 0.38b0.dev",
28+
"opentelemetry-api ~= 1.12",
29+
"opentelemetry-instrumentation == 0.38b0.dev",
3030
]
3131

32-
[project.optional-dependencies]
32+
[project.optional - dependencies]
3333
instruments = []
3434
test = [
35-
"opentelemetry-instrumentation-threading[instruments]",
36-
"opentelemetry-test-utils == 0.38b0.dev",
35+
"opentelemetry-instrumentation-threading[instruments]",
36+
"opentelemetry-test-utils == 0.38b0.dev",
3737
]
3838

39-
[project.entry-points.opentelemetry_instrumentor]
39+
[project.entry - points.opentelemetry_instrumentor]
4040
threading = "opentelemetry.instrumentation.threading:ThreadingInstrumentor"
4141

4242
[project.urls]
@@ -47,8 +47,8 @@ path = "src/opentelemetry/instrumentation/threading/version.py"
4747

4848
[tool.hatch.build.targets.sdist]
4949
include = [
50-
"/src",
51-
"/tests",
50+
"/src",
51+
"/tests",
5252
]
5353

5454
[tool.hatch.build.targets.wheel]

instrumentation/opentelemetry-instrumentation-threading/src/opentelemetry/instrumentation/threading/__init__.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,24 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# pylint: disable=empty-docstring,no-value-for-parameter,no-member,no-name-in-module
15+
# pylint:
16+
# disable=empty-docstring,no-value-for-parameter,no-member,no-name-in-module
1617

17-
import threading # pylint: disable=import-self
18+
import threading # pylint: disable=import-self
1819
from os import environ
1920
from typing import Collection
20-
from opentelemetry import context
2121

22+
from opentelemetry import context, trace
2223
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
23-
2424
from opentelemetry.instrumentation.threading.package import _instruments
2525
from opentelemetry.instrumentation.threading.version import __version__
26-
27-
from opentelemetry import trace
2826
from opentelemetry.trace import (
2927
get_current_span,
28+
get_tracer,
3029
get_tracer_provider,
31-
get_tracer
3230
)
3331

32+
3433
class _InstrumentedThread(threading.Thread):
3534
def __init__(self, *args, **kwargs):
3635
super().__init__(*args, **kwargs)
@@ -47,21 +46,23 @@ def run(self):
4746
context.attach(ctx)
4847
super().run()
4948

50-
class ThreadingInstrumentor(BaseInstrumentor): # pylint: disable=empty-docstring
51-
49+
50+
class ThreadingInstrumentor(
51+
BaseInstrumentor
52+
): # pylint: disable=empty-docstring
5253
original_threadcls = threading.Thread
5354

5455
def instrumentation_dependencies(self) -> Collection[str]:
5556
return _instruments
5657

57-
58-
def _instrument(self, *args, **kwargs):
59-
60-
tracer_provider = kwargs.get("tracer_provider", None) or get_tracer_provider()
58+
def _instrument(self, *args, **kwargs):
59+
tracer_provider = (
60+
kwargs.get("tracer_provider", None) or get_tracer_provider()
61+
)
6162

6263
tracer = get_tracer(__name__, __version__, tracer_provider)
6364
threading.Thread = _InstrumentedThread
6465
_InstrumentedThread._tracer = tracer
65-
66+
6667
def _uninstrument(self, **kwargs):
67-
threading.Thread = self.original_threadcls
68+
threading.Thread = self.original_threadcls

instrumentation/opentelemetry-instrumentation-threading/tests/test_threading.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from unittest import mock
1818

1919
from packaging import version
20+
2021
from opentelemetry import trace as trace_api
2122
from opentelemetry.instrumentation.threading import ThreadingInstrumentor
2223
from opentelemetry.test.test_base import TestBase
@@ -33,32 +34,34 @@ def setUp(self):
3334
def tearDown(self):
3435
super().tearDown()
3536
ThreadingInstrumentor().uninstrument()
37+
3638
def print_square(self, num):
3739
with self.tracer.start_as_current_span("square"):
38-
print("Square: {}" .format(num * num))
40+
print("Square: {}".format(num * num))
3941

4042
def print_cube(self, num):
4143
with self.tracer.start_as_current_span("cube"):
42-
print("Cube: {}" .format(num * num * num))
44+
print("Cube: {}".format(num * num * num))
4345

4446
def print_square_with_thread(self, num):
4547
with self.tracer.start_as_current_span("square"):
4648
cube_thread = threading.Thread(target=self.print_cube, args=(10,))
47-
print("Square: {}" .format(num * num))
49+
print("Square: {}".format(num * num))
4850
cube_thread.start()
4951
cube_thread.join()
5052

5153
def calculate(self, num):
5254
with self.tracer.start_as_current_span("calculate"):
53-
square_thread = threading.Thread(target=self.print_square, args=(num,))
55+
square_thread = threading.Thread(
56+
target=self.print_square, args=(num,)
57+
)
5458
cube_thread = threading.Thread(target=self.print_cube, args=(num,))
5559
square_thread.start()
5660
square_thread.join()
57-
61+
5862
cube_thread.start()
5963
cube_thread.join()
6064

61-
6265
def test_without_thread_nesting(self):
6366
square_thread = threading.Thread(target=self.print_square, args=(10,))
6467

@@ -70,18 +73,19 @@ def test_without_thread_nesting(self):
7073
self.assertEqual(len(spans), 2)
7174

7275
target, root = spans[:2]
73-
76+
7477
self.assertIs(target.parent, root.get_span_context())
7578
self.assertIsNone(root.parent)
7679

7780
def test_with_thread_nesting(self):
78-
#
79-
# Following scenario is tested.
80-
# threadA -> methodA -> threadB -> methodB
81-
#
82-
83-
square_thread = threading.Thread(target=self.print_square_with_thread, args=(10,))
81+
#
82+
# Following scenario is tested.
83+
# threadA -> methodA -> threadB -> methodB
84+
#
8485

86+
square_thread = threading.Thread(
87+
target=self.print_square_with_thread, args=(10,)
88+
)
8589

8690
with self.tracer.start_as_current_span("root"):
8791
square_thread.start()
@@ -92,30 +96,30 @@ def test_with_thread_nesting(self):
9296
self.assertEqual(len(spans), 3)
9397

9498
cube, square, root = spans[:3]
95-
99+
96100
self.assertIs(cube.parent, square.get_span_context())
97101
self.assertIs(square.parent, root.get_span_context())
98102
self.assertIsNone(root.parent)
99103

100104
def test_with_thread_multi_nesting(self):
101-
#
102-
# Following scenario is tested.
103-
# / threadB -> methodB
104-
# threadA -> methodA ->
105-
# \ threadC -> methodC
106-
#
105+
#
106+
# Following scenario is tested.
107+
# / threadB -> methodB
108+
# threadA -> methodA ->
109+
# \ threadC -> methodC
110+
#
107111
calculate_thread = threading.Thread(target=self.calculate, args=(10,))
108112

109113
with self.tracer.start_as_current_span("root"):
110114
calculate_thread.start()
111115
calculate_thread.join()
112116

113117
spans = self.memory_exporter.get_finished_spans()
114-
118+
115119
self.assertEqual(len(spans), 4)
116120

117121
cube, square, calculate, root = spans[:4]
118-
122+
119123
self.assertIs(cube.parent, calculate.get_span_context())
120124
self.assertIs(square.parent, calculate.get_span_context())
121125
self.assertIs(calculate.parent, root.get_span_context())
@@ -130,4 +134,4 @@ def test_uninstrumented(self):
130134
spans = self.memory_exporter.get_finished_spans()
131135
self.assertEqual(len(spans), 1)
132136

133-
ThreadingInstrumentor().instrument()
137+
ThreadingInstrumentor().instrument()

0 commit comments

Comments
 (0)