Skip to content

Commit 72a781b

Browse files
basepibmorelli25
andauthored
Add deprecation warnings for python 2 (#809)
* Add deprecation warnings for python 2 * Use PendingDeprecationWarning and update docs * Update docs/index.asciidoc Co-Authored-By: Brandon Morelli <bmorelli25@gmail.com> Co-authored-by: Brandon Morelli <bmorelli25@gmail.com>
1 parent c1e6f73 commit 72a781b

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

docs/index.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ endif::[]
88

99
= APM Python Agent Reference
1010

11+
NOTE: Python 2.7 reached End of Life on January 1, 2020.
12+
The Elastic APM agent will stop supporting Python 2.7 starting in version 6.0.0.
13+
1114
include::./getting-started.asciidoc[]
1215

1316
include::./set-up.asciidoc[]

docs/supported-technologies.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ The following Python versions are supported:
2424
* 3.7
2525
* 3.8
2626

27-
WARNING: Python 2.7 will reach End of Life on January 1, 2020.
28-
The Elastic APM agent will stop supporting Python 2.7 in the first major version after that date.
27+
WARNING: Python 2.7 reached End of Life on January 1, 2020.
28+
The Elastic APM agent will stop supporting Python 2.7 starting in 6.0.0.
2929

3030
[float]
3131
[[supported-django]]

elasticapm/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,16 @@ def load_processors(self):
530530

531531
def check_python_version(self):
532532
v = tuple(map(int, platform.python_version_tuple()[:2]))
533-
if (2, 7) < v < (3, 5):
534-
warnings.warn("The Elastic APM agent only supports Python 2.7 and 3.5+", DeprecationWarning)
533+
if v == (2, 7):
534+
warnings.warn(
535+
(
536+
"The Elastic APM agent will stop supporting Python 2.7 starting in 6.0.0 -- "
537+
"Please upgrade to Python 3.5+ to continue to use the latest features."
538+
),
539+
PendingDeprecationWarning,
540+
)
541+
elif v < (3, 5):
542+
warnings.warn("The Elastic APM agent only supports Python 3.5+", DeprecationWarning)
535543

536544

537545
class DummyClient(Client):

tests/client/client_tests.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,16 @@ def test_server_url_joining(elasticapm_client, expected):
770770

771771

772772
@pytest.mark.parametrize(
773-
"version,raises",
774-
[(("2", "7", "0"), False), (("3", "3", "0"), True), (("3", "4", "0"), True), (("3", "5", "0"), False)],
773+
"version,raises,pending",
774+
[
775+
(("2", "7", "0"), True, True),
776+
(("3", "3", "0"), True, False),
777+
(("3", "4", "0"), True, False),
778+
(("3", "5", "0"), False, False),
779+
],
775780
)
776781
@mock.patch("platform.python_version_tuple")
777-
def test_python_version_deprecation(mock_python_version_tuple, version, raises, recwarn):
782+
def test_python_version_deprecation(mock_python_version_tuple, version, raises, pending, recwarn):
778783
warnings.simplefilter("always")
779784

780785
mock_python_version_tuple.return_value = version
@@ -786,7 +791,11 @@ def test_python_version_deprecation(mock_python_version_tuple, version, raises,
786791
e.close()
787792
if raises:
788793
assert len(recwarn) == 1
789-
w = recwarn.pop(DeprecationWarning)
790-
assert "agent only supports" in w.message.args[0]
794+
if pending:
795+
w = recwarn.pop(PendingDeprecationWarning)
796+
assert "will stop supporting" in w.message.args[0]
797+
else:
798+
w = recwarn.pop(DeprecationWarning)
799+
assert "agent only supports" in w.message.args[0]
791800
else:
792801
assert len(recwarn) == 0

0 commit comments

Comments
 (0)