getsentry / raven-python

Raven is the legacy Python client for Sentry (getsentry.com) — replaced by sentry-python
https://sentry.io
BSD 3-Clause "New" or "Revised" License
1.68k stars 657 forks source link

Installing raven can fail due to new contextlib2 version (released June 27, 2021) that dropped python2 support #1371

Open bhogan125 opened 3 years ago

bhogan125 commented 3 years ago

Environment

Python2.7 environment that imports raven

Steps to Reproduce

  1. Have a python2.7.X project that includes raven as a dependency (tested via raven==6.10.0) and pip install
  2. Try to import raven in a file (or in the repl)
  3. Watch the syntax error pop up due to contextlib2==21.6.0 (released June 27th 2021) using async code

This stems from https://github.com/getsentry/raven-python/blob/master/setup.py#L133 . That version specification for contextlib2 no longer works since contextlib2 released a new version on June 27th, 2021 which is tagged as supporting python3, and raven just checks for a version that supports anything less than python 3.2. This should be updated to either hardcode the last contextlib2 version (0.6.0.post1), or by specifying any version that supports < python 3

Expected Result

I expected raven to be installed correctly via pip in a python2.7 environment and to be able to import and use raven as normal.

This is for work and we are trying to migrate off this environment, but can't for the foreseeable future.

Actual Result

Traceback (most recent call last):
  File "/usr/local/bin/initialize_theano", line 11, in <module>
      load_entry_point(......)()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 489, in load_entry_point
      return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
      return ep.load()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2443, in load
      return self.resolve()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2449, in resolve
      module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/workdir/svar_extractor/utils.py", line 12, in <module>
      from pylib.utils import log, metrics, redis_utils, sentry, status
  File "/usr/local/lib/python2.7/dist-packages/pylib-1.0.0-py2.7.egg/pylib/utils/sentry.py", line 10, in <module>
      import raven
  File "/usr/local/lib/python2.7/dist-packages/raven/__init__.py", line 49, in <module>
      from raven.base import *  # NOQA
  File "/usr/local/lib/python2.7/dist-packages/raven/base.py", line 28, in <module>
      import contextlib2 as contextlib
  File "/usr/local/lib/python2.7/dist-packages/contextlib2/__init__.py", line 56
      async def __aenter__(self):
                ^
                SyntaxError: invalid syntax

Workarounds

In any project that depends on raven, just set contextlib2==0.6.0.post1 in your requirements file to guarantee you get a python2 compatible version

graingert commented 3 years ago

contextlib2 sets python_requires: https://github.com/jazzband/contextlib2/blob/0828b5a3322a148de8fdaf7443fefda983e7e9c8/setup.py#L10

you probably need to do pip install pip-with-requires-python before installing raven