Skip to content

Commit 6aff099

Browse files
committed
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 <[email protected]>
1 parent 1b3c39c commit 6aff099

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/frequenz/repo/config/setuptools/grpc_tools.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import pathlib as _pathlib
1414
import subprocess as _subprocess
1515
import sys as _sys
16-
from typing import cast
16+
from collections.abc import Iterable
17+
from typing import assert_never, cast
1718

1819
import setuptools as _setuptools
1920
import setuptools.command.build as _build_command
@@ -30,8 +31,8 @@ class CompileProto(_setuptools.Command):
3031
proto_glob: str
3132
"""The glob pattern to use to find the protobuf files."""
3233

33-
include_paths: str
34-
"""Comma-separated list of paths to include when compiling the protobuf files."""
34+
include_paths: str | Iterable[str]
35+
"""Iterable or comma-separated list of paths to include when compiling the protobuf files."""
3536

3637
py_path: str
3738
"""The path of the root directory where the Python files will be generated."""
@@ -72,15 +73,23 @@ def initialize_options(self) -> None:
7273

7374
self.proto_path = config.proto_path
7475
self.proto_glob = config.proto_glob
75-
self.include_paths = ",".join(config.include_paths)
76+
self.include_paths = config.include_paths
7677
self.py_path = config.py_path
7778

7879
def finalize_options(self) -> None:
7980
"""Finalize options."""
8081

8182
def run(self) -> None:
8283
"""Compile the Python protobuf files."""
83-
include_paths = self.include_paths.split(",")
84+
include_paths: Iterable[str]
85+
match self.include_paths:
86+
case str() as str_paths:
87+
include_paths = str_paths.split(",")
88+
case Iterable() as paths_it:
89+
include_paths = paths_it
90+
case unexpected:
91+
assert_never(unexpected)
92+
8493
proto_files = [
8594
str(p) for p in _pathlib.Path(self.proto_path).rglob(self.proto_glob)
8695
]

0 commit comments

Comments
 (0)