13
13
import pathlib as _pathlib
14
14
import subprocess as _subprocess
15
15
import sys as _sys
16
- from typing import cast
16
+ from collections .abc import Iterable
17
+ from typing import assert_never , cast
17
18
18
19
import setuptools as _setuptools
19
20
import setuptools .command .build as _build_command
@@ -30,8 +31,8 @@ class CompileProto(_setuptools.Command):
30
31
proto_glob : str
31
32
"""The glob pattern to use to find the protobuf files."""
32
33
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."""
35
36
36
37
py_path : str
37
38
"""The path of the root directory where the Python files will be generated."""
@@ -72,15 +73,25 @@ def initialize_options(self) -> None:
72
73
73
74
self .proto_path = config .proto_path
74
75
self .proto_glob = config .proto_glob
75
- self .include_paths = "," . join ( config .include_paths )
76
+ self .include_paths = config .include_paths
76
77
self .py_path = config .py_path
77
78
78
79
def finalize_options (self ) -> None :
79
80
"""Finalize options."""
80
81
81
82
def run (self ) -> None :
82
83
"""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
+
84
95
proto_files = [
85
96
str (p ) for p in _pathlib .Path (self .proto_path ).rglob (self .proto_glob )
86
97
]
0 commit comments