Skip to content

[GSoC 2020] Extending PCL for use with Python: Bindings generation using Pybind11 #4366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 234 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
234 commits
Select commit Hold shift + click to select a range
7981a1c
[point_types.json] add point_types.json
diivm May 15, 2020
cab3031
[point_types.json] update to a part of hpp implementation
diivm May 17, 2020
c7498c1
[point_types.json] add parent structs and friendly operators
diivm May 18, 2020
ed344c6
[point_types.json] change to parent
diivm May 19, 2020
066a5ce
[generate_binding.py] start generate_binding.py
diivm May 18, 2020
65f3d19
[generate_binding.py] ultra rough
diivm May 19, 2020
40eab68
[generate_binding.py] format and add global
diivm May 19, 2020
afbc1c7
[py_point_types.cpp] add output for point_types
diivm May 19, 2020
4f37afd
[py_point_types.cpp] corrected for namespaces and operators
diivm May 19, 2020
b1e3cc9
[generate_binding.py] rearrange
diivm May 21, 2020
ff4a689
[generate_binding.py] change namespace to braces form
diivm May 22, 2020
37acd51
[generate_binding.py] remove operator handling cause errors
diivm May 22, 2020
1e19e67
[generate_binding.py] fix parameters to just use type
diivm May 22, 2020
b432122
[py_point_types.cpp] after some fixes
diivm May 22, 2020
4a2a548
[point_types.json] fix change parameters to parameters_types
diivm May 22, 2020
0b2dfdf
[point_types.json] fix add meta for parent
diivm May 22, 2020
0994867
[setup.py] add build files. building, but not importing
diivm May 22, 2020
421cf62
[CMakeLists.txt] add build files. building, but not importing
diivm May 22, 2020
3598b20
[CMakeLists.txt] change module name to fix import error. import worki…
diivm May 23, 2020
5bdd5ca
[Dockerfile] minimum working dockerfile
diivm Jun 1, 2020
ff92a9e
[Makefile] init Makefile
diivm Jun 1, 2020
fedded1
[parse.cpp] minimum compiling solution
diivm Jun 2, 2020
29eb197
[discussion.md] add discussion.md
diivm Jun 6, 2020
a4ab71f
[Dockerfile] updates
diivm Jun 8, 2020
6f4bf43
[libclang.py] initial grep example
diivm Jun 8, 2020
f2bdfad
[libclang.py] easy print
diivm Jun 9, 2020
b8c1a6b
refactor folder
diivm Jun 10, 2020
c915cd1
[union_test.cpp] union_test for pybind11
diivm Jun 10, 2020
8c307e9
[python/README.md] init info
diivm Jun 10, 2020
5d7b8cf
[tooling/README.md] init info
diivm Jun 10, 2020
82dd17c
[libclang.py] full match and struct replacement
diivm Jun 10, 2020
8eab1d8
[tooling/README.md] remove sudo
diivm Jun 11, 2020
6b2e569
[libclang.py] working soln, gives info about file's components
diivm Jun 11, 2020
42aaa43
[tooling/README.md] update python run info
diivm Jun 11, 2020
3aedbfe
[libclang.py] add depth
diivm Jun 11, 2020
eeffca5
[libclang.py] add compile commands
diivm Jun 13, 2020
48f729e
[libclang.py] change print
diivm Jun 13, 2020
c95ac4e
[compile_commands.json] add compile_commands.json
diivm Jun 13, 2020
884e733
[libclang.py] change arg type
diivm Jun 13, 2020
9f5df82
[compile_commands.json] remove unnecessary include
diivm Jun 13, 2020
15089b3
[Dockerfile] update
diivm Jun 13, 2020
0dd20ff
[libclang.py] fix compile_db not loading and getting args
diivm Jun 19, 2020
f424ea8
[libclang.py] args not needed, producing invalid o/p with args
diivm Jun 19, 2020
c1ab9a2
[libclang.py] remove unwanted, cleanup
diivm Jun 19, 2020
7f9e0af
[libclang.py] add json output generation
diivm Jun 19, 2020
0c31b37
[compile_commands.json] fixes, but not being used currently
diivm Jun 19, 2020
a6dd4f8
[o/p] initial o/p
diivm Jun 19, 2020
4797bdb
[libclang.py] json output gen betterment
diivm Jun 19, 2020
aaab507
[o/p] refactor
diivm Jun 19, 2020
d9f2243
[libclang.py] we need -std
diivm Jun 20, 2020
10ee1fe
refactor folder
diivm Jun 20, 2020
321edc9
develop in single folder
diivm Jun 20, 2020
fcfc69e
[libclang.py] use compile_commands, after correction
diivm Jun 21, 2020
ff0d19d
[o/p] changed after compile_commands
diivm Jun 21, 2020
35ff1fd
[compile_commands.json] add file
diivm Jun 22, 2020
72b22c5
[libclang.py] remove more_than_one_file
diivm Jun 22, 2020
a5baeb8
[compile_commands.json] remove include
diivm Jun 22, 2020
bab60ba
[o/p] changed after removing include
diivm Jun 22, 2020
42c3648
[libclang.py] add access_specifier, result_type, brief_comment, raw_c…
diivm Jun 22, 2020
4148184
[o/p] add more info
diivm Jun 22, 2020
73d895e
refactor
diivm Jun 22, 2020
9730365
[python/README.md] update
diivm Jun 22, 2020
5e89ada
rename
diivm Jun 28, 2020
fa79863
[parse.py] add type info
diivm Jun 29, 2020
428e074
[parse.py] replace `is not`
diivm Jun 29, 2020
586d127
[o/p] after adding type info
diivm Jun 29, 2020
efbf9f9
Merge pull request #7 from divmadan/devel/add_type_info
diivm Jul 1, 2020
47cd10c
restructure into a module
diivm Jul 4, 2020
84db804
Merge pull request #9 from divmadan/devel/restructure
diivm Jul 4, 2020
377bf23
Add pytest.yml
diivm Jul 18, 2020
0ca9cbc
[utils.py] add utils
diivm Jul 5, 2020
a0bef42
[parse.py] clean and simplify
diivm Jul 5, 2020
67db056
[parse.py] change bool function name
diivm Jul 6, 2020
5e01ee6
[parse.py] consistent naming
diivm Jul 6, 2020
7e6719d
[parse.py] compilation_commands in one function and fixed path
diivm Jul 6, 2020
4acfb38
[parse.py] fixed path
diivm Jul 6, 2020
01ca66a
parse_arguments fix
diivm Jul 6, 2020
ad34e5f
[utils.py] remove unused function
diivm Jul 6, 2020
c212300
[parse.py] remove `None` returns
diivm Jul 6, 2020
db68b45
[parse.py] changes
diivm Jul 6, 2020
098d915
[parse.py] format using default args
diivm Jul 6, 2020
4886e82
[parse.py] remove unnecessary create_index
diivm Jul 6, 2020
59a4920
[parse.py] add docstrings
diivm Jul 7, 2020
ffd8041
[utils.py] add compilation_database_path and json_output_path
diivm Jul 7, 2020
04a5de4
[parse.py] take user input for compilation_database_path and json_out…
diivm Jul 7, 2020
3683aa5
[utils.py] changes
diivm Jul 7, 2020
05e10d5
[parse.py] use join_path
diivm Jul 7, 2020
69cacc7
[parse.py] change `tu` to `source_ast`
diivm Jul 7, 2020
45378d8
[utils.py] remove unnecessary `args` parameter
diivm Jul 7, 2020
6f6586d
[parse.py] update
diivm Jul 7, 2020
7d04ace
[utils.py] update get_json_output_path
diivm Jul 10, 2020
7ffc2d3
[parse.py] refactor for better testing interface
diivm Jul 12, 2020
52b10b6
[parse.py] print_ast was at wrong pos
diivm Jul 13, 2020
d41a0f7
[parse.py] use node dictionary
diivm Jul 13, 2020
a2e530e
[parse.py] change to parse_file
diivm Jul 13, 2020
12c19cc
[parse.py] More comments
diivm Jul 13, 2020
09885dc
[utils.py] More comments
diivm Jul 13, 2020
20aee2d
add context
diivm Jul 14, 2020
7559807
[parse.py] fix import to work across directories
diivm Jul 14, 2020
70690db
[utils.py] modify to add generate.py functionalities
diivm Jul 17, 2020
4dae2b5
[parse.py] update output_filepath
diivm Jul 17, 2020
ffb8d60
[parse.py] update function definitions and calls to use `node`
diivm Jul 19, 2020
8bf2c7b
[parse.py] updates and fixes
diivm Jul 20, 2020
1e18a0f
[utils.py] extension updation and comments
diivm Jul 20, 2020
02de83f
[parse.py] extension change
diivm Jul 20, 2020
fcd0c14
[parse.py] return fix
diivm Jul 20, 2020
cfce950
[parse.py] small changes
diivm Jul 20, 2020
242d057
[utils.py] comment fix
diivm Jul 20, 2020
8c6e53a
Merge pull request #10 from divmadan/fix/correct_parse
diivm Jul 20, 2020
9712956
[tests/context.py] add tests context
diivm Jul 26, 2020
8fd421f
[tests/compile_commands.py] add tests compilation db
diivm Jul 26, 2020
f8a51f9
[test_parse.py] add test_parse.py
diivm Jul 26, 2020
bdd94bc
[parse.py] remove initial check for ast parsing
diivm Jul 21, 2020
a5f592f
[pytest.yml] package version updation
diivm Jul 21, 2020
bebc780
[pytest.yml] package version updation
diivm Jul 23, 2020
b7b6f07
[pytest.yml] simplify
diivm Jul 23, 2020
2196bcd
[test_parse.py] add anonymous test
diivm Jul 28, 2020
17b41a2
Merge pull request #16 from divmadan/fix/anonymous
diivm Jul 28, 2020
31b21e9
[parse.py] introduce ANONYMOUS_ prefix
diivm Jul 28, 2020
3a8f29a
[test_parse.py] update tests for ANONYMOUS prefix
diivm Jul 28, 2020
365d98b
Merge pull request #21 from divmadan/fix/anonymous-hotfix
diivm Jul 28, 2020
214b654
Revert "hotfix for anonymous decls"
diivm Jul 30, 2020
24e9d30
add empty name
diivm Jul 30, 2020
f9404e9
Merge pull request #23 from divmadan/fix/anonymous-hotfix
diivm Jul 30, 2020
7f52454
[test_parse.py] ready tests
diivm Jul 31, 2020
e172799
Merge pull request #24 from divmadan/test-merge
diivm Jul 31, 2020
09a5b2b
[test_parse.py] add initial tests
diivm Jul 26, 2020
19915ca
[test_parse.py] add var_decl and call_expr
diivm Jul 26, 2020
8b6585c
[test_parse.py] refactoring
diivm Jul 30, 2020
c9f1125
Merge pull request #18 from divmadan/devel/test-init
diivm Aug 1, 2020
998bef6
[pytest.yml] whitespace formatting; keys' source updation; remove -y …
diivm Aug 8, 2020
bcb514e
Merge pull request #28 from divmadan/fix/ci
diivm Aug 10, 2020
f53e3e9
[test_parse.py] add struct based tests
diivm Jul 26, 2020
5cf5eb9
[test_parse.py] refactor
diivm Jul 31, 2020
5ef3164
[test_parse.py] struct based tests
diivm Jul 31, 2020
e7eb3a5
[test_parse.py] add aParameter check
diivm Aug 8, 2020
fd55e5c
[test_parse.py] add member_ref name
diivm Aug 8, 2020
fdaad6f
Merge pull request #19 from divmadan/test-struct
diivm Aug 10, 2020
7093ac7
[parse.py] add detailed preprocessing option
diivm Aug 8, 2020
9903317
[parse.py] move is_node_in_this_file to valid_children function
diivm Aug 8, 2020
6aca243
[parse.py] remove child_parsed_info check
diivm Aug 8, 2020
a47f24a
[parse.py] comments updation
diivm Aug 10, 2020
1bc9655
[test_parse.py] correct for inclusion directive
diivm Aug 10, 2020
48f3856
[test_parse.py] template based tests
diivm Jul 26, 2020
4d21a35
[test_parse.py] added more info for template based tests
diivm Aug 11, 2020
7f47c28
[parse.py] replace `is not None` with implicit
diivm Aug 11, 2020
f3dd722
Merge pull request #29 from divmadan/fix/parse
diivm Aug 12, 2020
3278307
Merge pull request #20 from divmadan/devel/test-class-template
diivm Aug 13, 2020
f4d92ef
[parse.py] docstring fix
diivm Aug 13, 2020
23ed6a3
[pytest.yml] clean `on`
diivm Aug 17, 2020
0beb1ce
Merge pull request #35 from divmadan/fix/ci
diivm Aug 17, 2020
48e792e
[test_parse.py] add default and delete ctor
diivm Aug 8, 2020
d6b8cd4
[parse.py] add checks available in cindex.py
diivm Aug 13, 2020
e59d2b3
[parse.py] refactor
diivm Aug 17, 2020
f1bca02
[parse.py] comment
diivm Aug 17, 2020
1268d44
[test_parse.py] add default ctor check
diivm Aug 17, 2020
e5fbc9c
remove unnecessary; cleanup
diivm Aug 8, 2020
e3440f9
[test_parse.py] minor fix .hpp to .cpp
diivm Aug 18, 2020
89dbbab
Merge pull request #36 from divmadan/fix/cleanup
diivm Aug 19, 2020
03121d8
Merge pull request #32 from divmadan/devel/add_checks
diivm Aug 20, 2020
061fc77
Merge pull request #30 from divmadan/devel/default-delete-ctor
diivm Aug 20, 2020
a09ab58
[CMakeLists] update path
diivm Jul 17, 2020
b574125
[CMakeLists] path change
diivm Jul 17, 2020
ffe92ec
[CMakeLists] temp fix
diivm Aug 11, 2020
8b53911
[generate_bindings.py] fixed some stuff, needs cleaning
diivm Jul 14, 2020
25692eb
[generate_bindings.py] cmake build without error!
diivm Jul 17, 2020
0a9624b
[generate_bindings.py] clean
diivm Jul 17, 2020
2f97370
[generate.py] use utils
diivm Jul 17, 2020
2995ba6
[generate.py] messy fix for anonymous gen and member definition
diivm Jul 30, 2020
54491a9
[generate.py] add inclusion_directive
diivm Aug 11, 2020
ae5dcd4
[generate.py] fix cxx_method
diivm Aug 11, 2020
24dafcd
[generate.py] remove parameter_list from constructor
diivm Aug 11, 2020
1f0055e
[generate.py] some comments and minor fixes
diivm Aug 11, 2020
387dab3
[generate.py] comment updation and minor refactoring
diivm Aug 11, 2020
d440805
[generate.py] list to tuple `in`s
diivm Aug 11, 2020
7a0e69d
[generate.py] new names
diivm Aug 13, 2020
d8c0816
[generate.py] remove `get_prev_depth_node`
diivm Aug 13, 2020
a3b9c81
[generate.py] add docstrings - 1
diivm Aug 13, 2020
f09f4ad
[generate.py] add libraries everytime
diivm Aug 17, 2020
527555c
[generate.py] unnecessary if
diivm Aug 18, 2020
f1b9923
[generate.py] close() -> end_scope() rename
diivm Aug 18, 2020
c7027ae
[generate.py] make `get_fields_from_anonymous` static
diivm Aug 18, 2020
c496539
[generate.py] `get_fields_from_anonymous` better internals
diivm Aug 18, 2020
581e847
[generate.py] extract generation for testing calls
diivm Aug 18, 2020
69e4944
[generate.py] elif fix
diivm Aug 18, 2020
9443be5
[generate.py] separate pybind line list
diivm Aug 18, 2020
9c43bf2
[generate.py] fix hardcoded filepath
diivm Aug 18, 2020
58d5f31
[generate.py] add template support
diivm Aug 20, 2020
d129de9
[generate.py] minor fix, use class_name
diivm Aug 21, 2020
7eba647
[generate_bindings.py] initial changes; building
diivm Jun 29, 2020
e2caad9
[generate_bindings.py] stuff, not working as of yet
diivm Jul 14, 2020
9695248
[CMakeLists.txt] add some comments
diivm Aug 22, 2020
e40a17b
Merge pull request #39 from divmadan/fix/make_lives_easier-1
diivm Aug 23, 2020
d31691f
[generate.py] documentation and rearranging
diivm Aug 24, 2020
0d09658
[test_generate.py] init file
diivm Aug 11, 2020
232dd98
[test_generate.py] intial setup and some tests
diivm Aug 18, 2020
12617c2
[test_generate.py] fix intial_lines problem, new function
diivm Aug 18, 2020
28a1673
[test_generate.py] updates
diivm Aug 23, 2020
5875c31
[utils.py] add options to dump_json
diivm Aug 23, 2020
86b10f0
[generate.py] renaming and change `pcl/filename`->`filename` in include
diivm Aug 23, 2020
ba275b7
[test_generate.py] str won't work
diivm Aug 24, 2020
9a70fa1
[generate.py] if condition for default ctor in handle_constructor
diivm Aug 24, 2020
95016c2
Merge pull request #40 from divmadan/fix/make_lives_easier-2
diivm Aug 24, 2020
40a5c7e
[generate.py] fix bad merge and an elif chain
diivm Aug 24, 2020
d7f8f4b
[generate.py] comments and make pybind lines private
diivm Aug 24, 2020
3521b35
[generate.py] updation
diivm Aug 24, 2020
999172c
[test_generate.py] initial_pybind_list private
diivm Aug 24, 2020
86483cd
[pytest.yml] update
diivm Aug 25, 2020
8515a7b
[black.yml] formatting ci
diivm Aug 24, 2020
a88b261
[setup.py] black format
diivm Aug 25, 2020
4b32ed9
Merge pull request #43 from divmadan/devel/format-ci
diivm Aug 25, 2020
4b545f0
Merge pull request #44 from divmadan/fix/pytest-ci
diivm Aug 25, 2020
eea0e90
[generate.py] remove handle_class_template
diivm Aug 26, 2020
ed97be5
[generate.py] better end_scope
diivm Aug 26, 2020
ea8b109
[generate.py] expand comments
diivm Aug 26, 2020
26b6de8
[generate.py] module_name to class ctor
diivm Aug 26, 2020
2b85984
[test_generate.py] module_name to class ctor
diivm Aug 26, 2020
6b09e86
[generate.py] unnecessary collections import
diivm Aug 26, 2020
a9092f0
[generate.py] remove `handle_final` from class
diivm Aug 26, 2020
d074f13
[generate.py] move combine_lines out of the if loop
diivm Aug 26, 2020
17298d2
[generate.py] Add option of directly operating on dicts apart from JSONs
diivm Aug 26, 2020
fa2b67b
[test_generate.py] `generate_bindings`: operate directly on dict
diivm Aug 26, 2020
68bfb14
[generate.py] minor changes
diivm Aug 26, 2020
933da99
[generate.py] range to enumerate
diivm Aug 26, 2020
9a78047
[generate.py] remove self from static method
diivm Aug 26, 2020
ae1c9ce
[generate.py] remove blacklist
diivm Aug 26, 2020
f41e9e0
[generate.py] add Exception to return type
diivm Aug 26, 2020
4a1c70b
[generate.py] nothing, self doesn't work; use classname in staticmethod
diivm Aug 28, 2020
244d49a
[generate.py] comments
diivm Aug 29, 2020
f887f04
[test_generate.py] rename
diivm Aug 29, 2020
3f4ae5e
Merge pull request #41 from divmadan/fix/make_lives_easier-3
diivm Aug 29, 2020
053c28c
[generate.py] fixes encountered during template handling
diivm Aug 29, 2020
8a78e9f
[test_generate.py] todo comment
diivm Aug 29, 2020
276dcda
Apply suggestions from code review
diivm Sep 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Black Formatting

on: [push]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restrict to directories with python files


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Black:
# The type of runner that the job will run on
runs-on: ubuntu-latest

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Setup python version
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? Can we have something like "latest" so we don't need to update the version?


# Install pip and packages
- name: Install pip
run: python -m pip install --upgrade pip

- name: Install black
run: pip install black

# Format with black
- name: Format with black
run: |
cd bindings/python
black .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run black on .dev/scripts too?


# Diff check
- name: Check git diff
# Output the diff in ${GITHUB_WORKSPACE}
run: git diff > black_formatting_diff.patch

# Exit if diff
- name: Set job exit status
run: "[ ! -s black_formatting_diff.patch ]"

# Artifacts
- name: Upload formatting diff
uses: actions/upload-artifact@v2
with:
# We are in ${GITHUB_WORKSPACE}
# ${GITHUB_SHA} won't work: use ${{ github.sha }}
name: black_formatting_diff-${{ github.sha }}
path: black_formatting_diff.patch
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
65 changes: 65 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Pytest

on: [push]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Pytest:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Setup python version
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Display python version
run: python -c "import sys; print(sys.version)"

# Install pip and packages
- name: Install pip
run: python -m pip install --upgrade pip

- name: Install pytest
run: pip install pytest

# Install clang and it's python inteface via apt
- name: Add llvm keys
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' | sudo tee -a /etc/apt/sources.list
echo 'deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' | sudo tee -a /etc/apt/sources.list
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kunaltyagi can/should these two bionic references be extrapolated to an outer scope/file now that we're merging with master?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the name with lsb_release -cs and install lsb-release via apt

- name: Install libclang and its python bindings
run: |
sudo apt-get update
sudo apt-get install -y libclang-11-dev python3-clang-11

# Add dist-package to path to enable apt installed python3-clang import
- name: Add dist-packages to PYTHONPATH
run: echo "::set-env name=PYTHONPATH::${PYTHON_PATH}:/usr/lib/python3/dist-packages"
- name: Display PYTHONPATH
run: python -c "import sys; print('\n'.join(sys.path))"

# Test with pytest
- name: Test with pytest
run: cd ${_PYTHON_BINDINGS_PATH} && pytest --junitxml=${GITHUB_WORKSPACE}/result_${{ matrix.python-version }}.xml
env:
_PYTHON_BINDINGS_PATH: bindings/python

# Artifacts
- name: Upload pytest test results
uses: actions/upload-artifact@v2
with:
# We are in ${GITHUB_WORKSPACE}
# ${GITHUB_SHA} won't work: use ${{ github.sha }}
name: pytest_py${{ matrix.python-version }}-${{ github.sha }}
path: result_${{ matrix.python-version }}.xml
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
158 changes: 158 additions & 0 deletions bindings/discussion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
## Python bindings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be included in the PR as is or modified?


### Shared pointer usage
#### [05-06-2020]
- > When we want `cloud = pcl.PointCloud[pcl.PointXYZ]()` to be a shared_ptr by default, we set the holder class as shared_ptr. This is needed in some cases because the interface otherwise would be non-idomatic:
> ```py
> import pcl
>
> filter = pcl.filters.PassThrough[pcl.PointXYZ]()
> filter.setInput(cloud)
> ```
>
> Here, cloud needs to be a shared_ptr. That can be done in 2 ways
> 1. `cloud = pcl.PointCloud[pcl.PointXYZ]()` and the holder class as shared_ptr
> 2. `cloud = pcl.make_shared[pcl.PointXYZ]()` and holder class as void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cloud = pcl.make_shared[pcl.PointCloud[pcl.PointXYZ]]()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void and shared_ptr (back tick the classes)

