|
15 | 15 | import pkgutil
|
16 | 16 | import sys
|
17 | 17 | from pathlib import Path
|
18 |
| -from typing import Any, Dict, List, NamedTuple, Set, Union |
| 18 | +from typing import Any, Dict, List, NamedTuple, Optional, Set, Union |
19 | 19 |
|
20 | 20 | _ARGUMENT_SELF = {"kind": "POSITIONAL_OR_KEYWORD", "name": "self"}
|
21 | 21 |
|
22 | 22 |
|
23 | 23 | class InterfaceScanner:
|
24 |
| - def __init__(self) -> None: |
| 24 | + def __init__(self, skipped_modules: Optional[List[str]] = None) -> None: |
25 | 25 | self.signatures: Dict[str, Union[inspect.Signature]] = {}
|
26 | 26 | self.variables: Set[str] = set()
|
| 27 | + self.skipped_modules: Set[str] = set(skipped_modules or []) |
27 | 28 |
|
28 | 29 | def scan_interfaces_recursively(self, module_name: str) -> None:
|
| 30 | + if module_name in self.skipped_modules: |
| 31 | + return |
29 | 32 | self._scan_interfaces_in_module(module_name)
|
30 | 33 | for submodule in pkgutil.iter_modules([module_name.replace(".", os.path.sep)]):
|
31 | 34 | submodule_name = module_name + "." + submodule.name
|
@@ -212,13 +215,20 @@ def main() -> None:
|
212 | 215 | subparsers = parser.add_subparsers(dest="command")
|
213 | 216 | extract = subparsers.add_parser("extract", help="Extract public interfaces")
|
214 | 217 | extract.add_argument("--module", help="The module to extract public interfaces", type=str, default="samtranslator")
|
| 218 | + extract.add_argument( |
| 219 | + "--skipped-module", |
| 220 | + help="The modules that should be skipped", |
| 221 | + type=str, |
| 222 | + nargs="*", |
| 223 | + default=["samtranslator.internal"], |
| 224 | + ) |
215 | 225 | check = subparsers.add_parser("check", help="Check public interface changes")
|
216 | 226 | check.add_argument("original_json", help="The original public interface JSON file", type=Path)
|
217 | 227 | check.add_argument("new_json", help="The new public interface JSON file", type=Path)
|
218 | 228 | args = parser.parse_args()
|
219 | 229 |
|
220 | 230 | if args.command == "extract":
|
221 |
| - scanner = InterfaceScanner() |
| 231 | + scanner = InterfaceScanner(skipped_modules=args.skipped_module) |
222 | 232 | scanner.scan_interfaces_recursively(args.module)
|
223 | 233 | _print(scanner.signatures, scanner.variables)
|
224 | 234 | elif args.command == "check":
|
|
0 commit comments