Skip to content

Commit 8cb2d05

Browse files
committed
Upgrade sanity Docker image to debian:stretch
* Use latest pylint in Python 3.7 (they dropped support for PY2) * Make latest pylint happy * Forced to upgrade to shellcheck 0.4.4 * Make shellcheck 0.4.4 happy * Adopt reviewers' advice to reduce global disabled rules
1 parent 60f2d37 commit 8cb2d05

36 files changed

+94
-70
lines changed

.pylintrc

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
[MASTER]
2+
ignore=
3+
src/python/grpcio/grpc/beta,
4+
src/python/grpcio/grpc/framework,
5+
src/python/grpcio/grpc/framework/common,
6+
src/python/grpcio/grpc/framework/foundation,
7+
src/python/grpcio/grpc/framework/interfaces,
8+
19
[VARIABLES]
210

311
# TODO(https://github.com/PyCQA/pylint/issues/1345): How does the inspection
@@ -82,3 +90,5 @@ disable=
8290
# if:/else: and for:/else:.
8391
useless-else-on-loop,
8492
no-else-return,
93+
# NOTE(lidiz): Python 3 make object inheritance default, but not PY2
94+
useless-object-inheritance,

.pylintrc-tests

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[MASTER]
2+
ignore-patterns=
3+
.+?(beta|framework).+?\.py
4+
15
[VARIABLES]
26

37
# TODO(https://github.com/PyCQA/pylint/issues/1345): How does the inspection
@@ -115,3 +119,5 @@ disable=
115119
# if:/else: and for:/else:.
116120
useless-else-on-loop,
117121
no-else-return,
122+
# NOTE(lidiz): Python 3 make object inheritance default, but not PY2
123+
useless-object-inheritance,

src/python/grpcio/grpc/_auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, credentials):
4646

4747
# Hack to determine if these are JWT creds and we need to pass
4848
# additional_claims when getting a token
49-
self._is_jwt = 'additional_claims' in inspect.getargspec(
49+
self._is_jwt = 'additional_claims' in inspect.getargspec( # pylint: disable=deprecated-method
5050
credentials.get_access_token).args
5151

5252
def __call__(self, context, callback):

src/python/grpcio/grpc/_channel.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def _blocking(self, request, timeout, metadata, credentials,
525525
state, operations, deadline, rendezvous = self._prepare(
526526
request, timeout, metadata, wait_for_ready)
527527
if state is None:
528-
raise rendezvous
528+
raise rendezvous # pylint: disable-msg=raising-bad-type
529529
else:
530530
call = self._channel.segregated_call(
531531
0, self._method, None, deadline, metadata, None
@@ -535,7 +535,7 @@ def _blocking(self, request, timeout, metadata, credentials,
535535
),))
536536
event = call.next_event()
537537
_handle_event(event, state, self._response_deserializer)
538-
return state, call,
538+
return state, call
539539

540540
def __call__(self,
541541
request,
@@ -566,7 +566,7 @@ def future(self,
566566
state, operations, deadline, rendezvous = self._prepare(
567567
request, timeout, metadata, wait_for_ready)
568568
if state is None:
569-
raise rendezvous
569+
raise rendezvous # pylint: disable-msg=raising-bad-type
570570
else:
571571
event_handler = _event_handler(state, self._response_deserializer)
572572
call = self._managed_call(
@@ -599,7 +599,7 @@ def __call__(self,
599599
initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
600600
wait_for_ready)
601601
if serialized_request is None:
602-
raise rendezvous
602+
raise rendezvous # pylint: disable-msg=raising-bad-type
603603
else:
604604
state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None, None)
605605
operationses = (
@@ -653,7 +653,7 @@ def _blocking(self, request_iterator, timeout, metadata, credentials,
653653
state.condition.notify_all()
654654
if not state.due:
655655
break
656-
return state, call,
656+
return state, call
657657

658658
def __call__(self,
659659
request_iterator,
@@ -745,10 +745,10 @@ def __new__(cls, value=_EMPTY_FLAGS):
745745
def with_wait_for_ready(self, wait_for_ready):
746746
if wait_for_ready is not None:
747747
if wait_for_ready:
748-
self = self.__class__(self | cygrpc.InitialMetadataFlags.wait_for_ready | \
748+
return self.__class__(self | cygrpc.InitialMetadataFlags.wait_for_ready | \
749749
cygrpc.InitialMetadataFlags.wait_for_ready_explicitly_set)
750750
elif not wait_for_ready:
751-
self = self.__class__(self & ~cygrpc.InitialMetadataFlags.wait_for_ready | \
751+
return self.__class__(self & ~cygrpc.InitialMetadataFlags.wait_for_ready | \
752752
cygrpc.InitialMetadataFlags.wait_for_ready_explicitly_set)
753753
return self
754754

src/python/grpcio/grpc/_utilities.py

-3
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,12 @@ def done(self):
132132

133133
def result(self, timeout=None):
134134
self._block(timeout)
135-
return None
136135

137136
def exception(self, timeout=None):
138137
self._block(timeout)
139-
return None
140138

141139
def traceback(self, timeout=None):
142140
self._block(timeout)
143-
return None
144141

145142
def add_done_callback(self, fn):
146143
with self._condition:

src/python/grpcio_testing/grpc_testing/_server/_handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def stream_response_termination(self):
185185
elif self._code is None:
186186
self._condition.wait()
187187
else:
188-
return self._trailing_metadata, self._code, self._details,
188+
return self._trailing_metadata, self._code, self._details
189189

190190
def expire(self):
191191
with self._condition:

src/python/grpcio_tests/tests/_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def try_set_handler(name, handler):
203203
check_kill_self()
204204
time.sleep(0)
205205
case_thread.join()
206-
except:
206+
except: # pylint: disable=try-except-raise
207207
# re-raise the exception after forcing the with-block to end
208208
raise
209209
result.set_output(augmented_case.case, stdout_pipe.output(),

src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def protoc(self, proto_path, python_out, absolute_proto_file_names):
144144
absolute_proto_file_names)
145145
pb2_grpc_protoc_exit_code = _protoc(
146146
proto_path, None, 'grpc_2_0', python_out, absolute_proto_file_names)
147-
return pb2_protoc_exit_code, pb2_grpc_protoc_exit_code,
147+
return pb2_protoc_exit_code, pb2_grpc_protoc_exit_code
148148

149149

150150
class _GrpcBeforeProtoProtocStyle(object):
@@ -160,7 +160,7 @@ def protoc(self, proto_path, python_out, absolute_proto_file_names):
160160
proto_path, None, 'grpc_2_0', python_out, absolute_proto_file_names)
161161
pb2_protoc_exit_code = _protoc(proto_path, python_out, None, None,
162162
absolute_proto_file_names)
163-
return pb2_grpc_protoc_exit_code, pb2_protoc_exit_code,
163+
return pb2_grpc_protoc_exit_code, pb2_protoc_exit_code
164164

165165

166166
_PROTOC_STYLES = (
@@ -243,9 +243,9 @@ def _protoc(self):
243243

244244
def _services_modules(self):
245245
if self.PROTOC_STYLE.grpc_in_pb2_expected():
246-
return self._services_pb2, self._services_pb2_grpc,
246+
return self._services_pb2, self._services_pb2_grpc
247247
else:
248-
return self._services_pb2_grpc,
248+
return (self._services_pb2_grpc,)
249249

250250
def test_imported_attributes(self):
251251
self._protoc()

src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def HalfDuplexCall(self, request_iter, context):
223223
server.start()
224224
channel = implementations.insecure_channel('localhost', port)
225225
stub = getattr(service_pb2, STUB_FACTORY_IDENTIFIER)(channel)
226-
yield servicer_methods, stub,
226+
yield servicer_methods, stub
227227
server.stop(0)
228228

229229

src/python/grpcio_tests/tests/qps/benchmark_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def __init__(self, server, config, hist):
180180
self._streams = [
181181
_SyncStream(self._stub, self._generic, self._request,
182182
self._handle_response)
183-
for _ in xrange(config.outstanding_rpcs_per_channel)
183+
for _ in range(config.outstanding_rpcs_per_channel)
184184
]
185185
self._curr_stream = 0
186186

src/python/grpcio_tests/tests/qps/client_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, client, request_count):
7777
def start(self):
7878
self._is_running = True
7979
self._client.start()
80-
for _ in xrange(self._request_count):
80+
for _ in range(self._request_count):
8181
self._client.send_request()
8282

8383
def stop(self):

src/python/grpcio_tests/tests/qps/worker_server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def RunClient(self, request_iterator, context):
109109
start_time = time.time()
110110

111111
# Create a client for each channel
112-
for i in xrange(config.client_channels):
112+
for i in range(config.client_channels):
113113
server = config.server_targets[i % len(config.server_targets)]
114114
runner = self._create_client_runner(server, config, qps_data)
115115
client_runners.append(runner)

src/python/grpcio_tests/tests/stress/client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ def run_test(args):
132132
server.start()
133133

134134
for test_server_target in test_server_targets:
135-
for _ in xrange(args.num_channels_per_server):
135+
for _ in range(args.num_channels_per_server):
136136
channel = _get_channel(test_server_target, args)
137-
for _ in xrange(args.num_stubs_per_channel):
137+
for _ in range(args.num_stubs_per_channel):
138138
stub = test_pb2_grpc.TestServiceStub(channel)
139139
runner = test_runner.TestRunner(stub, test_cases, hist,
140140
exception_queue, stop_event)

src/python/grpcio_tests/tests/testing/_client_application.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ def _run_stream_stream(stub):
130130
request_pipe = _Pipe()
131131
response_iterator = stub.StreStre(iter(request_pipe))
132132
request_pipe.add(_application_common.STREAM_STREAM_REQUEST)
133-
first_responses = next(response_iterator), next(response_iterator),
133+
first_responses = next(response_iterator), next(response_iterator)
134134
request_pipe.add(_application_common.STREAM_STREAM_REQUEST)
135-
second_responses = next(response_iterator), next(response_iterator),
135+
second_responses = next(response_iterator), next(response_iterator)
136136
request_pipe.close()
137137
try:
138138
next(response_iterator)

src/python/grpcio_tests/tests/unit/_from_grpc_import_star.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
_BEFORE_IMPORT = tuple(globals())
1616

17-
from grpc import * # pylint: disable=wildcard-import
17+
from grpc import * # pylint: disable=wildcard-import,unused-wildcard-import
1818

1919
_AFTER_IMPORT = tuple(globals())
2020

templates/tools/dockerfile/test/sanity/Dockerfile.template

+9-13
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,24 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
FROM debian:jessie
18-
19-
<%include file="../../apt_get_basic.include"/>
20-
<%include file="../../gcp_api_libraries.include"/>
21-
<%include file="../../python_deps.include"/>
17+
<%include file="../../python_stretch.include"/>
2218
<%include file="../../cxx_deps.include"/>
2319
#========================
2420
# Sanity test dependencies
21+
RUN apt-get update && apt-get -t testing install -y python3.7 python3-all-dev
22+
RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7
23+
# Make Python 3.7 the default Python 3 version
24+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
2525
RUN apt-get update && apt-get install -y ${"\\"}
26-
python-pip ${"\\"}
2726
autoconf ${"\\"}
2827
automake ${"\\"}
2928
libtool ${"\\"}
3029
curl ${"\\"}
31-
python-virtualenv ${"\\"}
32-
python-lxml ${"\\"}
3330
shellcheck
34-
RUN pip install simplejson mako
35-
31+
RUN python2 -m pip install simplejson mako virtualenv lxml
32+
RUN python3 -m pip install simplejson mako virtualenv lxml
33+
3634
<%include file="../../clang5.include"/>
37-
<%include file="../../run_tests_addons.include"/>
38-
35+
3936
# Define the default command.
4037
CMD ["bash"]
41-

tools/distrib/pylint_code.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ TEST_DIRS=(
3131
)
3232

3333
VIRTUALENV=python_pylint_venv
34-
python -m virtualenv $VIRTUALENV
34+
python3 -m virtualenv $VIRTUALENV
3535

3636
PYTHON=$VIRTUALENV/bin/python
3737

38-
$PYTHON -m pip install --upgrade pip==10.0.1
39-
$PYTHON -m pip install pylint==1.9.2
38+
$PYTHON -m pip install --upgrade pip==18.1
39+
$PYTHON -m pip install --upgrade pylint==2.2.2
4040

4141
EXIT=0
4242
for dir in "${DIRS[@]}"; do

tools/dockerfile/test/sanity/Dockerfile

+18-20
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM debian:jessie
16-
15+
FROM debian:stretch
16+
1717
# Install Git and basic packages.
1818
RUN apt-get update && apt-get install -y \
1919
autoconf \
@@ -53,37 +53,38 @@ RUN apt-get update && apt-get install -y time && apt-get clean
5353
RUN apt-get update && apt-get install -y python-pip && apt-get clean
5454
RUN pip install --upgrade google-api-python-client oauth2client
5555

56-
#====================
57-
# Python dependencies
56+
# Install Python 2.7
57+
RUN apt-get update && apt-get install -y python2.7 python-all-dev
58+
RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7
5859

59-
# Install dependencies
60+
# Add Debian 'testing' repository
61+
RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list
62+
RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local
6063

61-
RUN apt-get update && apt-get install -y \
62-
python-all-dev \
63-
python3-all-dev \
64-
python-pip
6564

66-
# Install Python packages from PyPI
67-
RUN pip install --upgrade pip==10.0.1
68-
RUN pip install virtualenv
69-
RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.2.post1 six==1.10.0 twisted==17.5.0
65+
RUN mkdir /var/local/jenkins
66+
67+
# Define the default command.
68+
CMD ["bash"]
7069

7170
#=================
7271
# C++ dependencies
7372
RUN apt-get update && apt-get -y install libgflags-dev libgtest-dev libc++-dev clang && apt-get clean
7473

7574
#========================
7675
# Sanity test dependencies
76+
RUN apt-get update && apt-get -t testing install -y python3.7 python3-all-dev
77+
RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7
78+
# Make Python 3.7 the default Python 3 version
79+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
7780
RUN apt-get update && apt-get install -y \
78-
python-pip \
7981
autoconf \
8082
automake \
8183
libtool \
8284
curl \
83-
python-virtualenv \
84-
python-lxml \
8585
shellcheck
86-
RUN pip install simplejson mako
86+
RUN python2 -m pip install simplejson mako virtualenv lxml
87+
RUN python3 -m pip install simplejson mako virtualenv lxml
8788

8889
RUN apt-get update && apt-get -y install wget xz-utils
8990
RUN wget http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu14.04.tar.xz
@@ -94,8 +95,5 @@ RUN ln -s /clang+llvm-5.0.0-linux-x86_64-ubuntu14.04/bin/clang-tidy /usr/local/b
9495
ENV CLANG_TIDY=clang-tidy
9596

9697

97-
RUN mkdir /var/local/jenkins
98-
99-
10098
# Define the default command.
10199
CMD ["bash"]

tools/run_tests/artifacts/build_artifact_protoc.sh

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515

1616
# Use devtoolset environment that has GCC 4.8 before set -ex
17+
# shellcheck disable=SC1091
1718
source scl_source enable devtoolset-2
1819

1920
set -ex

tools/run_tests/artifacts/build_artifact_ruby.sh

+2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ SYSTEM=$(uname | cut -f 1 -d_)
1818

1919
cd "$(dirname "$0")/../../.."
2020
set +ex
21+
# shellcheck disable=SC1091
2122
[[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh
23+
# shellcheck disable=SC1090
2224
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
2325
set -ex
2426

tools/run_tests/artifacts/run_in_workspace.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
set -ex
2020

2121
cd "$(dirname "$0")/../../.."
22-
export repo_root=$(pwd)
22+
repo_root=$(pwd)
23+
export repo_root
2324

2425
# TODO: fix file to pass shellcheck
2526

tools/run_tests/dockerize/build_and_run_docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set -ex
2020

2121
cd "$(dirname "$0")/../../.."
2222
git_root=$(pwd)
23-
cd -
23+
cd - # shellcheck disable=SC2103
2424

2525
# Inputs
2626
# DOCKERFILE_DIR - Directory in which Dockerfile file is located.

0 commit comments

Comments
 (0)