Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 25362e7

Browse files
authored
Enable lint for tests and examples (#419)
Re-enable lint checks for tests/ and examples/ and fix existing lint errors.
1 parent 0e5f67c commit 25362e7

File tree

75 files changed

+1115
-1188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1115
-1188
lines changed

examples/stats/exporter/prometheus.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@
3434
VIDEO_SIZE_VIEW_NAME = "my.org/views/video_size"
3535
VIDEO_SIZE_DISTRIBUTION = aggregation_module.DistributionAggregation(
3636
[0.0, 16.0 * MiB, 256.0 * MiB])
37-
VIDEO_SIZE_VIEW = view_module.View(VIDEO_SIZE_VIEW_NAME,
38-
"processed video size over time",
39-
[FRONTEND_KEY],
40-
VIDEO_SIZE_MEASURE,
41-
VIDEO_SIZE_DISTRIBUTION)
37+
VIDEO_SIZE_VIEW = view_module.View(
38+
VIDEO_SIZE_VIEW_NAME, "processed video size over time", [FRONTEND_KEY],
39+
VIDEO_SIZE_MEASURE, VIDEO_SIZE_DISTRIBUTION)
4240

4341

4442
def main():
4543
stats = stats_module.Stats()
4644
view_manager = stats.view_manager
4745
stats_recorder = stats.stats_recorder
4846

49-
exporter = prometheus.new_stats_exporter(prometheus.Options(namespace="opencensus"))
47+
exporter = prometheus.new_stats_exporter(
48+
prometheus.Options(namespace="opencensus"))
5049
view_manager.register_exporter(exporter)
5150

5251
# Register view.
@@ -72,8 +71,8 @@ def main():
7271
view_data = view_manager.get_view(VIDEO_SIZE_VIEW_NAME)
7372
pprint(vars(view_data))
7473
for k, v in view_data._tag_value_aggregation_data_map.items():
75-
pprint(k)
76-
pprint(vars(v))
74+
pprint(k)
75+
pprint(vars(v))
7776

7877

7978
if __name__ == '__main__':

examples/stats/exporter/stackdriver.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@
2929
"my.org/measure/video_size_test2", "size of processed videos", "By")
3030
VIDEO_SIZE_VIEW_NAME = "my.org/views/video_size_test2"
3131
VIDEO_SIZE_DISTRIBUTION = aggregation_module.DistributionAggregation(
32-
[0.0, 16.0 * MiB, 256.0 * MiB])
33-
VIDEO_SIZE_VIEW = view_module.View(VIDEO_SIZE_VIEW_NAME,
34-
"processed video size over time",
35-
[FRONTEND_KEY],
36-
VIDEO_SIZE_MEASURE,
37-
VIDEO_SIZE_DISTRIBUTION)
38-
39-
32+
[0.0, 16.0 * MiB, 256.0 * MiB])
33+
VIDEO_SIZE_VIEW = view_module.View(
34+
VIDEO_SIZE_VIEW_NAME, "processed video size over time", [FRONTEND_KEY],
35+
VIDEO_SIZE_MEASURE, VIDEO_SIZE_DISTRIBUTION)
4036

4137
stats = stats_module.Stats()
4238
view_manager = stats.view_manager
4339
stats_recorder = stats.stats_recorder
4440

45-
exporter = stackdriver.new_stats_exporter(stackdriver.Options(project_id="opencenus-node"))
41+
exporter = stackdriver.new_stats_exporter(
42+
stackdriver.Options(project_id="opencenus-node"))
4643
view_manager.register_exporter(exporter)
4744

4845
# Register view.

examples/stats/helloworld/main.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
VIDEO_SIZE_VIEW_NAME = "my.org/views/video_size"
3434
VIDEO_SIZE_DISTRIBUTION = aggregation_module.DistributionAggregation(
3535
[0.0, 16.0 * MiB, 256.0 * MiB])
36-
VIDEO_SIZE_VIEW = view_module.View(VIDEO_SIZE_VIEW_NAME,
37-
"processed video size over time",
38-
[FRONTEND_KEY],
39-
VIDEO_SIZE_MEASURE,
40-
VIDEO_SIZE_DISTRIBUTION)
36+
VIDEO_SIZE_VIEW = view_module.View(
37+
VIDEO_SIZE_VIEW_NAME, "processed video size over time", [FRONTEND_KEY],
38+
VIDEO_SIZE_MEASURE, VIDEO_SIZE_DISTRIBUTION)
4139