>
> The issue is the ease-of-use and expected semantics
> ```py
> cloud2 = cloud1 # Python user will assume this is a shallow copy
> ```
>
> This will only be true for a variable held in a shared_ptr. This is the semantics in Python.
>
> However, wrapping everything in shared_ptr has downsides for C++ wrapper:
> ```py
> import pcl
>
> point = pcl.PointXYZ()
> cloud[100] = point
> ```
>
> If PointXYZ is held in a shared_ptr... things go south. If not, things go south

### Handling unions
#### [04-06-2020]
- > given `assert(&(union.r) == &(union.rgb));` does the following hold:
> `assert id(union_wrapper.r) == id(union_wrapper.rgb) ?`
Yes. Tested.
- Working example:
```cpp
#include <pybind11/pybind11.h>
namespace py = pybind11;

union RGB {
int rgb;
struct {
int r;
int g;
int b;
};
};

PYBIND11_MODULE(pcl, m)
{
py::class_<RGB>(m, "RGB")
.def(py::init<>())
.def_property(
"rgb",
[](RGB& self) -> int { return self.rgb; },
[](RGB& self, int value) { self.rgb = value; })
.def_property(
"r",
[](RGB& self) -> int { return self.r; },
[](RGB& self, int value) { self.r = value; })
.def_property(
"g",
[](RGB& self) -> int { return self.g; },
[](RGB& self, int value) { self.g = value; })
.def_property(
"b",
[](RGB& self) -> int { return self.b; },
[](RGB& self, int value) { self.b = value; });
}
```

