Skip to content

Commit

Permalink
remove submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Jul 16, 2024
1 parent 07dcca0 commit 594c970
Show file tree
Hide file tree
Showing 19 changed files with 287 additions and 195 deletions.
23 changes: 0 additions & 23 deletions .flake8

This file was deleted.

8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ dist/
pyminiply/_wrapper.cpp
*.so
*.pyc

# cmake
#######
CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
compile_commands.json
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

56 changes: 23 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,72 +1,62 @@
# See https://pre-commit.ci/
ci:
autofix_prs: true
autoupdate_schedule: quarterly
autofix_prs: true
autoupdate_schedule: quarterly

repos:
- repo: https://github.com/psf/black
rev: 23.12.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.2
hooks:
- id: black
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: ^(docs/|tests)
- id: ruff-format

- repo: https://github.com/keewis/blackdoc
rev: v0.3.9
hooks:
- id: blackdoc
exclude: README.rst

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
exclude: "setup.py"
args: [
"--profile", "black",
"--force-sort-within-sections",
"--skip-glob", "*__init__.py",
]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
args: ["--skip=*.vt*"]
args: [--skip=*.vt*]

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
additional_dependencies: [tomli==2.0.1]
files: ^pyminiply/.*\.py
files: ^src/pyminiply/.*\.py

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: trailing-whitespace
exclude: .*\.cdb$

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
hooks:
- id: pretty-format-toml
args: [--autofix]
- id: pretty-format-yaml
args: [--autofix, --indent, '2']

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
- id: clang-format
files: |
(?x)^(
pyminiply/[^_].*\.cpp.*
)$

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
rev: 0.29.0
hooks:
- id: check-github-workflows
- id: check-github-workflows

- repo: https://github.com/dzhu/rstfmt
rev: v0.0.14
hooks:
- id: rstfmt
- id: rstfmt
53 changes: 53 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.15...3.26)

project(nanobind_project LANGUAGES CXX)
# find_package(OpenMP REQUIRED)

# Try to import all Python components potentially needed by nanobind
find_package(Python 3.8
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)

# Import nanobind through CMake's find_package mechanism
find_package(nanobind CONFIG REQUIRED)

nanobind_add_module(
# Name of the extension
_wrapper

# Target the stable ABI for Python 3.12+, which reduces
# the number of binary wheels that must be built. This
# does nothing on older Python versions
STABLE_ABI

# conserve space by reusing a shared libnanobind across libraries
NB_STATIC

src/wrapper.cpp
src/miniply/miniply.cpp
)

# Link OpenMP
# if(OpenMP_CXX_FOUND)
# target_link_libraries(_wrapper PRIVATE OpenMP::OpenMP_CXX)
# endif()

# Compiler-specific options
if(MSVC)
# Use MSVC optimization levels and OpenMP setup
target_compile_options(_wrapper PRIVATE /O2 /std:c++17)
# /openmp:llvm
else()
# Assuming GCC or Clang
target_compile_options(_wrapper PRIVATE -O3)
# -fopenmp
endif()

# Example debugging
# set solib-search-path /home/user/python/.venv311/lib/python3.11/site-packages/stl_reader/
# set breakpoint with b qual.cpp:4872
# target_compile_options(stl_reader PRIVATE -g -O0)
# target_compile_options(pfh PRIVATE -g -O0)

# Install directive for scikit-build-core
install(TARGETS _wrapper LIBRARY DESTINATION pyminiply)
57 changes: 57 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
### C Extension

