gnocchixyz / gnocchi

Timeseries database
Apache License 2.0
302 stars 85 forks source link

image: hack jaraco.text and werkzeug to fix CI #1395

Closed tobias-urdin closed 3 months ago

tobias-urdin commented 3 months ago

we get a collision because jaraco.text is installed in site-packages but we want a newer version when testing.

werkzeug dist package in ubuntu works with python 3.10 but not 3.9, this fixes that, the hack can be removed when we drop 3.9 support

Callum027 commented 3 months ago

Hi @tobias-urdin, I believe I have found the cause of the Werkzeug errors.

It looks like the system python3-werkzeug package is being used in the test, as shown in the traceback below.

  File "/usr/lib/python3/dist-packages/werkzeug/__init__.py", line 2, in <module>
    from .test import Client as Client
  File "/usr/lib/python3/dist-packages/werkzeug/test.py", line 42, in <module>
    from .utils import get_content_type
  File "/usr/lib/python3/dist-packages/werkzeug/utils.py", line 25, in <module>
    from .wsgi import wrap_file
  File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 11, in <module>
    from .sansio import utils as _sansio_utils
  File "/usr/lib/python3/dist-packages/werkzeug/sansio/utils.py", line 9, in <module>
    def host_is_trusted(hostname: str | None, trusted_list: t.Iterable[str]) -> bool:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

The latest version for Jammy (2.0.2+dfsg1-1ubuntu0.22.04.2) appears to have some non-standard patches on top of version 2.0.2. werkzeug/sansio/utils.py appears to patch in the modern type hints, but not delayed annotation evaluation using from __future__ import annotations.

root@45111dbf5eae:/# dpkg -l | grep python3-werkzeug
ii  python3-werkzeug            2.0.2+dfsg1-1ubuntu0.22.04.2            all          collection of utilities for WSGI applications (Python 3.x)
root@45111dbf5eae:/# head -n17 /usr/lib/python3/dist-packages/werkzeug/sansio/utils.py 
import typing as t

from .._internal import _encode_idna
from ..exceptions import SecurityError
from ..urls import uri_to_iri
from ..urls import url_quote

def host_is_trusted(hostname: str | None, trusted_list: t.Iterable[str]) -> bool:
    """Check if a host matches a list of trusted names.

    :param hostname: The name to check.
    :param trusted_list: A list of valid names to match. If a name
        starts with a dot it will match all subdomains.

    .. versionadded:: 0.9
    """

This is actually fine for Python 3.10 (the system Python for Ubuntu Jammy), but broken for Python 3.9 obviously. You'll want to override this in the Gnocchi virtualenv.

tobias-urdin commented 3 months ago

Hi @tobias-urdin, I believe I have found the cause of the Werkzeug errors.

It looks like the system python3-werkzeug package is being used in the test, as shown in the traceback below.

  File "/usr/lib/python3/dist-packages/werkzeug/__init__.py", line 2, in <module>
    from .test import Client as Client
  File "/usr/lib/python3/dist-packages/werkzeug/test.py", line 42, in <module>
    from .utils import get_content_type
  File "/usr/lib/python3/dist-packages/werkzeug/utils.py", line 25, in <module>
    from .wsgi import wrap_file
  File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 11, in <module>
    from .sansio import utils as _sansio_utils
  File "/usr/lib/python3/dist-packages/werkzeug/sansio/utils.py", line 9, in <module>
    def host_is_trusted(hostname: str | None, trusted_list: t.Iterable[str]) -> bool:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

The latest version for Jammy (2.0.2+dfsg1-1ubuntu0.22.04.2) appears to have some non-standard patches on top of version 2.0.2. werkzeug/sansio/utils.py appears to patch in the modern type hints, but not delayed annotation evaluation using from __future__ import annotations.

root@45111dbf5eae:/# dpkg -l | grep python3-werkzeug
ii  python3-werkzeug            2.0.2+dfsg1-1ubuntu0.22.04.2            all          collection of utilities for WSGI applications (Python 3.x)
root@45111dbf5eae:/# head -n17 /usr/lib/python3/dist-packages/werkzeug/sansio/utils.py 
import typing as t

from .._internal import _encode_idna
from ..exceptions import SecurityError
from ..urls import uri_to_iri
from ..urls import url_quote

def host_is_trusted(hostname: str | None, trusted_list: t.Iterable[str]) -> bool:
    """Check if a host matches a list of trusted names.

    :param hostname: The name to check.
    :param trusted_list: A list of valid names to match. If a name
        starts with a dot it will match all subdomains.

    .. versionadded:: 0.9
    """

This is actually fine for Python 3.10 (the system Python for Ubuntu Jammy), but broken for Python 3.9 obviously. You'll want to override this in the Gnocchi virtualenv.

thanks for the details, looks like it's passing now

tobias-urdin commented 3 months ago

@mergifyio backport stable/4.6

mergify[bot] commented 3 months ago

backport stable/4.6

✅ Backports have been created

* [#1399 image: hack jaraco.text and werkzeug to fix CI (backport #1395)](https://github.com/gnocchixyz/gnocchi/pull/1399) has been created for branch `stable/4.6`