Skip to content

Commit 7325cd4

Browse files
committed
Fix cli bug
1 parent 3497c44 commit 7325cd4

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

cppygen/__main__.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,42 @@ def run():
2727
cwd = pathlib.Path(args.cwd)
2828

2929
sources = []
30-
if configs["sources"] is None:
30+
if (config_sources := configs.get("sources")) is None:
3131
logger.error("Please Specify the sources field in config file")
3232
exit(1)
33-
for i in configs["sources"]:
33+
for i in config_sources:
3434
sources.extend([j for j in cwd.glob(i)])
3535

3636
headers = []
37-
if configs["headers"] is None:
37+
if (config_headers := configs.get("headers")) is None:
3838
logger.error("Please Specify the headers field in config file")
3939
exit(1)
40-
for i in configs["headers"]:
40+
for i in config_headers:
4141
headers.extend([j for j in cwd.glob(i)])
4242

43-
if configs["output_dir"] is None:
43+
if (config_output_dir := configs.get("output_dir")) is None:
4444
logger.error("Please Specify the output_dir field in config file")
4545
exit(1)
46-
output_dir = cwd.joinpath(configs["output_dir"])
46+
output_dir = cwd.joinpath(config_output_dir)
4747

4848
cppygen = Parser(
49-
namespace=configs["search_namespace"], library_file=configs["libclang_path"]
49+
namespace=configs.get("search_namespace"),
50+
library_file=configs.get("libclang_path"),
5051
)
5152

52-
flags = configs["flags"] or []
53+
flags = configs.get("flags") or []
5354

54-
for i in configs["include_directories"] or []:
55+
for i in configs.get("include_directories") or []:
5556
flags.append(f"-I{str(cwd.joinpath(i).absolute())}")
5657
print(f"-I{str(cwd.joinpath(i).absolute())}")
5758

5859
for i in sources:
59-
cppygen.parse_from_file(i, lang="cpp", flags=configs["flags"])
60+
cppygen.parse_from_file(i, lang="cpp", flags=configs.get("flags") or [])
6061

6162
for i in headers:
62-
cppygen.parse_from_file(i, lang="hpp", flags=configs["flags"])
63+
cppygen.parse_from_file(i, lang="hpp", flags=configs.get("flags") or [])
6364

64-
for i in configs["include_headers"] or []:
65+
for i in configs.get("include_headers") or []:
6566
cppygen.add_hpp_includes(i)
6667

6768
with open(str(output_dir) + "/cppygen_generated.hpp", "w") as f:

example/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ find_package(pybind11 CONFIG)
1515
# Auto Generation
1616
set(cppygen_generated_hpp ${CMAKE_CURRENT_BINARY_DIR}/cppygen_generated.hpp)
1717
set(cppygen_generated_cpp ${CMAKE_CURRENT_BINARY_DIR}/cppygen_generated.cpp)
18+
set(cppygen_config_file ${CMAKE_CURRENT_LIST_DIR}/cppygenconfig.toml)
1819

1920
find_program(_CPPYGEN_GENERATOR cppygen)
21+
message(${cppygen_config_file})
2022

2123
add_custom_command(
2224
OUTPUT ${cppygen_generated_hpp} ${cppygen_generated_cpp}
2325
COMMAND
2426
${_CPPYGEN_GENERATOR} ARGS #
25-
--config_file ${CMAKE_CURRENT_LIST_DIR}/cppygenconfig.toml #
27+
--config_file ${cppygen_config_file}#
2628
--cwd ${CMAKE_CURRENT_LIST_DIR}
27-
DEPENDS ${SHELL_SOURCES}
29+
DEPENDS ${SHELL_SOURCES} ${cppygen_config_file}
2830
COMMENT
2931
"Generating CPPyGen Code To ${cppygen_generated_hpp} and ${cppygen_generated_cpp}"
3032
VERBATIM)

0 commit comments

Comments
 (0)