Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

tobias-urdin
Copy link
Contributor

@tobias-urdin tobias-urdin commented Aug 13, 2024

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

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

Callum027 commented Aug 15, 2024

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.

this is required for python 3.9 until
we drop that.
@tobias-urdin tobias-urdin force-pushed the remove-dist-jaraco-text branch from 04d18d1 to 070074a Compare August 15, 2024 08:41
@tobias-urdin tobias-urdin changed the title image: hack remove distro installed jaraco.text image: hack jaraco.text and werkzeug to fix CI Aug 15, 2024
@tobias-urdin
Copy link
Contributor Author

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 tobias-urdin merged commit dd2d63e into gnocchixyz:master Aug 15, 2024
23 checks passed
@tobias-urdin
Copy link
Contributor Author

@Mergifyio backport stable/4.6

Copy link
Contributor

mergify bot commented Aug 20, 2024

backport stable/4.6

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants