Skip to content

Commit

Permalink
added nanobind.__main__; minor cmake interface simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Apr 5, 2023
1 parent 40f4fff commit d5ccc88
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/building.rst
Expand Up @@ -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)
Expand Down
30 changes: 22 additions & 8 deletions setup.py
Expand Up @@ -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

Expand All @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions 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()

0 comments on commit d5ccc88

Please sign in to comment.