Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ee/src/cpp_example/naive_svg.hpp (#1)

* add headers

* init code

* fix

* rename to naive-svg

* fix

* init code

* update

* update

* init

* not ready

* faster build

---------

Co-authored-by: TANG ZHIXIONG <[email protected]>
  • Loading branch information
district10 and zhixiong-tang authored Sep 2, 2023
1 parent 862eee8 commit 3f73c8a
Show file tree
Hide file tree
Showing 20 changed files with 646 additions and 334 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@ jobs:
with:
submodules: true

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
with:
platforms: all

- uses: pypa/[email protected]
env:
# CIBW_ARCHS: auto64
CIBW_ARCHS_LINUX: x86_64 aarch64
CIBW_ARCHS_LINUX: x86_64
CIBW_ARCHS_WINDOWS: AMD64 # ARM64
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_BEFORE_BUILD: pip install numpy fire --prefer-binary
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = pybind11
url = https://github.com/pybind/pybind11.git
branch = master
[submodule "headers"]
path = headers
url = https://github.com/cubao/headers.git
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
cmake_minimum_required(VERSION 3.4...3.18)
project(cubao_cmake_example)
project(naive_svg)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(headers/include)

add_subdirectory(pybind11)
pybind11_add_module(pybind11_cubao_cmake_example src/main.cpp)
file(GLOB SRCS src/*.cpp)
pybind11_add_module(_naive_svg ${SRCS})

# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
# define (VERSION_INFO) here.
target_compile_definitions(pybind11_cubao_cmake_example
target_compile_definitions(_naive_svg
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ python_build:
python_sdist:
$(PYTHON) setup.py sdist
python_test:
$(PYTHON) -c 'from pybind11_rdp import rdp; print(rdp([[1, 1], [2, 2], [3, 3], [4, 4]]))'
$(PYTHON) -c 'import cubao_cmake_example; print(cubao_cmake_example.add(1, 2))'
$(PYTHON) -m cubao_cmake_example add 1 2
$(PYTHON) -m cubao_cmake_example subtract 9 4
$(PYTHON) -m cubao_cmake_example pure_python_func --arg1=43234
python3 -m pip install pytest
pytest tests

Expand Down
208 changes: 3 additions & 205 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cmake-example
# naive-svg

Online document: **[readthedocs](http://cmake-example.readthedocs.io/)**
Online document: **[readthedocs](http://naive-svg.readthedocs.io/)**

<!--intro-start-->

Expand All @@ -9,207 +9,5 @@ Online document: **[readthedocs](http://cmake-example.readthedocs.io/)**
Install:

```bash
python3 -m pip install cubao_cmake_example # install from pypi
python3 -c 'import cubao_cmake_example; print(cubao_cmake_example.add(1, 2))'
python3 -m pip install naive-svg # install from pypi
```

CLI interface: (created with [python-fire](https://github.com/google/python-fire))

```bash
python3 -m cubao_cmake_example add 1 2
python3 -m cubao_cmake_example subtract 9 4
```

Help:

```bash
$ python3 -m cubao_cmake_example --help
INFO: Showing help with the command '__main__.py -- --help'.

NAME
__main__.py

SYNOPSIS
__main__.py GROUP | COMMAND

GROUPS
GROUP is one of the following:

fire
The Python Fire module.

COMMANDS
COMMAND is one of the following:

add
add(arg0: int, arg1: int) -> int

subtract
subtract(arg0: int, arg1: int) -> int

pure_python_func
```

```bash
$ python3 -m cubao_cmake_example pure_python_func --help
INFO: Showing help with the command '__main__.py pure_python_func -- --help'.

NAME
__main__.py pure_python_func

SYNOPSIS
__main__.py pure_python_func <flags>

FLAGS
--arg1=ARG1
Type: int
Default: 42
--arg2=ARG2
Type: float
Default: 3.14
--arg3=ARG3
Type: str
Default: 'you shall not pass'

$ python3 -m cubao_cmake_example pure_python_func --arg1=43234
int: 43234, float: 3.14, str: you shall not pass
```

<!--intro-end-->

---

# Make a release

(We now use Github Workflow to release to pypi. Skip the rest if you don't want to manually compile wheels.)

## On linux

Install docker then

```
make python_build_all_in_linux
make upload_wheels
```

## On macOS

Install c++ compiler and cmake.

Install conda and envs:

```
# conda create -y -n py36 python=3.6
# conda create -y -n py37 python=3.7
conda create -y -n py38 python=3.8
conda create -y -n py39 python=3.9
conda create -y -n py310 python=3.10
conda env list
```

Then

```
make python_build_all_in_macos
make upload_wheels
```

## On windows

Install visual studio and cmake, (also git for windows, maybe).

Install conda and envs same as on macOS, then:

```
make python_build_all_in_windows
make upload_wheels
```

---

# cmake_example for pybind11

[![Gitter][gitter-badge]][gitter-link]

| CI | status |
|----------------------|--------|
| MSVC 2015 | [![AppVeyor][appveyor-badge]][appveyor-link] |
| conda.recipe | [![Conda Actions Status][actions-conda-badge]][actions-conda-link] |
| pip builds | [![Pip Actions Status][actions-pip-badge]][actions-pip-link] |
| [`cibuildwheel`][] | [![Wheels Actions Status][actions-wheels-badge]][actions-wheels-link] |

[gitter-badge]: https://badges.gitter.im/pybind/Lobby.svg
[gitter-link]: https://gitter.im/pybind/Lobby
[actions-badge]: https://github.com/pybind/cmake_example/workflows/Tests/badge.svg
[actions-conda-link]: https://github.com/pybind/cmake_example/actions?query=workflow%3A%22Conda
[actions-conda-badge]: https://github.com/pybind/cmake_example/workflows/Conda/badge.svg
[actions-pip-link]: https://github.com/pybind/cmake_example/actions?query=workflow%3A%22Pip
[actions-pip-badge]: https://github.com/pybind/cmake_example/workflows/Pip/badge.svg
[actions-wheels-link]: https://github.com/pybind/cmake_example/actions?query=workflow%3AWheels
[actions-wheels-badge]: https://github.com/pybind/cmake_example/workflows/Wheels/badge.svg
[appveyor-link]: https://ci.appveyor.com/project/dean0x7d/cmake-example/branch/master
[appveyor-badge]: https://ci.appveyor.com/api/projects/status/57nnxfm4subeug43/branch/master?svg=true

An example [pybind11](https://github.com/pybind/pybind11) module built with a
CMake-based build system. This is useful for C++ codebases that have an
existing CMake project structure. This is in many cases superseded by
[`scikit_build_example`](https://github.com/pybind/scikit_build_example), which uses
[scikit-build][], a tool from the makers of CMake designed to allow Python
packages to be driven from CMake. However, there are still cases where you
might want full control over the CMake run; and both of these approaches have
some trade-offs not present in a pure setuptools build (see
[`python_example`](https://github.com/pybind/python_example)). Python 3.6+ required;
see the commit history for older versions of Python.

## Prerequisites

* A compiler with C++11 support
* Pip 10+ or CMake >= 3.4 (or 3.8+ on Windows, which was the first version to support VS 2015)
* Ninja or Pip 10+


## Installation

Just clone this repository and pip install. Note the `--recursive` option which is
needed for the pybind11 submodule:

```bash
git clone --recursive https://github.com/pybind/cmake_example.git
pip install ./cmake_example
```

With the `setup.py` file included in this example, the `pip install` command will
invoke CMake and build the pybind11 module as specified in `CMakeLists.txt`.



## Building the documentation

Documentation for the example project is generated using Sphinx. Sphinx has the
ability to automatically inspect the signatures and documentation strings in
the extension module to generate beautiful documentation in a variety formats.
The following command generates HTML-based reference documentation; for other
formats please refer to the Sphinx manual:

- `cd cmake_example/docs`
- `make html`


## License

Pybind11 is provided under a BSD-style license that can be found in the LICENSE
file. By using, distributing, or contributing to this project, you agree to the
terms and conditions of this license.


## Test call

```python
import cubao_cmake_example
cubao_cmake_example.add(1, 2)
```

[`cibuildwheel`]: https://cibuildwheel.readthedocs.io
[FAQ]: http://pybind11.rtfd.io/en/latest/faq.html#working-with-ancient-visual-studio-2009-builds-on-windows
[vs2015_runtime]: https://www.microsoft.com/en-us/download/details.aspx?id=48145
[scikit-build]: https://scikit-build.readthedocs.io/en/latest/
10 changes: 0 additions & 10 deletions cubao_cmake_example/__init__.py

This file was deleted.

3 changes: 1 addition & 2 deletions docs/about/license.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ The legal stuff.
## Included projects

* [pybind/pybind11](https://github.com/pybind/pybind11/blob/master/LICENSE) (BSD)
* [pybind/cmake_example](https://github.com/pybind/cmake_example/blob/master/LICENSE) (BSD)

## License (BSD)

See <https://github.com/cubao/cmake_example/blob/master/LICENSE>.
See <https://github.com/cubao/pybind11-naive-svg/blob/master/LICENSE>.
20 changes: 6 additions & 14 deletions docs/about/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@

## Upgrading

To upgrade `cubao_cmake_example` to the latest version, use pip:
To upgrade `naive-svg` to the latest version, use pip:

```bash
pip install -U cubao_cmake_example
pip install -U naive-svg
```

## Version 0.0.3 (2023-03-04)
## Version 0.0.1 (2023-09-02)

* Add macOS arm64 (for m1 chip)

## Version 0.0.2 (2023-03-03)

* Release to pypi on GitHub workflow

## Version 0.0.1 (2022-10-14)

* First release to pypi
* TODO

---

You can also checkout releases on:

- GitHub: <https://github.com/cubao/cmake_example/releases>
- PyPi: <https://pypi.org/project/cubao-cmake-example>
- GitHub: <https://github.com/cubao/pybind11-naive-svg/releases>
- PyPi: <https://pypi.org/project/naive-svg>
43 changes: 1 addition & 42 deletions docs/code.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
# code

GitHub: [cmake-example](https://github.com/cubao/cmake_example)

## CMakeLists.txt

```cmake
{%
include-markdown "../CMakeLists.txt"
comments=false
%}
```

## src/main.cpp

```cpp
{%
include-markdown "../src/main.cpp"
comments=false
%}
```
## setup.py
<details>
<summary>code</summary>
```python
{%
include-markdown "../setup.py"
comments=false
%}
```

</details>

## tests/test_basic.py

```cpp
{%
include-markdown "../tests/test_basic.py"
comments=false
%}
```
GitHub: [cmake-example](https://github.com/cubao/pybind11-naive-svg)
Loading

0 comments on commit 3f73c8a

Please sign in to comment.