This repository interfaces with `miniply/miniply.cpp` via
[nanobind](https://github.com/wjakob/nanobind) to efficiently generate C++
extensions.

#### Emacs configuration

If using emacs and helm, generate the project configuration files using `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`. Here's a sample configuration for C++11 on Linux:

```
pip install nanobind
export NANOBIND_INCLUDE=$(python -c "import nanobind, os; print(os.path.join(os.path.dirname(nanobind.__file__), 'cmake'))")
cmake -Dnanobind_DIR=$NANOBIND_INCLUDE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES="/usr/include/c++/11;/usr/include/x86_64-linux-gnu/c++/11/;/usr/lib/gcc/x86_64-linux-gnu/11/include/"
```

These will be necessary for helm and treesit to determine the locations of the header files.


#### Debug Build

This can be helpful when debugging segfaults since this extension often uses raw pointers.


Set the cmake build type to debug in `pyproject.toml``
```
[tool.scikit-build]
cmake.build-type = "Debug"
```

Set the target compile options to build debug symbols with `-g` and `-O0` in `CMakeLists.txt`:

```
target_compile_options(_utilities PRIVATE -g -O0)
```

Finally, run using `gdb`. For example:

```
$ gdb --args python test_ext.py
(gdb) b qual.cpp:4872
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (qual.cpp:4872) pending.
(gdb) run
Thread 1 "python" hit Breakpoint 1, ComputeWeights<float> (offset=0x1fe5830, neigh=0x20432e0,
indices=0x1bb8ec0, points=0x1d6a7a0, n_neigh=108, n_points=27, fac=-0.75, num_threads=4) at /home/user/library-path/src/qual.cpp:4872
4872 T *weights = new T[n_neigh];
(gdb)
```

#### Debugging memory leaks

These can be challenging to find. Use [valgrind](https://valgrind.org/) with the following to identify memory leaks. Be sure to download [valgrind-python.supp](https://github.com/python/cpython/blob/main/Misc/valgrind-python.supp).

```
valgrind --leak-check=full --log-file=val.txt --suppressions=valgrind-python.supp pytest -k clus && grep 'new\[\]' val.txt
```
5 changes: 0 additions & 5 deletions MANIFEST.in

This file was deleted.

8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

``pyminiply`` is a Python library for rapidly reading PLY files. It is a
Python wrapper around the fast C++ PLY reading library provided by
`miniply <ehttps://github.com/vilya/miniply>`_. Thanks @vilya!
`miniply <https://github.com/vilya/miniply>`_. Thanks @vilya!

The main advantage of ``pyminiply`` over other PLY reading libraries is
its performance. See the benchmarks below for more details.
Expand All @@ -27,6 +27,12 @@ The recommended way to install ``pyminiply`` is via PyPI:
pip install pyminiply
Optionally with PyVista:

.. code:: sh
pip install pyminipl[pyvista]
You can also clone the repository and install it from source:

.. code:: sh
Expand Down
2 changes: 0 additions & 2 deletions pyminiply/__init__.py

This file was deleted.

10 changes: 0 additions & 10 deletions pyminiply/_version.py

This file was deleted.

1 change: 0 additions & 1 deletion pyminiply/miniply
Submodule miniply deleted from 1a235c
2 changes: 0 additions & 2 deletions pyminiply/wrapper.hpp

This file was deleted.

72 changes: 46 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
[build-system]
requires = [
"setuptools>=42",
"wheel>=0.33.0",
"cython>=3",
"oldest-supported-numpy"
]

build-backend = "setuptools.build_meta"
build-backend = "scikit_build_core.build"
requires = ["scikit-build-core >=0.4.3", "nanobind >=1.3.2"]

[tool.pytest.ini_options]
junit_family= "legacy"
filterwarnings = [
# bogus numpy ABI warning (see numpy/#432)
"ignore:.*numpy.dtype size changed.*:RuntimeWarning",
"ignore:.*numpy.ufunc size changed.*:RuntimeWarning"
[project]
authors = [
{name = "PyVista Developers", email = "[email protected]"}
]
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]
dependencies = [
"numpy"
]
description = "Rapidly read in PLY files using a wrapper over miniply"
name = "pyminiply"
readme = "README.rst"
requires-python = ">=3.8"
version = "0.2.dev0"

[project.optional-dependencies]
pyvista = ["pyvista"]

[tool.cibuildwheel]
archs = ["auto64"] # 64-bit only
skip = "cp36-* cp37-* pp* *musllinux*" # disable PyPy and musl-based wheels
test-requires = "pytest pyvista"
test-command = "pytest {project}/tests"
test-requires = "pytest pyvista"

[tool.cibuildwheel.macos]
archs = ["native"]
Expand All @@ -29,18 +42,25 @@ archs = ["native"]
MACOSX_DEPLOYMENT_TARGET = "10.14" # Needed for full C++17 support on MacOS

[tool.codespell]
skip = '*.cxx,*.h,*.gif,*.png,*.jpg,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./doc/build/*,./doc/images/*,./dist/*,*~,.hypothesis*,*.cpp,*.c'
quiet-level = 3
skip = '*.cxx,*.h,*.gif,*.png,*.jpg,*.js,*.html,*.doctree,*.ttf,*.woff,*.woff2,*.eot,*.mp4,*.inv,*.pickle,*.ipynb,flycheck*,./.git/*,./.hypothesis/*,*.yml,./doc/build/*,./doc/images/*,./dist/*,*~,.hypothesis*,*.cpp,*.c'

[tool.isort]
profile = "black"
force_sort_within_sections = true
default_section = "THIRDPARTY"
skip_glob = ["__init__.py"]
src_paths = ["doc", "src", "tests"]
[tool.pytest.ini_options]
filterwarnings = [
# bogus numpy ABI warning (see numpy/#432)
"ignore:.*numpy.dtype size changed.*:RuntimeWarning",
"ignore:.*numpy.ufunc size changed.*:RuntimeWarning"
]
testpaths = 'tests'

[tool.black]
[tool.ruff]
line-length = 100
skip-string-normalization = true
target-version = ['py39']
exclude='\.eggs|\.git|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist|node_modules'

[tool.ruff.lint]
extend-select = ["I"]

[tool.scikit-build]
# Setuptools-style build caching in a local directory
build-dir = "build/{wheel_tag}"
minimum-version = "0.4"
sdist.exclude = [".github", "*.png", "tests", ".mypy_cache", ".pre-commit-config.yaml", "*_cache", "CONTRIBUTING.md", ".gitignore"]
Loading

0 comments on commit 594c970

Please sign in to comment.