Skip to content

Commit f93e20f

Browse files
authored
setuptools: Fix passing empty include paths (#418)
2 parents 1b3c39c + 735bd98 commit f93e20f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ But you might still need to adapt your code:
3131
## Bug Fixes
3232

3333
- Fixed some typos in the docs.
34+
- `setuptools.grpc_tools`: Fix wrong passing of include paths when passed via:
35+
36+
* Command-line: Now extra white-spaces and empty strings are removed, before they were passed to `protoc -I`.
37+
* `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`.
3438

3539
### Cookiecutter template
3640

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

Lines changed: 16 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,25 @@ 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+
# If it comes as a comma-separated string, split it into a list,
88+
# stripping whitespace and ignoring empty strings.
89+
include_paths = filter(len, map(str.strip, str_paths.split(",")))
90+
case Iterable() as paths_it:
91+
include_paths = paths_it
92+
case unexpected:
93+
assert_never(unexpected)
94+
8495
proto_files = [
8596
str(p) for p in _pathlib.Path(self.proto_path).rglob(self.proto_glob)
8697
]

0 commit comments

Comments
 (0)