Repository: getsentry/sentry-python

Issue:
Version check of gevent breaks if version contains alphanumeric characters
### Environment

In the process of moving to Sentry Saas.

Python SDK 1.3.1

### Steps to Reproduce

```
pip install sentry-sdk==1.3.1
```
Try to run some unit tests afterwards.

### Expected Result

Able to start tests.

### Actual Result

```
../../../.pyenv/versions/3.5.3/lib/python3.5/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:986: in _gcd_import
    ???
<frozen importlib._bootstrap>:969: in _find_and_load
    ???
<frozen importlib._bootstrap>:958: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:673: in _load_unlocked
    ???
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:171: in exec_module
    exec(co, module.__dict__)
expand/utils/tests/conftest.py:8: in <module>
    import sentry_sdk
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/__init__.py:1: in <module>
    from sentry_sdk.hub import Hub, init
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/hub.py:8: in <module>
    from sentry_sdk.scope import Scope
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/scope.py:7: in <module>
    from sentry_sdk.utils import logger, capture_internal_exceptions
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/utils.py:882: in <module>
    HAS_REAL_CONTEXTVARS, ContextVar = _get_contextvars()
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/utils.py:852: in _get_contextvars
    if not _is_contextvars_broken():
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/utils.py:792: in _is_contextvars_broken
    version_tuple = tuple([int(part) for part in gevent.__version__.split(".")[:2]])
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/utils.py:792: in <listcomp>
    version_tuple = tuple([int(part) for part in gevent.__version__.split(".")[:2]])
E   ValueError: invalid literal for int() with base 10: '5a2'
```

I am aware we are using older versions of Python and gevent but might happen again with newer versions also.
Version check of gevent breaks if version contains alphanumeric characters
### Environment

In the process of moving to Sentry Saas.

Python SDK 1.3.1

### Steps to Reproduce

```
pip install sentry-sdk==1.3.1
```
Try to run some unit tests afterwards.

### Expected Result

Able to start tests.

### Actual Result

```
../../../.pyenv/versions/3.5.3/lib/python3.5/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:986: in _gcd_import
    ???
<frozen importlib._bootstrap>:969: in _find_and_load
    ???
<frozen importlib._bootstrap>:958: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:673: in _load_unlocked
    ???
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:171: in exec_module
    exec(co, module.__dict__)
expand/utils/tests/conftest.py:8: in <module>
    import sentry_sdk
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/__init__.py:1: in <module>
    from sentry_sdk.hub import Hub, init
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/hub.py:8: in <module>
    from sentry_sdk.scope import Scope
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/scope.py:7: in <module>
    from sentry_sdk.utils import logger, capture_internal_exceptions
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/utils.py:882: in <module>
    HAS_REAL_CONTEXTVARS, ContextVar = _get_contextvars()
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/utils.py:852: in _get_contextvars
    if not _is_contextvars_broken():
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/utils.py:792: in _is_contextvars_broken
    version_tuple = tuple([int(part) for part in gevent.__version__.split(".")[:2]])
../../../.pyenv/versions/3.5.3/envs/expand-core/lib/python3.5/site-packages/sentry_sdk/utils.py:792: in <listcomp>
    version_tuple = tuple([int(part) for part in gevent.__version__.split(".")[:2]])
E   ValueError: invalid literal for int() with base 10: '5a2'
```

I am aware we are using older versions of Python and gevent but might happen again with newer versions also.


Discussion:

Resolving patch:
diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py
--- a/sentry_sdk/utils.py
+++ b/sentry_sdk/utils.py
@@ -792,7 +792,9 @@ def _is_contextvars_broken():
         from gevent.monkey import is_object_patched  # type: ignore
 
         # Get the MAJOR and MINOR version numbers of Gevent
-        version_tuple = tuple([int(part) for part in gevent.__version__.split(".")[:2]])
+        version_tuple = tuple(
+            [int(part) for part in re.split(r"a|b|rc|\.", gevent.__version__)[:2]]
+        )
         if is_object_patched("threading", "local"):
             # Gevent 20.9.0 depends on Greenlet 0.4.17 which natively handles switching
             # context vars when greenlets are switched, so, Gevent 20.9.0+ is all fine.


Test patch: