Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 61 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Deploy Docs

on:
push:
branches:
- main
paths:
- "cbfpy/**.py"
- "docs/**"
- "examples/**.py"
- "pyproject.toml"
- ".github/workflows/docs.yml"
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: pages
cancel-in-progress: true

env:
PYTHON_VERSION: "3.10"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[dev]"

- name: Build docs
run: sphinx-build -W docs/source docs/build

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/build

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
79 changes: 43 additions & 36 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,75 @@ on:
- main
paths:
- "cbfpy/**.py"
- "docs/**"
- "examples/**.py"
- "tests/**.py"
- "poetry.lock"
- "pyproject.toml"
- ".github/workflows/pr-check.yml"

env:
PYTHON_VERSION: 3.8
PYTHON_VERSION: "3.10"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Poetry cache
uses: actions/cache@v3
id: poetry_cache
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[test]"

- name: Run tests
run: python -m pytest

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache Packages
uses: actions/cache@v3
id: package_cache
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
path: ~/.local
key: poetry-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 -
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[dev]"

- name: Install Dependencies
if: steps.poetry_cache.outputs.cache-hit != 'true' && steps.package_cache.outputs.cache-hit != 'true'
run: poetry install
- name: Ruff check
run: ruff check .

- name: Python Test
run: poetry run task test
- name: Ruff format check
run: ruff format --check .

lint:
- name: Mypy
run: mypy .

docs:
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache Poetry cache
uses: actions/cache@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Packages
uses: actions/cache@v3
with:
path: ~/.local
key: poetry-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[dev]"

- name: Python Lint
run: poetry run task lint
- name: Build docs
run: sphinx-build -W docs/source docs/build
28 changes: 18 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
*__pycache__
__pycache__/
*.pyc
.mypy_cache
.pytest_cache
/docs/source/*
/docs/build/*
!/docs/source/conf.py
*.egg-info/
dist/
.venv/

# type checker / linter
.mypy_cache/
.ruff_cache/

# test
.pytest_cache/
.coverage
coverage.xml
cov_html
.ruff_cache
.venv
dist
cov_html/

# docs
/docs/build/
/docs/source/_build/
/docs/source/Makefile
/docs/source/make.bat
19 changes: 6 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: check-added-large-files
args: ["--maxkb=10000"] # 10MB
args: ["--maxkb=10000"]
- id: check-toml
- id: check-yaml
- repo: https://github.com/pycqa/isort
rev: 5.11.4
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.221"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.10
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"recommendations": [
"ms-python.python",
"njpwerner.autodocstring",
"charliermarsh.ruff",
"ms-python.mypy-type-checker",
"ryanluker.vscode-coverage-gutters"
]
}
10 changes: 7 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"python.linting.mypyArgs": [
"--config-file=./pyproject.toml"
],
"python.testing.pytestEnabled": true,
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports.ruff": "explicit"
}
},
"coverage-gutters.showGutterCoverage": true,
"coverage-gutters.showLineCoverage": true,
"coverage-gutters.showRulerCoverage": true
Expand Down
56 changes: 22 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# cbfpy
Python package for using simple control barrier function.

[**Documentation**](https://toshi67026.github.io/cbfpy/)

## Requirements
- poetry 1.3.1
- Python >= 3.10

## Installation
Create virtualenv and install dependencies defined for the project.
```sh
poetry install
pip install -e .
```

Build and install locally with pip.
With dev/test dependencies:
```sh
poetry build
python -m pip install cbfpy --find-links=dist
pip install -e ".[dev,test]"
```

## Examples
Expand All @@ -24,49 +24,37 @@ python -m pip install cbfpy --find-links=dist

### Usage
```sh
poetry run python examples/example_{cbf name}.py
python examples/example_{cbf name}.py
```

## Document
Generate document from docstring.
```sh
poetry run task docs
```
## Documentation
Documentation is automatically published to [GitHub Pages](https://toshi67026.github.io/cbfpy/) on push to main.

Browse generated document by opening the html files in docs/build/ from your browser.
<img src=assets/sphinx_cbfpy.png>

## Tools
### Format
- isort
- black
To build locally:
```sh
poetry run task fmt
pip install -e ".[dev]"
sphinx-build docs/source docs/build
```
Then open `docs/build/index.html`.

### Lint
- black
- ruff
- mypy
## Tools
### Format & Lint
- [ruff](https://docs.astral.sh/ruff/) (format + lint + import sort)
- [mypy](https://mypy-lang.org/) (type check)
```sh
poetry run task lint
ruff format .
ruff check --fix .
mypy .
```

### Test
- pytest
- pytest-cov
```sh
poetry run task test
pytest
```
The vscode extension [coverage-gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) can be used to display the test coverage.

### pre-commit
Apply [config file](.pre-commit-config.yaml) for pre-commit.
```sh
poetry run pre-commit install
```

### Export requirements.txt
```sh
poetry export -f requirements.txt --output requirements.txt --without-hashes
pre-commit install
```
28 changes: 28 additions & 0 deletions cbfpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from cbfpy.cbf import (
CBFBase,
CircleCBF,
GeneralCBF,
LiDARCBF,
Pnorm2dCBF,
ScalarCBF,
ScalarRangeCBF,
UnicycleCircleCBF,
UnicyclePnorm2dCBF,
rotation_matrix_2d,
)
from cbfpy.cbf_qp_solver import CBFNomQPSolver, CBFQPSolver

__all__ = [
"CBFBase",
"CBFNomQPSolver",
"CBFQPSolver",
"CircleCBF",
"GeneralCBF",
"LiDARCBF",
"Pnorm2dCBF",
"ScalarCBF",
"ScalarRangeCBF",
"UnicycleCircleCBF",
"UnicyclePnorm2dCBF",
"rotation_matrix_2d",
]
Loading