4240

4341
def main():
@@ -64,8 +62,8 @@ def main():
6462
view_data = view_manager.get_view(VIDEO_SIZE_VIEW_NAME)
6563
pprint(vars(view_data))
6664
for k, v in view_data._tag_value_aggregation_data_map.items():
67-
pprint(k)
68-
pprint(vars(v))
65+
pprint(k)
66+
pprint(vars(v))
6967

7068

7169
if __name__ == '__main__':

examples/trace/grpc/hello_world_pb2.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/trace/grpc/hello_world_pb2_grpc.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,44 @@
55

66

77
class GreeterStub(object):
8-
"""The hello world service definition.
8+
"""The hello world service definition.
99
"""
1010

11-
def __init__(self, channel):
12-
"""Constructor.
11+
def __init__(self, channel):
12+
"""Constructor.
1313
1414
Args:
1515
channel: A grpc.Channel.
1616
"""
17-
self.SayHello = channel.unary_unary(
18-
'/helloworld.Greeter/SayHello',
19-
request_serializer=hello__world__pb2.HelloRequest.SerializeToString,
20-
response_deserializer=hello__world__pb2.HelloReply.FromString,
17+
self.SayHello = channel.unary_unary(
18+
'/helloworld.Greeter/SayHello',
19+
request_serializer=hello__world__pb2.HelloRequest.
20+
SerializeToString,
21+
response_deserializer=hello__world__pb2.HelloReply.FromString,
2122
)
2223

2324

2425
class GreeterServicer(object):
25-
"""The hello world service definition.
26+
"""The hello world service definition.
2627
"""
2728

28-
def SayHello(self, request, context):
29-
"""Say hello to the request sender (unary-unary)
29+
def SayHello(self, request, context):
30+
"""Say hello to the request sender (unary-unary)
3031
"""
31-
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
32-
context.set_details('Method not implemented!')
33-
raise NotImplementedError('Method not implemented!')
32+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
33+
context.set_details('Method not implemented!')
34+
raise NotImplementedError('Method not implemented!')
3435

3536

3637
def add_GreeterServicer_to_server(servicer, server):
37-
rpc_method_handlers = {
38-
'SayHello': grpc.unary_unary_rpc_method_handler(
39-
servicer.SayHello,
40-
request_deserializer=hello__world__pb2.HelloRequest.FromString,
41-
response_serializer=hello__world__pb2.HelloReply.SerializeToString,
42-
),
43-
}
44-
generic_handler = grpc.method_handlers_generic_handler(
45-
'helloworld.Greeter', rpc_method_handlers)
46-
server.add_generic_rpc_handlers((generic_handler,))
38+
rpc_method_handlers = {
39+
'SayHello':
40+
grpc.unary_unary_rpc_method_handler(
41+
servicer.SayHello,
42+
request_deserializer=hello__world__pb2.HelloRequest.FromString,
43+
response_serializer=hello__world__pb2.HelloReply.SerializeToString,
44+
),
45+
}
46+
generic_handler = grpc.method_handlers_generic_handler(
47+
'helloworld.Greeter', rpc_method_handlers)
48+
server.add_generic_rpc_handlers((generic_handler, ))

examples/trace/helloworld/django/app/settings.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
1514
"""Django settings for test app."""
1615

1716
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@@ -66,10 +65,13 @@
6665
]
6766

6867
OPENCENSUS_TRACE = {
69-
'SAMPLER': 'opencensus.trace.samplers.always_on.AlwaysOnSampler',
70-
'EXPORTER': 'opencensus.trace.exporters.stackdriver_exporter.StackdriverExporter',
71-
'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.'
72-
'GoogleCloudFormatPropagator',
68+
'SAMPLER':
69+
'opencensus.trace.samplers.always_on.AlwaysOnSampler',
70+
'EXPORTER':
71+
'opencensus.trace.exporters.stackdriver_exporter.StackdriverExporter',
72+
'PROPAGATOR':
73+
'opencensus.trace.propagation.google_cloud_format.'
74+
'GoogleCloudFormatPropagator',
7375
}
7476

7577
OPENCENSUS_TRACE_PARAMS = {
@@ -89,7 +91,6 @@
8991

9092
USE_TZ = True
9193

92-
9394
# Static files (CSS, JavaScript, Images)
9495
# https://docs.djangoproject.com/en/1.8/howto/static-files/
9596

examples/trace/helloworld/django/app/views.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import psycopg2
2424
import sqlalchemy
2525

26-
import time
2726
import os
2827
import requests
2928

@@ -51,8 +50,7 @@ def greetings(request):
5150
if form.is_valid():
5251
first_name = form.cleaned_data['fname']
5352
last_name = form.cleaned_data['lname']
54-
return HttpResponse(
55-
"Hello, {} {}".format(first_name, last_name))
53+
return HttpResponse("Hello, {} {}".format(first_name, last_name))
5654
else:
5755
return render(request, 'home.html')
5856

@@ -67,9 +65,7 @@ def trace_requests(request):
6765
def mysql_trace(request):
6866
try:
6967
conn = mysql.connector.connect(
70-
host=DB_HOST,
71-
user='root',
72-
password=MYSQL_PASSWORD)
68+
host=DB_HOST, user='root', password=MYSQL_PASSWORD)
7369
cursor = conn.cursor()
7470

7571
query = 'SELECT 2*3'
@@ -114,8 +110,8 @@ def postgresql_trace(request):
114110
def sqlalchemy_mysql_trace(request):
115111
try:
116112
engine = sqlalchemy.create_engine(
117-
'mysql+mysqlconnector://{}:{}@{}'.format(
118-
'root', MYSQL_PASSWORD, DB_HOST))
113+
'mysql+mysqlconnector://{}:{}@{}'.format('root', MYSQL_PASSWORD,
114+
DB_HOST))
119115
conn = engine.connect()
120116

121117
query = 'SELECT 2*3'
@@ -136,10 +132,8 @@ def sqlalchemy_mysql_trace(request):
136132

137133
def sqlalchemy_postgresql_trace(request):
138134
try:
139-
engine = sqlalchemy.create_engine(
140-
'postgresql://{}:{}@{}/{}'.format(
141-
'postgres', POSTGRES_PASSWORD,
142-
DB_HOST, 'postgres'))
135+
engine = sqlalchemy.create_engine('postgresql://{}:{}@{}/{}'.format(
136+
'postgres', POSTGRES_PASSWORD, DB_HOST, 'postgres'))
143137
conn = engine.connect()
144138

145139
query = 'SELECT 2*3'

examples/trace/helloworld/flask/simple.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414

1515
import flask
1616

17-
from opencensus.trace.exporters import stackdriver_exporter
1817
from opencensus.trace.ext.flask.flask_middleware import FlaskMiddleware
1918

20-
2119
app = flask.Flask(__name__)
2220

2321
# Enable tracing the requests

examples/trace/helloworld/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def main():
2929
exporter = print_exporter.PrintExporter()
3030
tracer = Tracer(sampler=sampler, exporter=exporter)
3131

32-
with tracer.span(name='root') as root_span:
33-
tracer.add_attribute_to_current_span(attribute_key='example key',
34-
attribute_value='example value')
32+
with tracer.span(name='root'):
33+
tracer.add_attribute_to_current_span(
34+
attribute_key='example key', attribute_value='example value')
3535
function_to_trace()
36-
with tracer.span(name='child') as child_span:
36+
with tracer.span(name='child'):
3737
function_to_trace()
3838

3939
# Get the current tracer
@@ -43,7 +43,7 @@ def main():
4343
tracer.start_span()
4444

4545
# Get current span
46-
cur_span = execution_context.get_current_span()
46+
execution_context.get_current_span()
4747

4848
# Explicitly end span
4949
tracer.end_span()

nox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def lint(session):
8585
session.install('.')
8686
session.run(
8787
'flake8',
88-
'--exclude=opencensus/trace/exporters/gen/opencensus/',
89-
'opencensus/')
88+
'--exclude=opencensus/trace/exporters/gen/',
89+
'opencensus/', 'tests/', 'examples/')
9090

9191

9292
@nox.session

0 commit comments

Comments
 (0)