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
24 changes: 10 additions & 14 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,28 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.11"]
python: ["3.10", "3.11", "3.12", "3.13"]
clang: ["18"]

steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
python-version: ${{ matrix.python }}
- name: "Set up Python"
run: uv python install ${{ matrix.python }}
- name: Setup Clang
uses: egor-tensin/setup-clang@v1
with:
version: ${{ matrix.clang }}
platform: x64
- name: Install virtual env and dependencies
run: |
python -m venv .venv
source ./.venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install the project
run: uv sync
- name: Type checks
run: |
source ./.venv/bin/activate
python -m mypy *.py --check-untyped-defs
run: uv run mypy *.py --check-untyped-defs
- name: Tests
run: |
source ./.venv/bin/activate
PY_CPPMODEL_LIBCLANG_PATH=/usr/lib/llvm-18/lib/libclang-18.so.1 \
python -m unittest discover --verbose .
uv run python -m unittest discover --verbose .
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: forbid-submodules
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.2
Expand Down
6 changes: 2 additions & 4 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ install a virtual environment with pre-commmit set up, and then use precommit to
install git hooks it to your local repository:

```bash
python3 -m venv .venv # Create a Python virtual env
source ./.venv/bin/activate # Activate the virtual env for bash by source.
pip install -r requirements.txt # Install latest requirements including pre-commit
pre-commit install # Use pre-commit to install git hooks into the working repository.
uv sync # Install dependencies
uv run pre-commit install # Use pre-commit to install git hooks into the working repository.
```

pre-commit is configured with .pre-commit-config.yaml which contains some
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ simple Python model of a C++ translation unit.
Currently the environment variable `PY_CPPMODEL_LIBCLANG_PATH` must be defined
to specify where libclang can be found. This may be fixed in the future.

## Testing
## Development

To set up the development environment, execute the following commands:

```sh
uv sync
```

To run the tests, run:

```sh
python3 -m venv .venv # Create a Python virtual env.
source ./.venv/bin/activate # Activate the virtual env for bash by source.
./test.macos.sh
```

To run type checking:

mypy *.py --check-untyped-defs # Run mypy to check type hints.
unittest discover . # Run tests.
```sh
uv run mypy *.py --check-untyped-defs
```

## Attribution
Expand Down
37 changes: 37 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[project]
name = "py-cppmodel"
version = "0.0.1"
description = "A Python wrapper around clang's python bindings to generate a simple Python model of a C++ translation unit."
readme = "README.md"
requires-python = ">=3.10"
license = { file = "LICENSE" }
authors = [{ name = "J.B. Coe", email = "jonathanbcoe@gmail.com" }]
dependencies = [
"clang>=14.0",
]

[project.urls]
Repository = "https://github.com/jbcoe/py_cppmodel"

[dependency-groups]
dev = [
"ipython>=8.12.3",
"jupyter>=1.1.1",
"mypy>=1.19.1",
"parameterized>=0.9.0",
"pre-commit>=4.5.1",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.sdist]
include = [
"py_cppmodel.py",
"LICENSE",
"README.md",
]

[tool.hatch.build.targets.wheel]
include = ["py_cppmodel.py"]
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

10 changes: 4 additions & 6 deletions test.macos.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env bash

# Virtual environment setup
python3 -m venv .venv # Create a Python virtual env
source ./.venv/bin/activate # Activate the virtual env for bash by source.
python3 -m pip install -r requirements.txt # Install latest requirements.
# Install dependencies
uv sync

# Type checks
python3 -m mypy *.py --check-untyped-defs # Run mypy to check type hints
uv run mypy *.py --check-untyped-defs

# Unit tests
PY_CPPMODEL_LIBCLANG_PATH=/Library/Developer/CommandLineTools/usr/lib/libclang.dylib \
python3 -m unittest discover --verbose . # Run tests
uv run python -m unittest discover --verbose .
2 changes: 0 additions & 2 deletions test_py_cppmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import py_cppmodel
import unittest

from ctypes.util import find_library

LIBCLANG_PATH = os.environ.get("PY_CPPMODEL_LIBCLANG_PATH")
if not LIBCLANG_PATH:
raise RuntimeError("PY_CPPMODEL_LIBCLANG_PATH is unset")
Expand Down
Loading