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

Remove support for grpclib #71

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

## Upgrading

- `grpclib` was removed, if you used `grpclib` you should switch to `grpcio` instead.

You should also update your dependency to `frequenz-client-base` (without any `[grpclib]` or `[grpcio]` suffix).

- The `parse_grpc_uri` function (and `BaseApiClient` constructor) now enables SSL by default (`ssl=false` should be passed to disable it).

- The `parse_grpc_uri` function now accepts an optional `default_ssl` parameter to set the default value for the `ssl` parameter when not present in the URI.

## New Features
Expand Down
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ plugins:
- https://frequenz-floss.github.io/frequenz-channels-python/v1.0-pre/objects.inv
- https://googleapis.dev/python/protobuf/latest/objects.inv
- https://grpc.github.io/grpc/python/objects.inv
- https://grpclib.readthedocs.io/en/latest/objects.inv
- https://typing-extensions.readthedocs.io/en/stable/objects.inv
# Note this plugin must be loaded after mkdocstrings to be able to use macros
# inside docstrings. See the comment in `docs/_scripts/macros.py` for more
Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ classifiers = [
requires-python = ">= 3.11, < 4"
dependencies = [
"frequenz-channels >= v1.0.0-rc1, < 2",
"grpcio >= 1.54.2, < 2",
"protobuf >= 4.21.6, < 6",
"typing-extensions >= 4.5.0, < 5",
]
Expand All @@ -37,15 +38,13 @@ name = "Frequenz Energy-as-a-Service GmbH"
email = "floss@frequenz.com"

[project.optional-dependencies]
grpcio = ["grpcio >= 1.54.2, < 2"]
grpclib = ["grpclib >= 0.4.0, < 0.5"]
dev-flake8 = [
"flake8 == 7.1.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.5.3",
"pydocstyle == 6.3.0",
"frequenz-client-base[grpclib,grpcio]",
"frequenz-client-base",
]
dev-formatting = ["black == 24.4.2", "isort == 5.13.2"]
dev-mkdocs = [
Expand All @@ -58,7 +57,7 @@ dev-mkdocs = [
"mkdocs-material == 9.5.27",
"mkdocstrings[python] == 0.25.1",
"frequenz-repo-config[lib] == 0.9.2",
"frequenz-client-base[grpclib,grpcio]",
"frequenz-client-base",
]
dev-mypy = [
"mypy == 1.10.1",
Expand All @@ -81,7 +80,7 @@ dev-pytest = [
"pytest-asyncio == 0.23.7",
"async-solipsism == 0.6",
"hypothesis == 6.104.2",
"frequenz-client-base[grpclib,grpcio]",
"frequenz-client-base",
]
dev = [
"frequenz-client-base[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
Expand Down
138 changes: 0 additions & 138 deletions src/frequenz/client/base/_grpchacks.py

This file was deleted.

26 changes: 9 additions & 17 deletions src/frequenz/client/base/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

"""Handling of gRPC channels."""

from typing import Any, AsyncContextManager, TypeVar, cast
from urllib.parse import parse_qs, urlparse

from . import _grpchacks
from grpc import ssl_channel_credentials
from grpc.aio import Channel, insecure_channel, secure_channel


def _to_bool(value: str) -> bool:
Expand All @@ -18,19 +18,14 @@ def _to_bool(value: str) -> bool:
raise ValueError(f"Invalid boolean value '{value}'")


ChannelT = TypeVar("ChannelT", bound=AsyncContextManager[Any])
"""A `grpclib` or `grpcio` channel type."""


def parse_grpc_uri(
uri: str,
channel_type: type[ChannelT],
/,
*,
default_port: int = 9090,
default_ssl: bool = True,
) -> ChannelT:
"""Create a grpclib client channel from a URI.
) -> Channel:
"""Create a client channel from a URI.

The URI must have the following format:

Expand All @@ -50,12 +45,11 @@ def parse_grpc_uri(

Args:
uri: The gRPC URI specifying the connection parameters.
channel_type: The type of channel to create.
default_port: The default port number to use if the URI does not specify one.
default_ssl: The default SSL setting to use if the URI does not specify one.

Returns:
A grpclib client channel object.
A client channel object.

Raises:
ValueError: If the URI is invalid or contains unexpected components.
Expand Down Expand Up @@ -85,9 +79,7 @@ def parse_grpc_uri(

host = parsed_uri.hostname
port = parsed_uri.port or default_port
match channel_type:
case _grpchacks.GrpcioChannel:
return cast(ChannelT, _grpchacks.grpcio_create_channel(host, port, ssl))
case _grpchacks.GrpclibChannel:
return cast(ChannelT, _grpchacks.grpclib_create_channel(host, port, ssl))
assert False, "Unexpected channel type: {channel_type}"
target = f"{host}:{port}"
if ssl:
return secure_channel(target, ssl_channel_credentials())
return insecure_channel(target)
Loading
Loading