Commit 295a05f7 authored by Eric Cousineau's avatar Eric Cousineau Committed by Joe Snyder
Browse files

Move all autopybind11 code into a package for clear boundaries

- Use `env <path> python -m autopybind11` to execute generator
parent e7fba6f1
/autopybind11.egg-info/
/venv/
......@@ -23,7 +23,7 @@ python3:
- apt-get update -qy
- apt-get install -y python3-dev git python3-pip cmake build-essential curl
- curl https://data.kitware.com/api/v1/file/5877a2498d777f05f44b13fb/download -o castxml.tar.gz && tar -xzf castxml.tar.gz
- python3 -m pip install -r requirements.txt
- python3 -m pip install -e .
windows:
......@@ -56,4 +56,4 @@ windows:
- Set-Item -Force -Path "env:PATH" -Value "C:\Python37;$pwdpath\.gitlab;$pwdpath\.gitlab\cmake\bin;$pwdpath\castxml\bin;$env:PATH"
- python -m venv venv
- . venv/Scripts/activate
- python -m pip install -r requirements.txt
\ No newline at end of file
- python -m pip install -e .
......@@ -4,11 +4,10 @@
# FIND_PACKAGE(AutoPyBind11 REQUIRED
#
# This file will define the following variables
# - AutoPyBind11_generator : Path to the generator.py file for wrapping
# - CastXML_EXECUTABLE : Path to the CastXML executable
#
include(FetchContent)
set(AutoPyBind11_INSTALL "${AutoPyBind11_DIR}")
set(AutoPyBind11_generator "${AutoPyBind11_DIR}/autopybind11.py")
include("${AutoPyBind11_DIR}/PyBindHelper.cmake")
include(FetchContent)
set(AutoPyBind11_INSTALL "${AutoPyBind11_DIR}")
include("${AutoPyBind11_DIR}/PyBindHelper.cmake")
......@@ -11,4 +11,6 @@ configure_file(CTestCustom.cmake.in
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR})
find_package(AutoPyBind11)
add_subdirectory(example)
add_test(NAME WG_Linter COMMAND pycodestyle ${CMAKE_SOURCE_DIR}/autopybind11.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME lint_lib COMMAND pycodestyle ${CMAKE_SOURCE_DIR}/autopybind11/ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
# TODO(someone else?): Fix linting for examples / tests.
# add_test(NAME lint_example COMMAND pycodestyle ${CMAKE_SOURCE_DIR}/example/ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
......@@ -18,6 +18,8 @@ macro(autopybind11_fetch_build_pybind11)
message(FATAL_ERROR
"Required program castxml not found set CastXML_EXECUTABLE")
endif()
set(AutoPyBind11_generator ${PYTHON_EXECUTABLE} -m autopybind11)
endmacro()
function(_autopybind11_get_compiler_flags)
......@@ -46,7 +48,7 @@ function(_autopybind11_get_sources)
set(PreProcessOneValueArgs YAML_INPUT DESTINATION GENERATED_SOURCES)
set(PYBIND_RUN_NAME ${ARGV0})
cmake_parse_arguments(PARSE_ARGV 1 PYBIND_RUN "" "${PreProcessOneValueArgs}" "")
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${AutoPyBind11_generator} "-y" ${PYBIND_RUN_YAML_INPUT}
execute_process(COMMAND ${AutoPyBind11_generator} "-y" ${PYBIND_RUN_YAML_INPUT}
"-o" ${PYBIND_RUN_DESTINATION}
"--module_name" "${PYBIND_RUN_NAME}"
-n
......@@ -55,6 +57,9 @@ function(_autopybind11_get_sources)
endfunction()
function(autopybind11_add_module)
if(NOT DEFINED AutoPyBind11_generator)
message(FATAL_ERROR "autopybind11_fetch_build_pybind11 must be called first")
endif()
set(generateOneValueArgs YAML_INPUT CONFIG_INPUT DESTINATION NAMESPACE C_STD_FLAG)
set(generateMultiValueArgs LINK_LIBRARIES FILES)
set(PYBIND_ADD_LIB_NAME ${ARGV0})
......@@ -93,7 +98,7 @@ function(autopybind11_add_module)
CONTENT "includes: ${includes}\nc_std: ${PYBIND_ADD_LIB_C_STD_FLAG}\ndefines: ${defines}")
if(PYBIND_ADD_LIB_CONFIG_INPUT AND EXISTS ${PYBIND_ADD_LIB_CONFIG_INPUT})
add_custom_command(OUTPUT ${PYBIND_ADD_LIB_FILES} wrapper.cpp COMMAND ${PYTHON_EXECUTABLE} ${AutoPyBind11_generator}
add_custom_command(OUTPUT ${PYBIND_ADD_LIB_FILES} wrapper.cpp COMMAND ${AutoPyBind11_generator}
-y ${PYBIND_ADD_LIB_YAML_INPUT}
"--module_name" ${PYBIND_ADD_LIB_NAME}
"-g" ${CastXML_EXECUTABLE}
......@@ -108,7 +113,7 @@ function(autopybind11_add_module)
else()
add_custom_command(OUTPUT ${PYBIND_ADD_LIB_FILES} wrapper.cpp
COMMAND ${PYTHON_EXECUTABLE} ${AutoPyBind11_generator} -y ${PYBIND_ADD_LIB_YAML_INPUT}
COMMAND ${AutoPyBind11_generator} -y ${PYBIND_ADD_LIB_YAML_INPUT}
"--module_name" ${PYBIND_ADD_LIB_NAME}
"-g" ${CastXML_EXECUTABLE}
"-o" ${PYBIND_ADD_LIB_DESTINATION}
......
......@@ -43,13 +43,14 @@ If it is not available, a selection of binary distributions can be found on the
Python Libraries
################
The repository contains a requirements.txt file which can be provided to the
The repository contains a ``setup.py`` file which can be provided to the
PIP program to install all required Python Libraries. Execute::
pip install -r requirements.txt
pip install -e .
to install the other required programs. (It is recommend to use this through a
virtual enviroment!)
to install the this library and other required programs.
It is **strongly** recommended to use this through a virtual enviroment - see
below.
Running Tests
#############
......@@ -62,7 +63,7 @@ running the tests:
# In project root
python3 -m virtualenv -p python3 ./venv/
source ./venv/bin/activate
pip install -r requirements.txt
pip install -e .
mkdir build && cd build
cmake ..
make -j
......@@ -246,11 +247,11 @@ can be installed via the ``pip`` program.
The program should be run at the top level so that the ``setup.cfg`` in the
repository is available. An example run is as follows::
$ pycodestyle autopybind11.py
$ pycodestyle autopybind11/
or setup a CMake build system and execute the ``WG_Linter`` test::
or setup a CMake build system and execute the ``lint_lib`` test::
$ ctest -R WG_Linter -VV
$ ctest -R lint_lib -VV
Alternatives Comparison
-----------------------
......
# Empty Python module.
......@@ -13,9 +13,9 @@ import pygccxml
import pygccxml.declarations as dec
import yaml
from bindings_sorter import get_binding_order
from op_names import names_dict, arg_dependent_ops
import text_blocks as tb
from autopybind11.bindings_sorter import get_binding_order
from autopybind11.op_names import names_dict, arg_dependent_ops
import autopybind11.text_blocks as tb
class BindingsGenerator:
......
......@@ -48,6 +48,7 @@
from toposort import toposort_flatten
# TODO: Could make a dictionary of class name to binding file.
# Then could loop through the keys, search for them in pygccxml data,
# and use the value to topological sort
......
......@@ -5,12 +5,13 @@ import sys
import unittest
# Make it so we search where we are running.
sys.path.append(os.getcwd())
sys.path.append(os.getcwd()) # noqa
import additional
# Import of test_base_double_py from additional causes conflict on run
# from additional.additional import nonTemplate_py
class additionalTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
......@@ -38,4 +39,3 @@ class additionalTests(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
......@@ -4,7 +4,7 @@ import os
import sys
import unittest
sys.path.append(os.getcwd())
sys.path.append(os.getcwd()) # noqa
# TODO: this will need to be changed when modules follow the
# namespace hierarchy
......@@ -15,6 +15,7 @@ import multi_namespaced_module as mnm
# Import of test_base_double_py from additional causes conflict on run
# from additional.additional import nonTemplate_py
class multiNamespacedModuleTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
......@@ -93,6 +94,6 @@ class multiNamespacedModuleTests(unittest.TestCase):
self.assertEqual(int_float_class_inst.var1, 7)
self.assertAlmostEqual(int_float_class_inst.var2, 2 * self.pi + 4, self.prec)
if __name__ == '__main__':
unittest.main()
......@@ -6,12 +6,13 @@ import sys
import unittest
# Make it so we search where we are running.
sys.path.append(os.getcwd())
sys.path.append(os.getcwd()) # noqa
import multi_target as mt
# Import of test_base_double_py from additional causes conflict on run
# from additional.additional import nonTemplate_py
class multiTargetTests(unittest.TestCase):
def test_flags(self):
mt.first_target_class_py().flag1_defined()
......
......@@ -37,10 +37,11 @@
import os
import sys
import unittest
sys.path.append(os.getcwd())
sys.path.append(os.getcwd()) # noqa
from vector2_module import Vector2_py
class OperatorTestSuite(unittest.TestCase):
def test_basic_operators(self):
v1 = Vector2_py(1, 2)
......
......@@ -6,12 +6,13 @@ import sys
import unittest
# Make it so we search where we are running.
sys.path.append(os.getcwd())
sys.path.append(os.getcwd()) # noqa
import example
# Import of test_base_double_py from additional causes conflict on run
# from additional.additional import nonTemplate_py
class exampleTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
......@@ -109,6 +110,6 @@ class exampleTests(unittest.TestCase):
# an ImportError will be raised.
from additional import additional
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
"""
Using Python to automatically wrap C++ code into Python via PyBind11
"""
from setuptools import setup
setup(
name="autopybind11",
version="0.1A",
author="Kitware Inc.",
author_email="kitware@kitware.com",
long_description=__doc__,
long_description_content_type="text/rst",
license="BSD 3 Clause",
packages=["autopybind11"],
py_modules=["autopybind11"],
url="https://gitlab.kitware.com/autopybind11/autopybind11",
install_requires=[
"ConfigArgParse",
"PyYAML >= 5.1",
"pygccxml",
"toposort",
]
)
#ifndef TMP_WRAPPING_HEADER
#define TMP_WRAPPING_HEADER
#include "test.hpp"
#include "test.hpp"
#include "test_2.hpp"
template class test_base<double>;
template class test<double>;
namespace _wrapping_
{
const char* const group = "drake_wrap";
namespace wrappers
{
typedef test_base<double> test_basedouble;
typedef test<double> testdouble;
auto template_f_double = &template_f<double>;
auto template_f_multi_arg_double = &template_f_multi_arg<double>;
auto template_f_multi_arg_float = &template_f_multi_arg<float>;
auto multi_template_double_float = &multi_template<double, float>;
}
void force_instantiate()
{
using namespace _wrapping_::wrappers;
}
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment