1313import pathlib as _pathlib
1414import subprocess as _subprocess
1515import sys as _sys
16- from typing import cast
16+ from collections .abc import Iterable
17+ from typing import assert_never , cast
1718
1819import setuptools as _setuptools
1920import 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