### General
#### [05-06-2020]
- MetaCPP relies on Clang's LibTooling to generate all the metadata: https://github.com/mlomb/MetaCPP

#### [04-06-2020]
- > Was reading this yesterday: https://peerj.com/articles/cs-149.pdf
>
> Summary:
> - They too, automatically generate Python bindings for C++ code using Boost::Python.
> - The whole process is python based.
> - Same design as to what we have in mind i.e., parse, process, and generate.
> - Their data structure of choice for the whole process is Abstract Semantic Graph: https://github.com/StatisKit/AutoWIG/blob/master/src/py/autowig/asg.py
> - The architecture is plugin-based, and somebody added a pybind plugin some months back: https://github.com/StatisKit/AutoWIG/blob/master/src/py/autowig/pybind11_generator.py
> - They use libclang for frontend parsing(python API). The project was done some time back so they wrote their own py-libclang code: https://github.com/StatisKit/AutoWIG/blob/master/src/py/autowig/libclang_parser.py
> - Repo: https://github.com/StatisKit/AutoWIG
>
> I think it can act as a good reference for the project. Have a look at the pdf and the source if you wish.
> The libclang python part can be explored from their repo as of now (as python-libclang has no documentation whatsoever and the 1-2 example articles are outdated)
- Problems:
> Templates:
> * suffixing doesn't work well. Unless you're a fan of the pseudo-Hungarian notation espoused by older devs (and by MS). It's ok for 1 (or maybe 2) arguments.
> * Templates in Python represent an instantiation of C++ template. It should be easy to add/remove an instantiation without affecting needless code. It should also be visually easy to switch the template type without having to lookup the notation or count underscores
> * Python has a strong syntax for this: index lookup via __getitem__ and __setitem__
> * Using strings as keys is bad because the editor can't help if spelling is wrong. Pandas MultiKey failed here.
- Use of a templating engine for pybind11 code gen (jinja2>mako)

