From d5ccc8844b29ca6cd5188ffd8d16e034bcee9f73 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 5 Apr 2023 09:34:03 +0200 Subject: [PATCH] added nanobind.__main__; minor cmake interface simplifications --- README.md | 2 +- docs/building.rst | 2 +- setup.py | 30 ++++++++++++++++++++++-------- src/__main__.py | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 src/__main__.py diff --git a/README.md b/README.md index 1ef782b5..ef000aa2 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ _nanobind_ is a small binding library that exposes C++ types in Python and vice versa. It is reminiscent of [Boost.Python](https://www.boost.org/doc/libs/1_64_0/libs/python/doc/html) and [pybind11](https://github.com/pybind/pybind11) and uses near-identical syntax. -In contrast to these existing tools, nanobind is _more efficient_: bindings +In contrast to these existing tools, nanobind is more efficient: bindings compile in a shorter amount of time, produce smaller binaries, and have better runtime performance. diff --git a/docs/building.rst b/docs/building.rst index b19367a9..b3afdc98 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -53,7 +53,7 @@ step depend on *how you installed* nanobind, in the :ref:`previous section # Detect the installed nanobind package and import it into CMake execute_process( - COMMAND "${Python_EXECUTABLE}" -c "import nanobind; print(nanobind.cmake_dir())" + COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR) list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}") find_package(nanobind CONFIG REQUIRED) diff --git a/setup.py b/setup.py index 3c9a8d72..610fd664 100644 --- a/setup.py +++ b/setup.py @@ -13,14 +13,27 @@ matches = dict(VERSION_REGEX.findall(f.read())) nanobind_version = "{MAJOR}.{MINOR}.{PATCH}".format(**matches) -long_description = '''\ +long_description = ''' +![nanobind logo]( +https://github.com/wjakob/nanobind/raw/master/docs/images/logo.jpg?raw=True) + _nanobind_ is a small binding library that exposes C++ types in Python and vice versa. It is reminiscent of -_[Boost.Python](https://www.boost.org/doc/libs/1_64_0/libs/python/doc/html)_ -and _[pybind11](http://github.com/pybind/pybind11)_ and uses near-identical -syntax. In contrast to these existing tools, _nanobind_ is more _efficient_: +[Boost.Python](https://www.boost.org/doc/libs/1_64_0/libs/python/doc/html) +and [pybind11](http://github.com/pybind/pybind11) and uses near-identical +syntax. In contrast to these existing tools, nanobind is more efficient: bindings compile in a shorter amount of time, produce smaller binaries, and -have better runtime performance.''' +have better runtime performance. + +More concretely, +[benchmarks](https://nanobind.readthedocs.io/en/latest/benchmark.html) show +**~2-3× faster** compile time, **~3× smaller** binaries, and up to **~8× +lower** runtime overheads compared to pybind11. + +Please see the following links for tutorial and reference documentation in +[HTML](https://nanobind.readthedocs.io/en/latest/) and +[PDF](https://nanobind.readthedocs.io/_/downloads/en/latest/pdf/) formats. +''' from tempfile import TemporaryDirectory @@ -33,15 +46,16 @@ os.path.join(temp_dir, name), dirs_exist_ok=True) - shutil.move(os.path.join(temp_dir, 'src', '__init__.py'), - os.path.join(temp_dir, '__init__.py')) + for fname in ['__init__.py', '__main__.py']: + shutil.move(os.path.join(temp_dir, 'src', fname), + os.path.join(temp_dir, fname)) setup( name="nanobind", version=nanobind_version, author="Wenzel Jakob", author_email="wenzel.jakob@epfl.ch", - description='Seamless operability between C++17 and Python', + description='nanobind: tiny and efficient C++/Python bindings', url="https://github.com/wjakob/nanobind", license="BSD", long_description=long_description, diff --git a/src/__main__.py b/src/__main__.py new file mode 100644 index 00000000..f239099b --- /dev/null +++ b/src/__main__.py @@ -0,0 +1,36 @@ +import argparse +import sys +import sysconfig + +from . import __version__, include_dir, cmake_dir + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument( + "--version", + action="version", + version=__version__, + help="Print the version number.", + ) + parser.add_argument( + "--include_dir", + action="store_true", + help="Print the path to the nanobind C++ header directory." + ) + parser.add_argument( + "--cmake_dir", + action="store_true", + help="Print the path to the nanobind CMake module directory." + ) + args = parser.parse_args() + if not sys.argv[1:]: + parser.print_help() + if args.include_dir: + print(include_dir()) + if args.cmake_dir: + print(cmake_dir()) + + +if __name__ == "__main__": + main()