Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.

Commit 1cb8e52

Browse files
cedyyurishkuro
andauthored
Remove Python2 support from code and CI (#307)
* Remove python2 tests from CI Signed-off-by: George Leman <[email protected]> * Update crossdock image to python 3.9 Signed-off-by: George Leman <[email protected]> * Remove python 2 mentions from code Signed-off-by: George Leman <[email protected]> * Make python2 tests run on python3 Signed-off-by: George Leman <[email protected]> * Install tchannel in setup.py Signed-off-by: George Leman <[email protected]> * Fix failing tests Signed-off-by: Yuri Shkuro <[email protected]> * Fix crossdock tests for Tornado 6+ Signed-off-by: Yuri Shkuro <[email protected]> * Fix tornado exclusion Signed-off-by: Yuri Shkuro <[email protected]> * Decode request.body Signed-off-by: George Leman <[email protected]> * Convert to str before loading json data Signed-off-by: George Leman <[email protected]> * Convert to str before loading json data Signed-off-by: George Leman <[email protected]> Co-authored-by: Yuri Shkuro <[email protected]>
1 parent 72a1dd1 commit 1cb8e52

File tree

11 files changed

+37
-48
lines changed

11 files changed

+37
-48
lines changed

.github/workflows/ci-crossdock.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- uses: actions/setup-python@v2
2121
with:
22-
python-version: 2.7
22+
python-version: 3.9
2323

2424
- uses: docker/login-action@v1
2525
id: dockerhub-login

.github/workflows/ci-unit-tests.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ jobs:
1414
strategy:
1515
matrix:
1616
version:
17-
- python: "2.7"
18-
tornado: ">=4,<5"
19-
- python: "2.7"
20-
tornado: ">=5,<6"
2117
- python: "3.5"
2218
tornado: ">=4,<5"
2319
- python: "3.5"

CONTRIBUTING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ ImportError: pycurl: libcurl link-time ssl backend (openssl) is different from c
3434
It can be fixed with:
3535

3636
```
37+
OPENSSL=/usr/local/opt/openssl
3738
pip uninstall pycurl
38-
export LDFLAGS="-L/usr/local/opt/openssl/lib"
39-
export CPPFLAGS="-I/usr/local/opt/openssl/include"
39+
export LDFLAGS="-L$OPENSSL/lib"
40+
export CPPFLAGS="-I$OPENSSL/include"
4041
export PYCURL_SSL_LIBRARY=openssl
41-
pip install --no-cache-dir --compile --ignore-installed --install-option="--with-openssl" --install-option="--openssl-dir=/usr/local/opt/openssl" pycurl
42+
pip install --no-cache-dir --compile --ignore-installed --install-option="--with-openssl" --install-option="--openssl-dir=$OPENSSL" pycurl
4243
```
4344

4445
## Making A Change

crossdock/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:2.7
1+
FROM python:3.9
22

33
ARG tornado
44
ENV APPDIR /usr/src/app/
@@ -20,7 +20,7 @@ COPY crossdock/setup_crossdock.py ${APPDIR}
2020
RUN python setup_crossdock.py install
2121

2222
# TODO Remove this after the tchannel-python crossdock is no longer a package
23-
RUN rm -rf /usr/local/lib/python2.7/site-packages/crossdock
23+
RUN rm -rf /usr/local/lib/python3.9/site-packages/crossdock
2424

2525
CMD ["crossdock"]
2626
EXPOSE 8080-8082

crossdock/server/endtoend.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ def local_agent_sender(self):
116116

117117
@tornado.gen.coroutine
118118
def generate_traces(self, request, response_writer):
119+
if isinstance(request.body, (bytes, bytearray)):
120+
request.body = request.body.decode('utf-8')
119121
req = json.loads(request.body)
120122
sampler_type = req.get('type', 'remote')
121123
tracer = self.tracers[sampler_type]
122124
for _ in range(req.get('count', 0)):
123125
span = tracer.start_span(req['operation'])
124-
for k, v in req.get('tags', {}).iteritems():
126+
for k, v in req.get('tags', {}).items():
125127
span.set_tag(k, v)
126128
span.finish()
127129
response_writer.finish()

crossdock/server/serializer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ def set_downstream_object_values(downstream_object, json_obj):
2727

2828

2929
def join_trace_request_from_json(json_request):
30+
if isinstance(json_request, (bytes, bytearray)):
31+
json_request = json_request.decode('utf-8')
3032
request = JoinTraceRequest()
3133
set_downstream_object_values(request, json.loads(json_request))
3234
return request
3335

3436

3537
def start_trace_request_from_json(json_request):
38+
if isinstance(json_request, (bytes, bytearray)):
39+
json_request = json_request.decode('utf-8')
3640
request = StartTraceRequest()
3741
set_downstream_object_values(request, json.loads(json_request))
3842
return request
@@ -75,6 +79,8 @@ def traceresponse_from_struct(json_obj):
7579

7680
def traceresponse_from_json(json_str):
7781
try:
82+
if isinstance(json_str, (bytes, bytearray)):
83+
json_str = json_str.decode('utf-8')
7884
return traceresponse_from_struct(json.loads(json_str))
7985
except: # noqa: E722
8086
logging.exception('Failed to parse JSON')
@@ -107,7 +113,7 @@ def traced_service_object_to_json(obj):
107113

108114

109115
def set_traced_service_object_values(obj, values, downstream_func):
110-
for k in values.iterkeys():
116+
for k in values.keys():
111117
if hasattr(obj, k):
112118
if k == 'downstream':
113119
if values[k] is not None:

jaeger_client/codecs.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,15 @@ def inject(self, span_context, carrier):
6565
if baggage:
6666
for key, value in six.iteritems(baggage):
6767
encoded_key = key
68+
if isinstance(key, six.binary_type):
69+
encoded_key = str(key, 'utf-8')
6870
if self.url_encoding:
69-
if six.PY2 and isinstance(value, six.text_type):
70-
encoded_value = urllib_parse.quote(value.encode('utf-8'))
71-
else:
72-
encoded_value = urllib_parse.quote(value)
73-
# we assume that self.url_encoding means we are injecting
74-
# into HTTP headers. httplib does not like unicode strings
75-
# so we convert the key to utf-8. The URL-encoded value is
76-
# already a plain string.
77-
if six.PY2 and isinstance(key, six.text_type):
78-
encoded_key = key.encode('utf-8')
71+
encoded_value = urllib_parse.quote(value)
7972
else:
80-
if six.PY3 and isinstance(value, six.binary_type):
73+
if isinstance(value, six.binary_type):
8174
encoded_value = str(value, 'utf-8')
8275
else:
8376
encoded_value = value
84-
if six.PY3 and isinstance(key, six.binary_type):
85-
encoded_key = str(key, 'utf-8')
8677
# Leave the below print(), you will thank me next time you debug unicode strings
8778
# print('adding baggage', key, '=>', value, 'as', encoded_key, '=>', encoded_value)
8879
header_key = '%s%s' % (self.baggage_prefix, encoded_key)

jaeger_client/thrift.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ def id_to_int(big_id):
5959

6060
def _to_string(s):
6161
try:
62-
# Thrift in PY2 likes strings as bytes
63-
if six.PY2 and isinstance(s, six.text_type):
64-
return s.encode('utf-8')
65-
else:
66-
return str(s)
62+
return str(s)
6763
except Exception as e:
6864
return str(e)
6965

setup.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
'Intended Audience :: Developers',
3333
'License :: OSI Approved :: Apache Software License',
3434
'Natural Language :: English',
35-
'Programming Language :: Python :: 2.7',
3635
'Programming Language :: Python :: 3.5',
3736
'Programming Language :: Python :: 3.6',
3837
],
@@ -48,9 +47,6 @@
4847
# ],
4948
test_suite='tests',
5049
extras_require={
51-
':python_version<"3"': [
52-
'futures',
53-
],
5450
'tests': [
5551
'mock==1.0.1',
5652
'pycurl>=7.43,<8',
@@ -66,7 +62,7 @@
6662
'flake8',
6763
'flake8-quotes',
6864
'codecov',
69-
'tchannel>=0.27;python_version=="2.7"', # This is only used in python 2
65+
'tchannel==2.1.0',
7066
'opentracing_instrumentation>=3,<4',
7167
'prometheus_client==0.3.1',
7268
]

tests/test_codecs.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_context_to_readable_headers(self):
119119
ctx._baggage = {
120120
'bender': 'Countess de la Roca',
121121
'fry': u'Leela',
122-
b'key1': bytes(chr(75)) if six.PY2 else bytes([75]),
122+
b'key1': bytes([75]),
123123
u'key2': 'cafe',
124124
u'key3': u'\U0001F47E',
125125
}
@@ -526,12 +526,8 @@ def test_debug_id():
526526

527527

528528
def test_baggage_as_unicode_strings_with_httplib(httpserver):
529-
if six.PY2:
530-
import urllib2
531-
urllib_under_test = urllib2
532-
else:
533-
import urllib.request
534-
urllib_under_test = urllib.request
529+
import urllib.request
530+
urllib_under_test = urllib.request
535531

536532
# httpserver is provided by pytest-localserver
537533
httpserver.serve_content(content='Hello', code=200, headers=None)
@@ -548,7 +544,7 @@ def test_baggage_as_unicode_strings_with_httplib(httpserver):
548544
(b'key1', b'value'),
549545
(u'key2', b'value'),
550546
('key3', u'value'),
551-
(b'key4', bytes(chr(255)) if six.PY2 else bytes([255])),
547+
(b'key4', bytes([255])),
552548
(u'key5', u'\U0001F47E')
553549
]
554550
for b in baggage:

0 commit comments

Comments
 (0)