From 21ca9f4fd67593433e633e4057d3545f051ed381 Mon Sep 17 00:00:00 2001 From: Roberto Rossini <71787608+robomics@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:58:35 +0200 Subject: [PATCH] Fix stubgen --- src/CMakeLists.txt | 2 -- utils/devel/stubgen.py | 9 +++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 395725e..6e50623 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,7 +58,6 @@ target_compile_definitions(_hictkpy PRIVATE $<$:SPDLOG_ACTI install(TARGETS _hictkpy LIBRARY DESTINATION hictkpy) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/hictkpy") -file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/hictkpy/__init__.pyi") # This properly escapes Windows paths string(REPLACE "\\" "/" HICTKPY_PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}) @@ -75,7 +74,6 @@ install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/NanobindStubgen.cmake") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hictkpy/py.typed" DESTINATION hictkpy) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hictkpy/__init__.pyi" DESTINATION hictkpy) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hictkpy/hictkpy.pyi" DESTINATION hictkpy) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hictkpy/cooler.pyi" DESTINATION hictkpy) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hictkpy/hic.pyi" DESTINATION hictkpy) diff --git a/utils/devel/stubgen.py b/utils/devel/stubgen.py index 7390844..a3d93a4 100755 --- a/utils/devel/stubgen.py +++ b/utils/devel/stubgen.py @@ -23,11 +23,13 @@ def make_cli() -> argparse.ArgumentParser: def process_module(mod_name: str, out_file: str, force: bool): print(f'Processing module "{mod_name}"...', file=sys.stderr) - sg = StubGen(importlib.import_module(mod_name)) - if not force and os.path.exists(out_file): raise RuntimeError(f'Refusing to overwrite file "{out_file}". Pass --force to overwrite.') + mod = importlib.import_module(mod_name) + sg = StubGen(mod) + sg.put(mod) + print(f'Writing stub to file "{out_file}"...', file=sys.stderr) with open(out_file, "w") as f: print(sg.get(), file=f) @@ -52,10 +54,9 @@ def main(): pyarrow = importlib.import_module("pyarrow") pyarrow.create_library_symlinks() - touch_file(os.path.join(args["output-dir"], "__init__.pyi"), args["force"]) touch_file(os.path.join(args["output-dir"], "py.typed"), args["force"]) - process_module("hictkpy._hictkpy", os.path.join(args["output-dir"], "hictkpy.pyi"), args["force"]) + process_module("hictkpy._hictkpy", os.path.join(args["output-dir"], "__init__.pyi"), args["force"]) process_module("hictkpy._hictkpy.cooler", os.path.join(args["output-dir"], "cooler.pyi"), args["force"]) process_module("hictkpy._hictkpy.hic", os.path.join(args["output-dir"], "hic.pyi"), args["force"])