-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend nb stubs to all arts submodules (#866)
Adds completion support for all nb submodules inside the arts module. .pyi files are now written to an `arts` subfolder. Getting access to the new completions requires deleting either the whole build directory or removing `build/python/src/pyarts/arts.pyi` manually.
- Loading branch information
Showing
4 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function (ARTS_ADD_CPP_STUBS) | ||
|
||
foreach (MODULENAME IN LISTS ARGN) | ||
nanobind_add_stub( | ||
pyarts_${MODULENAME}_cpp_stub | ||
MODULE arts.${MODULENAME} | ||
OUTPUT ${ARTS_BINARY_DIR}/python/src/pyarts/arts/${MODULENAME}.pyi | ||
PYTHON_PATH ${ARTS_BINARY_DIR}/python/src/pyarts | ||
DEPENDS pyarts_cpp | ||
) | ||
list(APPEND deplist "pyarts_${MODULENAME}_cpp_stub") | ||
endforeach() | ||
|
||
nanobind_add_stub( | ||
pyarts_cpp_stub | ||
MODULE arts | ||
OUTPUT ${ARTS_BINARY_DIR}/python/src/pyarts/arts/__init__.pyi | ||
PYTHON_PATH ${ARTS_BINARY_DIR}/python/src/pyarts | ||
DEPENDS pyarts_cpp "${deplist}" | ||
) | ||
set_property( | ||
TARGET pyarts_cpp_stub | ||
APPEND | ||
PROPERTY ADDITIONAL_CLEAN_FILES ${ARTS_BINARY_DIR}/python/src/pyarts/arts | ||
) | ||
|
||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
dependencies: | ||
- boost | ||
- ccache | ||
- clang | ||
- clangxx | ||
- clang>=19 | ||
- clangxx>=19 | ||
- cmake | ||
- docutils | ||
- doxygen | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from inspect import getmembers, ismodule | ||
from pathlib import Path | ||
|
||
import pyarts | ||
from pyarts import arts | ||
|
||
|
||
class TestStubFiles: | ||
def walk_modules(self, m): | ||
submodules = getmembers(m, ismodule) | ||
for submodule in submodules: | ||
if submodule[1].__name__.startswith("pyarts.arts."): | ||
yield submodule[1].__name__ | ||
yield from self.walk_modules(submodule[1]) | ||
|
||
def test_pyi(self): | ||
missing_stubs = [] | ||
for module in self.walk_modules(arts): | ||
if ( | ||
not Path(pyarts.__path__[0]) | ||
.joinpath(module.replace("pyarts.", "").replace(".", "/") + ".pyi") | ||
.is_file() | ||
): | ||
missing_stubs.append(module.replace("pyarts.arts.", "")) | ||
|
||
assert len(missing_stubs) == 0, ( | ||
f"Missing stub file(s) for arts submodule(s): \n" | ||
f" {"\n ".join(missing_stubs)}\n" | ||
f"Add them to the `arts_add_cpp_stubs` call in " | ||
f"src/python_interface/CMakeLists.txt" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
a = TestStubFiles() | ||
a.test_pyi() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters