Skip to content

Commit 4e91284

Browse files
authored
Remove support for grpclib (#71)
The grpclib project is in maintainance mode, as it was only created as an alternative to grpcio when it didn't support async. The author has no intention to keep developping it, so it is a bit risky to depend on it. Fixes #69.
2 parents 3fd2eed + 72420b8 commit 4e91284

File tree

12 files changed

+188
-536
lines changed

12 files changed

+188
-536
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
## Upgrading
88

9+
- `grpclib` was removed, if you used `grpclib` you should switch to `grpcio` instead.
10+
11+
You should also update your dependency to `frequenz-client-base` (without any `[grpclib]` or `[grpcio]` suffix).
12+
913
- The `parse_grpc_uri` function (and `BaseApiClient` constructor) now enables SSL by default (`ssl=false` should be passed to disable it).
14+
1015
- 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.
1116

1217
## New Features

mkdocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ plugins:
118118
- https://frequenz-floss.github.io/frequenz-channels-python/v1.0-pre/objects.inv
119119
- https://googleapis.dev/python/protobuf/latest/objects.inv
120120
- https://grpc.github.io/grpc/python/objects.inv
121-
- https://grpclib.readthedocs.io/en/latest/objects.inv
122121
- https://typing-extensions.readthedocs.io/en/stable/objects.inv
123122
# Note this plugin must be loaded after mkdocstrings to be able to use macros
124123
# inside docstrings. See the comment in `docs/_scripts/macros.py` for more

pyproject.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ classifiers = [
2727
requires-python = ">= 3.11, < 4"
2828
dependencies = [
2929
"frequenz-channels >= v1.0.0-rc1, < 2",
30+
"grpcio >= 1.54.2, < 2",
3031
"protobuf >= 4.21.6, < 6",
3132
"typing-extensions >= 4.5.0, < 5",
3233
]
@@ -37,15 +38,13 @@ name = "Frequenz Energy-as-a-Service GmbH"
3738
3839

3940
[project.optional-dependencies]
40-
grpcio = ["grpcio >= 1.54.2, < 2"]
41-
grpclib = ["grpclib >= 0.4.0, < 0.5"]
4241
dev-flake8 = [
4342
"flake8 == 7.1.0",
4443
"flake8-docstrings == 1.7.0",
45-
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
44+
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
4645
"pydoclint == 0.5.3",
4746
"pydocstyle == 6.3.0",
48-
"frequenz-client-base[grpclib,grpcio]",
47+
"frequenz-client-base",
4948
]
5049
dev-formatting = ["black == 24.4.2", "isort == 5.13.2"]
5150
dev-mkdocs = [
@@ -58,7 +57,7 @@ dev-mkdocs = [
5857
"mkdocs-material == 9.5.27",
5958
"mkdocstrings[python] == 0.25.1",
6059
"frequenz-repo-config[lib] == 0.9.2",
61-
"frequenz-client-base[grpclib,grpcio]",
60+
"frequenz-client-base",
6261
]
6362
dev-mypy = [
6463
"mypy == 1.10.1",
@@ -81,7 +80,7 @@ dev-pytest = [
8180
"pytest-asyncio == 0.23.7",
8281
"async-solipsism == 0.6",
8382
"hypothesis == 6.104.2",
84-
"frequenz-client-base[grpclib,grpcio]",
83+
"frequenz-client-base",
8584
]
8685
dev = [
8786
"frequenz-client-base[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",

src/frequenz/client/base/_grpchacks.py

Lines changed: 0 additions & 138 deletions
This file was deleted.

src/frequenz/client/base/channel.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
"""Handling of gRPC channels."""
55

6-
from typing import Any, AsyncContextManager, TypeVar, cast
76
from urllib.parse import parse_qs, urlparse
87

9-
from . import _grpchacks
8+
from grpc import ssl_channel_credentials
9+
from grpc.aio import Channel, insecure_channel, secure_channel
1010

1111

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

2020

21-
ChannelT = TypeVar("ChannelT", bound=AsyncContextManager[Any])
22-
"""A `grpclib` or `grpcio` channel type."""
23-
24-
2521
def parse_grpc_uri(
2622
uri: str,
27-
channel_type: type[ChannelT],
2823
/,
2924
*,
3025
default_port: int = 9090,
3126
default_ssl: bool = True,
32-
) -> ChannelT:
33-
"""Create a grpclib client channel from a URI.
27+
) -> Channel:
28+
"""Create a client channel from a URI.
3429
3530
The URI must have the following format:
3631
@@ -50,12 +45,11 @@ def parse_grpc_uri(
5045
5146
Args:
5247
uri: The gRPC URI specifying the connection parameters.
53-
channel_type: The type of channel to create.
5448
default_port: The default port number to use if the URI does not specify one.
5549
default_ssl: The default SSL setting to use if the URI does not specify one.
5650
5751
Returns:
58-
A grpclib client channel object.
52+
A client channel object.
5953
6054
Raises:
6155
ValueError: If the URI is invalid or contains unexpected components.
@@ -85,9 +79,7 @@ def parse_grpc_uri(
8579

8680
host = parsed_uri.hostname
8781
port = parsed_uri.port or default_port
88-
match channel_type:
89-
case _grpchacks.GrpcioChannel:
90-
return cast(ChannelT, _grpchacks.grpcio_create_channel(host, port, ssl))
91-
case _grpchacks.GrpclibChannel:
92-
return cast(ChannelT, _grpchacks.grpclib_create_channel(host, port, ssl))
93-
assert False, "Unexpected channel type: {channel_type}"
82+
target = f"{host}:{port}"
83+
if ssl:
84+
return secure_channel(target, ssl_channel_credentials())
85+
return insecure_channel(target)

0 commit comments

Comments
 (0)