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

refactor!: remove python2 #78

Merged
merged 27 commits into from Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8edfc2a
ignore arguments
daniel-sanche Oct 13, 2020
3279e8c
updated pubsub to use requests
daniel-sanche Oct 13, 2020
35e844a
fixed lint issues
daniel-sanche Oct 13, 2020
5fe8f35
pulled in kokoro changes from autosynth branch
daniel-sanche Oct 13, 2020
1baba7a
added decrypt-secrets script
daniel-sanche Oct 13, 2020
1358e73
added testing dir
daniel-sanche Oct 13, 2020
ba4464a
added empty snippets dir
daniel-sanche Oct 13, 2020
323ff90
check if samples directory exists
daniel-sanche Oct 13, 2020
160ea80
echo before upload
daniel-sanche Oct 13, 2020
0da6ac6
removed python 2.7 tests
daniel-sanche Oct 13, 2020
a5e4af7
added back 2.7 unit tests
daniel-sanche Oct 13, 2020
b7eb5d9
comment out upload
daniel-sanche Oct 13, 2020
4233e95
moved comment
daniel-sanche Oct 13, 2020
d46057b
print env
daniel-sanche Oct 14, 2020
8795c02
removed env print
daniel-sanche Oct 15, 2020
4e9debd
added trampolinerc
daniel-sanche Oct 15, 2020
6b2cc10
pulled in test-samples from upstream
daniel-sanche Oct 15, 2020
5491715
brought in changes from #66
daniel-sanche Oct 15, 2020
56d7b53
removed python 2 references
daniel-sanche Oct 15, 2020
3a79a38
use latest pubsub
daniel-sanche Oct 15, 2020
2c042b8
use upstream nox file
daniel-sanche Oct 15, 2020
405476c
fixed lint issue
daniel-sanche Oct 26, 2020
b2c7713
Merge branch 'master' into remove-python-2
daniel-sanche Oct 26, 2020
731983f
reverted synth.py
daniel-sanche Oct 26, 2020
e160d71
removed python2 from setup.py
daniel-sanche Oct 26, 2020
572e24d
removed unneeded imports
daniel-sanche Oct 27, 2020
dc96567
Merge branch 'master' into remove-python-2
daniel-sanche Oct 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 0 additions & 38 deletions google/cloud/logging/handlers/_helpers.py
Expand Up @@ -22,20 +22,10 @@
except ImportError: # pragma: NO COVER
flask = None

try:
import webapp2
except (ImportError, SyntaxError): # pragma: NO COVER
# If you try to import webapp2 under python3, you'll get a syntax
# error (since it hasn't been ported yet). We just pretend it
# doesn't exist. This is unlikely to hit in real life but does
# in the tests.
webapp2 = None

from google.cloud.logging.handlers.middleware.request import _get_django_request

_DJANGO_TRACE_HEADER = "HTTP_X_CLOUD_TRACE_CONTEXT"
_FLASK_TRACE_HEADER = "X_CLOUD_TRACE_CONTEXT"
_WEBAPP2_TRACE_HEADER = "X-CLOUD-TRACE-CONTEXT"


def format_stackdriver_json(record, message):
Expand Down Expand Up @@ -75,33 +65,6 @@ def get_trace_id_from_flask():
return trace_id


def get_trace_id_from_webapp2():
"""Get trace_id from webapp2 request headers.

:rtype: str
:returns: TraceID in HTTP request headers.
"""
if webapp2 is None:
return None

try:
# get_request() succeeds if we're in the middle of a webapp2
# request, or raises an assertion error otherwise:
# "Request global variable is not set".
req = webapp2.get_request()
except AssertionError:
return None

header = req.headers.get(_WEBAPP2_TRACE_HEADER)

if header is None:
return None

trace_id = header.split("/", 1)[0]

return trace_id


def get_trace_id_from_django():
"""Get trace_id from django request headers.

Expand Down Expand Up @@ -131,7 +94,6 @@ def get_trace_id():
checkers = (
get_trace_id_from_django,
get_trace_id_from_flask,
get_trace_id_from_webapp2,
)

for checker in checkers:
Expand Down
5 changes: 1 addition & 4 deletions google/cloud/logging/handlers/middleware/request.py
Expand Up @@ -34,11 +34,8 @@ def _get_django_request():


try:
# Django >= 1.10
from django.utils.deprecation import MiddlewareMixin
except ImportError:
# Not required for Django <= 1.9, see:
# https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware
except ImportError: # pragma: NO COVER
MiddlewareMixin = object


Expand Down
18 changes: 3 additions & 15 deletions noxfile.py
Expand Up @@ -26,8 +26,8 @@
'pytest',
'pytest-cov',
'flask',
'webapp2',
'webob',
'django'
)


Expand Down Expand Up @@ -71,13 +71,12 @@ def lint_setup_py(session):
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")


def default(session, django_dep=('django',)):
def default(session):
"""Default unit test session.
"""

# Install all test dependencies, then install this package in-place.
deps = UNIT_TEST_DEPS
deps += django_dep

session.install(*deps)
session.install('-e', '.')
Expand All @@ -100,18 +99,7 @@ def default(session, django_dep=('django',)):
@nox.session(python=['3.5', '3.6', '3.7'])
def unit(session):
"""Run the unit test suite."""

# Testing multiple version of django
# See https://www.djangoproject.com/download/ for supported version
django_deps_27 = [
('django==1.8.19',),
('django >= 1.11.0, < 2.0.0dev',),
]

if session.virtualenv.interpreter == '2.7':
[default(session, django_dep=django) for django in django_deps_27]
else:
default(session)
default(session)


@nox.session(python=['3.6'])
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Expand Up @@ -70,8 +70,6 @@
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
Expand All @@ -84,7 +82,7 @@
namespace_packages=namespaces,
install_requires=dependencies,
extras_require=extras,
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
python_requires='>=3.5',
include_package_data=True,
zip_safe=False,
)
53 changes: 0 additions & 53 deletions tests/unit/handlers/test__helpers.py
Expand Up @@ -12,18 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

import mock
import six

try:
from webapp2 import RequestHandler
except SyntaxError:
# webapp2 has not been ported to python3, so it will give a syntax
# error if we try. We'll just skip the webapp2 tests in that case.
RequestHandler = object


class Test_get_trace_id_from_flask(unittest.TestCase):
Expand Down Expand Up @@ -68,50 +59,6 @@ def test_valid_context_header(self):
self.assertEqual(trace_id, expected_trace_id)


class _GetTraceId(RequestHandler):
def get(self):
from google.cloud.logging.handlers import _helpers

trace_id = _helpers.get_trace_id_from_webapp2()
self.response.content_type = "application/json"
self.response.out.write(json.dumps(trace_id))


@unittest.skipIf(not six.PY2, "webapp2 is Python 2 only")
class Test_get_trace_id_from_webapp2(unittest.TestCase):
@staticmethod
def create_app():
import webapp2

app = webapp2.WSGIApplication([("/", _GetTraceId)])

return app

def test_no_context_header(self):
import webob

req = webob.BaseRequest.blank("/")
response = req.get_response(self.create_app())
trace_id = json.loads(response.body)

self.assertEqual(None, trace_id)

def test_valid_context_header(self):
import webob

webapp2_trace_header = "X-Cloud-Trace-Context"
expected_trace_id = "testtraceidwebapp2"
webapp2_trace_id = expected_trace_id + "/testspanid"

req = webob.BaseRequest.blank(
"/", headers={webapp2_trace_header: webapp2_trace_id}
)
response = req.get_response(self.create_app())
trace_id = json.loads(response.body)

self.assertEqual(trace_id, expected_trace_id)


class Test_get_trace_id_from_django(unittest.TestCase):
@staticmethod
def _call_fut():
Expand Down