Skip to content

Commit

Permalink
bump version, merge pull request #37 from AMYPAD/pybind11
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Feb 19, 2024
2 parents 6c2b75c + 5c66eb4 commit 5e71cb3
Show file tree
Hide file tree
Showing 36 changed files with 1,222 additions and 743 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/comment-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
post({
owner: context.repo.owner, repo: context.repo.repo,
comment_id: context.payload.comment.id, content: "eyes"})
github-token: ${{ secrets.GH_TOKEN || github.token }}
- name: Tag Commit
run: |
git clone https://${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY} repo
Expand All @@ -39,7 +40,7 @@ jobs:
rm -rf repo
env:
BODY: ${{ github.event.comment.body }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
- name: React Success
uses: actions/github-script@v7
with:
Expand All @@ -50,3 +51,4 @@ jobs:
post({
owner: context.repo.owner, repo: context.repo.repo,
comment_id: context.payload.comment.id, content: "rocket"})
github-token: ${{ secrets.GH_TOKEN || github.token }}
111 changes: 25 additions & 86 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,17 @@ on:
push:
pull_request:
schedule: [{cron: '30 23 * * 6'}] # M H d m w (Sat at 23:30)
workflow_dispatch:
jobs:
check:
clang-format:
if: github.event_name != 'pull_request' || !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: set PYSHA
run: echo "PYSHA=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PYSHA }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: dependencies
run: |
pip install -U pre-commit
sudo apt-get install -yqq clang-format
- uses: reviewdog/action-setup@v1
- if: github.event_name == 'push' || github.event_name == 'pull_request'
name: comment
run: |
if [[ $EVENT == pull_request ]]; then
REPORTER=github-pr-review
else
REPORTER=github-check
fi
pre-commit run -a todo | reviewdog -efm="%f:%l: %m" -name=TODO -tee -reporter=$REPORTER -filter-mode nofilter
pre-commit run -a flake8 | reviewdog -f=pep8 -name=flake8 -tee -reporter=$REPORTER -filter-mode nofilter
pre-commit run -a mypy | reviewdog -efm="%f:%l: %m" -name=mypy -tee -reporter=$REPORTER -filter-mode nofilter
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EVENT: ${{ github.event_name }}
- run: pre-commit run -a --show-diff-on-failure
with: {python-version: '3.x'}
- run: sudo apt-get install -yqq clang-format
- uses: pre-commit/action@v3.0.1
with: {extra_args: --all-files clang-format}
test:
if: github.event_name != 'pull_request' || !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association)
name: py${{ matrix.python }}
Expand All @@ -48,31 +23,18 @@ jobs:
python: [3.7, 3.11]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
with: {fetch-depth: 0}
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: pip install -U -e .[dev]
# in-place for pytest (-e . doesn't work yet for scikit-build-core)
run: |
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["build-system"]["requires"] + ["cmake>=" + c["tool"]["scikit-build"]["cmake"]["minimum-version"]]), end="")' \
| xargs -0 pip install ninja
pip install --no-build-isolation --no-deps -t . -U -v . -Ccmake.define.CUVEC_DEBUG=1
git restore cuvec/src
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["project"]["dependencies"] + c["project"]["optional-dependencies"]["dev"]), end="")' \
| xargs -0 pip install
- run: pytest
- uses: codecov/codecov-action@v3
run: make CXX_FLAGS='' deps-build build-editable deps-run
- run: make test
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: compile -Wall
run: |
git clean -Xdf
pip install build
python -m build -n -w \
-Ccmake.define.CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-function-type"
run: make clean build-wheel
cuda:
if: github.event_name != 'pull_request' || !contains('OWNER,MEMBER,COLLABORATOR', github.event.pull_request.author_association)
name: CUDA py${{ matrix.python }}
Expand All @@ -82,57 +44,38 @@ jobs:
python: [3.7, 3.11]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
with: {fetch-depth: 0}
- name: Run setup-python
run: setup-python -p${{ matrix.python }} 'cuda-version<12' cupy
run: setup-python -p${{ matrix.python }} 'cuda-version<12' 'cupy<13'
- name: pip install -U -e .[dev]
# in-place for pytest (-e . doesn't work yet for scikit-build-core)
run: |
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["build-system"]["requires"] + ["cmake>=" + c["tool"]["scikit-build"]["cmake"]["minimum-version"]]), end="")' \
| xargs -0 pip install ninja
pip install --no-build-isolation --no-deps -t . -U -v . -Ccmake.define.CUVEC_DEBUG=1
git restore cuvec/src
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["project"]["dependencies"] + c["project"]["optional-dependencies"]["dev"]), end="")' \
| xargs -0 pip install
- run: pytest
- uses: codecov/codecov-action@v3
run: make CXX_FLAGS='' deps-build build-editable deps-run
- run: make test
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: compile -Wall
run: |
git clean -Xdf
pip install build
python -m build -n -w \
-Ccmake.define.CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-function-type" \
-Ccmake.define.CMAKE_CUDA_ARCHITECTURES=all
run: make CUDA_ARCHITECTURES=all clean build-wheel
- name: Post Run setup-python
run: setup-python -p${{ matrix.python }} -Dr
if: ${{ always() }}
deploy:
needs: [check, test, cuda]
needs: [clang-format, test, cuda]
name: PyPI Deploy
environment: pypi
permissions:
contents: write
id-token: write
permissions: {contents: write, id-token: write}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN || github.token }}
- uses: actions/setup-python@v5
with:
python-version: '3.x'
with: {python-version: '3.x'}
- id: dist
uses: casperdcl/deploy-pypi@v2
with:
build: -s
upload: false
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
upload: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
name: Release
run: |
Expand All @@ -142,11 +85,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GH_TOKEN || github.token }}
- name: Docs
run: |
pushd docs
pip install -U -r requirements.txt
PYTHONPATH=. pydoc-markdown --build --site-dir=../../../dist/site
popd
run: make deps-docs docs
- if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') || github.event_name == 'workflow_dispatch' }}
uses: casperdcl/push-dir@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ __pycache__/
/cuvec/example_swig.py
/cuvec/swvec.py
/dist/
/build/
/docs/build/

# Unit test / coverage reports
Expand Down
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ci: {skip: [clang-format]}
default_language_version:
python: python3
repos:
Expand Down Expand Up @@ -26,7 +27,7 @@ repos:
types: [text]
exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
args: [-j8]
Expand All @@ -50,7 +51,7 @@ repos:
args: [-i]
additional_dependencies: [toml]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/doublify/pre-commit-clang-format
Expand Down
23 changes: 8 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,24 @@
Install in "development/editable" mode including dev/test dependencies:

```sh
git clone https://github.com/AMYPAD/CuVec && cd CuVec
# clone & install dependencies (one-off)
git clone https://github.com/AMYPAD/CuVec
cd CuVec
make deps-build deps-run

# `pip install -e .[dev]` won't work due to https://github.com/scikit-build/scikit-build-core/issues/114
# work-around:
# 1. install dependencies (one-off)
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml")
print("\0".join(c["build-system"]["requires"] + c["project"]["dependencies"] + c["project"]["optional-dependencies"]["dev"]), end="")' \
| xargs -0 pip install -U ninja cmake
# 2. delete build artefacts, (re)build & install in-place with debug info
git clean -Xdf
pip install --no-build-isolation --no-deps -t . -U -v . \
-Ccmake.define.CUVEC_DEBUG=1
-Ccmake.define.CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-function-type"
git restore cuvec/src # undo deletion of sources
# delete build artefacts, (re)build & install in-place with debug info
make CUVEC_DEBUG=1 build-editable
```

Once installed in development/editable mode, tests may be run using:

```sh
pytest
pytest -k "not perf"
```

To run performance tests, build with debugging disabled (`CUVEC_DEBUG=0`), then run:

```sh
pytest -k "perf" -n=0
python tests/test_perf.py
```
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# NOTE: cannot `pip install -U -e .[dev]` (install in-place for pytest)
# since `-e .` doesn't work yet (https://github.com/scikit-build/scikit-build-core/issues/114).
# Instead, do `make deps-build build-editable deps-run`
CUVEC_DEBUG=0
CXX_FLAGS=-Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-cast-function-type
CUDA_ARCHITECTURES=native
BUILD_CMAKE_FLAGS=-Ccmake.define.CUVEC_DEBUG=$(CUVEC_DEBUG) -Ccmake.define.CMAKE_CXX_FLAGS="$(CXX_FLAGS)" -Ccmake.define.CMAKE_CUDA_ARCHITECTURES=$(CUDA_ARCHITECTURES)
CCACHE=
ifneq ($(CCACHE),)
BUILD_CMAKE_FLAGS+= -Ccmake.define.CMAKE_CXX_COMPILER_LAUNCHER=ccache
endif
.PHONY: build-editable clean deps-build deps-run build-wheel deps-docs docs docs-serve
build-editable:
git diff --exit-code --quiet '*/src/**' || (echo "Uncommitted changes in */src"; exit 1)
pip install --no-build-isolation --check-build-dependencies -Cbuild-dir=build --no-deps -t . -U -v . $(BUILD_CMAKE_FLAGS)
git restore '*/src/**'
test:
pytest -k "not perf" -n=3
pytest -k "perf" -n=0 --cov-append
clean:
git clean -Xdf
deps-build:
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml"); print("\0".join(c["build-system"]["requires"] + ["cmake>=" + c["tool"]["scikit-build"]["cmake"]["minimum-version"]]), end="")' | xargs -0 pip install ninja
deps-run:
pip install toml
python -c 'import toml; c=toml.load("pyproject.toml"); print("\0".join(c["project"]["dependencies"] + c["project"]["optional-dependencies"]["dev"]), end="")' | xargs -0 pip install
build-wheel:
pip install build
python -m build -n -w $(BUILD_CMAKE_FLAGS)
deps-docs:
cd docs && pip install -r requirements.txt
docs:
cd docs && PYTHONPATH=. pydoc-markdown --build --site-dir=../../../dist/site
docs-serve: docs
python -m http.server -d dist/site
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ See also `NumCu <https://github.com/AMYPAD/NumCu>`_, a minimal stand-alone Pytho
External Projects
~~~~~~~~~~~~~~~~~

For integration into Python, C++, CUDA, CMake, and general SWIG projects, see `the external project documentation <https://amypad.github.io/CuVec/#external-projects>`_.
Full and explicit example modules using the `CPython API <https://github.com/AMYPAD/CuVec/tree/main/cuvec/src/example_mod>`_ and `SWIG <https://github.com/AMYPAD/CuVec/tree/main/cuvec/src/example_swig>`_ are also provided.
For integration into Python, C++, CUDA, CMake, pybind11, and general SWIG projects, see `the external project documentation <https://amypad.github.io/CuVec/#external-projects>`_.
Full and explicit example modules using the `CPython API <https://github.com/AMYPAD/CuVec/tree/main/cuvec/src/example_cpython>`_, `pybind11 API <https://github.com/AMYPAD/CuVec/tree/main/cuvec/src/example_pybind11>`_, and `SWIG <https://github.com/AMYPAD/CuVec/tree/main/cuvec/src/example_swig>`_ are also provided.

Contributing
~~~~~~~~~~~~
Expand All @@ -83,7 +83,7 @@ Copyright:
:target: https://github.com/AMYPAD/CuVec/blob/main/LICENCE
.. |Tests| image:: https://img.shields.io/github/actions/workflow/status/AMYPAD/CuVec/test.yml?branch=main&logo=GitHub
:target: https://github.com/AMYPAD/CuVec/actions
.. |Downloads| image:: https://img.shields.io/pypi/dm/cuvec.svg?logo=pypi&logoColor=white&label=PyPI%20downloads
.. |Downloads| image:: https://img.shields.io/pypi/dm/cuvec?logo=pypi&logoColor=white
:target: https://pypi.org/project/cuvec
.. |Coverage| image:: https://codecov.io/gh/AMYPAD/CuVec/branch/main/graph/badge.svg
:target: https://codecov.io/gh/AMYPAD/CuVec
Expand Down
Loading

0 comments on commit 5e71cb3

Please sign in to comment.