From 6aff0995d93ff53e36f32804486c3bf83dde2031 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 16 Jun 2025 12:00:34 +0200 Subject: [PATCH 1/3] Do not convert array of paths to a string When loading protobuf include paths from the pyproject.toml file, the paths are received as an array/list. If we convert them to a comma-separated string there is the risk of a path containing commas to be split incorrectly, leading to compilation errors. Using the original array/list of paths instead of a comma-separated string is safer and more flexible. Signed-off-by: Leandro Lucarella --- .../repo/config/setuptools/grpc_tools.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/frequenz/repo/config/setuptools/grpc_tools.py b/src/frequenz/repo/config/setuptools/grpc_tools.py index 9d0559eb..d6917aba 100644 --- a/src/frequenz/repo/config/setuptools/grpc_tools.py +++ b/src/frequenz/repo/config/setuptools/grpc_tools.py @@ -13,7 +13,8 @@ import pathlib as _pathlib import subprocess as _subprocess import sys as _sys -from typing import cast +from collections.abc import Iterable +from typing import assert_never, cast import setuptools as _setuptools import setuptools.command.build as _build_command @@ -30,8 +31,8 @@ class CompileProto(_setuptools.Command): proto_glob: str """The glob pattern to use to find the protobuf files.""" - include_paths: str - """Comma-separated list of paths to include when compiling the protobuf files.""" + include_paths: str | Iterable[str] + """Iterable or comma-separated list of paths to include when compiling the protobuf files.""" py_path: str """The path of the root directory where the Python files will be generated.""" @@ -72,7 +73,7 @@ def initialize_options(self) -> None: self.proto_path = config.proto_path self.proto_glob = config.proto_glob - self.include_paths = ",".join(config.include_paths) + self.include_paths = config.include_paths self.py_path = config.py_path def finalize_options(self) -> None: @@ -80,7 +81,15 @@ def finalize_options(self) -> None: def run(self) -> None: """Compile the Python protobuf files.""" - include_paths = self.include_paths.split(",") + include_paths: Iterable[str] + match self.include_paths: + case str() as str_paths: + include_paths = str_paths.split(",") + case Iterable() as paths_it: + include_paths = paths_it + case unexpected: + assert_never(unexpected) + proto_files = [ str(p) for p in _pathlib.Path(self.proto_path).rglob(self.proto_glob) ] From ef1733a5d7ae986c97e4879dfa94725edda573b7 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 16 Jun 2025 12:09:55 +0200 Subject: [PATCH 2/3] Clean comma-separated include paths in grpc_tools When include paths are passed via the commnad-line, they are passed as a comma-separated string. This means the user could add extra spaces or pass a double-comma, which would result in empty strings in the include paths list, making the protobuf compiler fail. This commit cleans the include paths by stripping whitespace and ignoring empty strings. Signed-off-by: Leandro Lucarella --- src/frequenz/repo/config/setuptools/grpc_tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/frequenz/repo/config/setuptools/grpc_tools.py b/src/frequenz/repo/config/setuptools/grpc_tools.py index d6917aba..d0da3362 100644 --- a/src/frequenz/repo/config/setuptools/grpc_tools.py +++ b/src/frequenz/repo/config/setuptools/grpc_tools.py @@ -84,7 +84,9 @@ def run(self) -> None: include_paths: Iterable[str] match self.include_paths: case str() as str_paths: - include_paths = str_paths.split(",") + # If it comes as a comma-separated string, split it into a list, + # stripping whitespace and ignoring empty strings. + include_paths = filter(len, map(str.strip, str_paths.split(","))) case Iterable() as paths_it: include_paths = paths_it case unexpected: From 735bd98de18e26da87b239fd62e24a41c843daf4 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 16 Jun 2025 12:14:39 +0200 Subject: [PATCH 3/3] Add release notes Signed-off-by: Leandro Lucarella --- RELEASE_NOTES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index dda1c7e6..faeb7913 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -31,6 +31,10 @@ But you might still need to adapt your code: ## Bug Fixes - Fixed some typos in the docs. +- `setuptools.grpc_tools`: Fix wrong passing of include paths when passed via: + + * Command-line: Now extra white-spaces and empty strings are removed, before they were passed to `protoc -I`. + * `pyproject.toml`: Now an empty array/list can be passed to override the default paths, before this resulted in an empty string being passed to `protoc -I`. ### Cookiecutter template