Repository: elastic/apm-agent-python

Issue:
Remove py2 leftovers
This is an issue to track all of the py2 stuff we can remove once a sufficient waiting period after 6.0 has passed.

- [x] Remove `zerorpc` (py2 only)
- [x] Remove `compat.py`
- [x] Run `pyupgrade`?

Ref #928 


Discussion:

Resolving patch:
diff --git a/elasticapm/contrib/zerorpc/__init__.py b/elasticapm/contrib/zerorpc/__init__.py
deleted file mode 100644
--- a/elasticapm/contrib/zerorpc/__init__.py
+++ /dev/null
@@ -1,84 +0,0 @@
-#  BSD 3-Clause License
-#
-#  Copyright (c) 2012, the Sentry Team, see AUTHORS for more details
-#  Copyright (c) 2019, Elasticsearch BV
-#  All rights reserved.
-#
-#  Redistribution and use in source and binary forms, with or without
-#  modification, are permitted provided that the following conditions are met:
-#
-#  * Redistributions of source code must retain the above copyright notice, this
-#    list of conditions and the following disclaimer.
-#
-#  * Redistributions in binary form must reproduce the above copyright notice,
-#    this list of conditions and the following disclaimer in the documentation
-#    and/or other materials provided with the distribution.
-#
-#  * Neither the name of the copyright holder nor the names of its
-#    contributors may be used to endorse or promote products derived from
-#    this software without specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-#  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-#  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-#  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
-
-import inspect
-
-from elasticapm.base import Client
-
-
-class Middleware(object):
-    """ElasticAPM middleware for ZeroRPC.
-
-    >>> elasticapm = Middleware(service_name='..', secret_token='...')
-    >>> zerorpc.Context.get_instance().register_middleware(elasticapm)
-
-    Exceptions detected server-side in ZeroRPC will be submitted to the apm server (and
-    propagated to the client as well).
-    """
-
-    def __init__(self, hide_zerorpc_frames=True, client=None, **kwargs):
-        """Create a middleware object that can be injected in a ZeroRPC server.
-
-        - hide_zerorpc_frames: modify the exception stacktrace to remove the
-                               internal zerorpc frames (True by default to make
-                               the stacktrace as readable as possible);
-        - client: use an existing raven.Client object, otherwise one will be
-                  instantiated from the keyword arguments.
-
-        """
-        self._elasticapm_client = client or Client(**kwargs)
-        self._hide_zerorpc_frames = hide_zerorpc_frames
-
-    def server_inspect_exception(self, req_event, rep_event, task_ctx, exc_info):
-        """Called when an exception has been raised in the code run by ZeroRPC"""
-
-        # Hide the zerorpc internal frames for readability, for a REQ/REP or
-        # REQ/STREAM server the frames to hide are:
-        # - core.ServerBase._async_task
-        # - core.Pattern*.process_call
-        # - core.DecoratorBase.__call__
-        #
-        # For a PUSH/PULL or PUB/SUB server the frame to hide is:
-        # - core.Puller._receiver
-        if self._hide_zerorpc_frames:
-            traceback = exc_info[2]
-            while traceback:
-                zerorpc_frame = traceback.tb_frame
-                zerorpc_frame.f_locals["__traceback_hide__"] = True
-                frame_info = inspect.getframeinfo(zerorpc_frame)
-                # Is there a better way than this (or looking up the filenames
-                # or hardcoding the number of frames to skip) to know when we
-                # are out of zerorpc?
-                if frame_info.function == "__call__" or frame_info.function == "_receiver":
-                    break
-                traceback = traceback.tb_next
-
-        self._elasticapm_client.capture_exception(exc_info, extra=task_ctx, handled=False)


Test patch:
diff --git a/tests/contrib/zerorpc/__init__.py b/tests/contrib/zerorpc/__init__.py
deleted file mode 100644
--- a/tests/contrib/zerorpc/__init__.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#  BSD 3-Clause License
-#
-#  Copyright (c) 2019, Elasticsearch BV
-#  All rights reserved.
-#
-#  Redistribution and use in source and binary forms, with or without
-#  modification, are permitted provided that the following conditions are met:
-#
-#  * Redistributions of source code must retain the above copyright notice, this
-#    list of conditions and the following disclaimer.
-#
-#  * Redistributions in binary form must reproduce the above copyright notice,
-#    this list of conditions and the following disclaimer in the documentation
-#    and/or other materials provided with the distribution.
-#
-#  * Neither the name of the copyright holder nor the names of its
-#    contributors may be used to endorse or promote products derived from
-#    this software without specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-#  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-#  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-#  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/tests/contrib/zerorpc/zeropc_tests.py b/tests/contrib/zerorpc/zeropc_tests.py
deleted file mode 100644
--- a/tests/contrib/zerorpc/zeropc_tests.py
+++ /dev/null
@@ -1,78 +0,0 @@
-#  BSD 3-Clause License
-#
-#  Copyright (c) 2019, Elasticsearch BV
-#  All rights reserved.
-#
-#  Redistribution and use in source and binary forms, with or without
-#  modification, are permitted provided that the following conditions are met:
-#
-#  * Redistributions of source code must retain the above copyright notice, this
-#    list of conditions and the following disclaimer.
-#
-#  * Redistributions in binary form must reproduce the above copyright notice,
-#    this list of conditions and the following disclaimer in the documentation
-#    and/or other materials provided with the distribution.
-#
-#  * Neither the name of the copyright holder nor the names of its
-#    contributors may be used to endorse or promote products derived from
-#    this software without specific prior written permission.
-#
-#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-#  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-#  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-#  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import os
-import random
-import shutil
-import sys
-import tempfile
-
-import pytest
-
-from elasticapm.conf.constants import ERROR
-from elasticapm.contrib.zerorpc import Middleware
-
-pytestmark = [
-    pytest.mark.zerorpc,
-    pytest.mark.skipif(sys.version_info >= (3, 4), reason="zerorpc>=0.4.0,0.5 not python 3 compatible"),
-]
-
-zerorpc = pytest.importorskip("zerorpc")
-gevent = pytest.importorskip("gevent")
-
-
-def test_zerorpc_middleware_with_reqrep(elasticapm_client):
-    tmpdir = tempfile.mkdtemp()
-    server_endpoint = "ipc://{0}".format(os.path.join(tmpdir, "random_zeroserver"))
-    try:
-        zerorpc.Context.get_instance().register_middleware(Middleware(client=elasticapm_client))
-        server = zerorpc.Server(random)
-        server.bind(server_endpoint)
-        gevent.spawn(server.run)
-
-        client = zerorpc.Client()
-        client.connect(server_endpoint)
-
-        with pytest.raises(zerorpc.exceptions.RemoteError) as excinfo:
-            client.choice([])
-
-        client.close()
-        server.close()
-    finally:
-        shutil.rmtree(tmpdir, ignore_errors=True)
-    ex = excinfo.value
-    assert ex.name == "IndexError"
-    assert len(elasticapm_client.events) == 1
-    exc = elasticapm_client.events[ERROR][0]["exception"]
-    assert exc["type"] == "IndexError"
-    frames = exc["stacktrace"]
-    assert frames[0]["function"] == "choice"
-    assert frames[0]["module"] == "random"
-    assert exc["handled"] is False
diff --git a/tests/requirements/reqs-zerorpc-0.4.txt b/tests/requirements/reqs-zerorpc-0.4.txt
deleted file mode 100644
--- a/tests/requirements/reqs-zerorpc-0.4.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-pyzmq==16.0.2 ; python_version == '2.7'
-gevent<1.2.0 ; python_version == '2.7'
-zerorpc>=0.4.0,<0.5 ; python_version == '2.7'
--r reqs-base.txt
diff --git a/tests/scripts/envs/zerorpc.sh b/tests/scripts/envs/zerorpc.sh
deleted file mode 100644
--- a/tests/scripts/envs/zerorpc.sh
+++ /dev/null
@@ -1 +0,0 @@
-export PYTEST_MARKER="-m zerorpc"