Coverage for packages/pyswig/src/pyswig/cli.py: 92%
25 statements
« prev ^ index » next coverage.py v7.14.3, created at 2026-06-26 21:05 +0000
« prev ^ index » next coverage.py v7.14.3, created at 2026-06-26 21:05 +0000
1# Copyright (c) 2015-2020 Michel Gillet
2# SPDX-License-Identifier: MIT
4"""Console entry point for PySwig."""
6from __future__ import annotations
8import sys
10from pyswig.cli_args import apply_to_engine, build_parser
11from pyswig.exceptions import PySwigError
12from pyswig.pyswig import PySwig
15def main(argv: list[str] | None = None) -> int:
16 """Run PySwig generation from the command line."""
17 if argv is None:
18 argv = sys.argv[1:]
19 if argv[:1] == ["--cmakedir"]:
20 from pyswig import cmake_prefix_path
22 print(cmake_prefix_path())
23 return 0
25 args = build_parser().parse_args(argv)
26 try:
27 engine = PySwig(parse_cli=False)
28 apply_to_engine(engine, args)
29 engine.generate()
30 if args.run_swig:
31 return engine.run_swig()
32 except PySwigError as exc:
33 print(f"ERROR: {exc}", file=sys.stderr)
34 return 1
35 return 0
38if __name__ == "__main__":
39 raise SystemExit(main())