#### [03-06-2020]
- Ambiguity in the phrase: "full control over clang's AST"

#### [02-06-2020]
- Use of python bindings of libclang, for faster prototyping: https://github.com/llvm/llvm-project/blob/master/clang/bindings/python/clang/cindex.py
- > protyping and exploring python bindings in which everything is runtime and can be done interactively would usually be my first approach

#### [28-05-2020]
- > While reading lsst's documentation, came to find out they use a __str__ method:
> ```py
> cls.def("__str__", [](Class const& self) {
> std::ostringstream os;
> os << self;
> return os.str();
> });
> ```
- > the << operator with ostreams is the most common way in C++ of extracting a string representation of a given object (I have no idea why there's no practice of implementing the cast to string method),
That being said I believe you can use << with std::stringstreams, effectively allowing you to fetch a string representation of PCL objects which have operator<< (std::ostream, ....) implemented.

#### [15-05-2020]
- > You can create docstring from \brief part and copy the function signature via libtooling.

#### [09-05-2020]
- Start with binding PointTypes.
- AST parsing helps in cases of convoluted code.
- > We can keep 2 approaches in parallel:
> 1. header parser on a limited number of files
> 2. libtooling to replace it
> 1st will allow the pipeline to be developed
> 2nd will replace that
- > We can make a prototype which works on manually provided API points
- > From my understanding:
> 1. Code -> AST -> JSON: use some tool for it first, then replace with libtooling
> 2. JSON -> cpp: Python tool, language dependent
> 3. CMake + compile_database.json: rest of toolchain
> 4. organize properly so usage in LANG is nice

#### [05-05-2020]
- > I'd put PyPi integration immediately after we get 1 module working. That'd allow us to keep shipping improved bindings after GSoC (in case the timeline gets delayed)
The order in which modules are tackled should be the dependency order (because we don't have the popularity data from our users)

***

## Javascript Bindings
#### [05-05-2020]
- Webassembly as an option: https://en.wikipedia.org/wiki/WebAssembly
- Emscripten as an option: https://emscripten.org/
- > * Getting clang to compile to WebAsm will be the best "performance".
> * Using Emscripten on the other hand is a well-travelled road, but the performance will be similar to hand written JS (or worse).
> Both approaches need clang so that's a milestone we need to conquer first.

***

## Jupyter Visualisation
#### [05-05-2020]
- > WebGL view straddles JS bindings and Python bindings. It should come before JS bindings in terms of priority keeping in mind the popularity of Python as a second language for the kind of C++ users PCL attracts (academia)
- > https://jupyter.org/widgets has pythreejs which is embedding js in python. .... That's 1 step above webgl, involves using JS in Py, but is faster to get up and running.... We can tackle this based on time when we reach some stage
14 changes: 14 additions & 0 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.5)
project(bindings)

# find_package(PCL REQUIRED)
find_package(PCL COMPONENTS common REQUIRED)

# We can replace `find_package` with `add_subdirectory`, depending on usage.
# https://pybind11.readthedocs.io/en/stable/compiling.html#find-package-vs-add-subdirectory
find_package(pybind11)

pybind11_add_module(pcl ${CMAKE_CURRENT_SOURCE_DIR}/pybind11-gen/common/include/pcl/impl/point_types.cpp)

target_link_libraries(pcl PRIVATE ${PCL_LIBRARIES})
# add_dependencies(pcl_demo some_other_target)
32 changes: 32 additions & 0 deletions bindings/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Python bindings for PCL

### common-archive
- `point_types.json`: contains JSON based meta of `point_types.h` and `point_types.hpp`.
- `py_point_types.cpp`: file generated by `generate_bindings.py` taking meta info from `point_types.json`.
- `union_test.cpp`: testing file for handling of unions.

### generate_bindings.py
- Converts JSON data to pybind11 C++ code.
- Run:
```py
python3 generate_bindings.py <path/to/json>
```

### CMakeLists.txt
- Finding PCL and pybind11, then adding the python module(s) via `pybind11_add_module` (which is a wrapper over `add_library`).

### setup.py
- For using setuptools. Uses `CMakeLists.txt`.

### libclang.py
- Using python libclang to parse C++ code, for generation of metadata by static analysis.
- Run:
```py
python3 libclang.py <path/to/file>
```

### json/*
- JSON output generated by `libclang.py`

### pybind11/*
- pybind11 C++ outupt generated by `generate_bindings.py`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Empty file.
6 changes: 6 additions & 0 deletions bindings/python/scripts/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
import sys

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

import scripts
Loading