Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
kaihsin committed Nov 19, 2024
0 parents commit c6a51e8
Show file tree
Hide file tree
Showing 15 changed files with 631 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/clang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint
on:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/[email protected]
with:
clang-format-version: '14'
check-path: 'src'
fallback-style: 'Google' # optional
18 changes: 18 additions & 0 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Run isort
on:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: isort/isort-action@v1
with:
sortPaths: "src" # only sort files in the src directory
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint
on:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
42 changes: 42 additions & 0 deletions .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Pytest
on:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true


jobs:
uv-test:
name: python
runs-on: ubuntu-latest

strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
# Install a specific version of uv.
version: "0.5.1"
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Setup Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install the project
run: uv sync --all-extras --dev

- name: Run tests
run: uv run pytest
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/*
*/__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info
# venv
.venv
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
args: ['--unsafe']
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.3.5"
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.6
hooks:
- id: clang-format
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)

set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 CONFIG REQUIRED)

pybind11_add_module(_core MODULE src/main.cpp)
install(TARGETS _core DESTINATION ${SKBUILD_PROJECT_NAME})
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Cytnx-core
This is the core compoment of the cytnx library

## Develop

### Package Management
We use [uv](https://docs.astral.sh/uv/getting-started/installation/) to manage the package.

```bash
uv sync --all-extras --dev
```

### Building Dependency:

- c++ compiler
- cmake 3.15 (see CMakeList.txt)

* most of the deps should be able to install via pypi.
64 changes: 64 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[project]
name = "cytnx-core"
version = "0.1.0"
description = "Core component of cytnx"
readme = "README.md"
authors = [
{ name = "kaihsin", email = "[email protected]" }
]
requires-python = ">=3.10"
dependencies = []

[tool.scikit-build]
minimum-version = "build-system.requires"
build-dir = "build/{wheel_tag}"

[tool.black]
line-length = 88

[tool.ruff]
target-version = "py310"
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

[tool.ruff.lint]
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.isort]
profile = "black"
combine_as_imports = true
multi_line_output = 3
src_paths = ["src/cytnx_core"]

[build-system]
requires = ["scikit-build-core>=0.10", "pybind11"]
build-backend = "scikit_build_core.build"

[dependency-groups]
dev = [
"isort>=5.13.2",
"lint>=1.2.1",
"pre-commit>=4.0.1",
"pytest>=8.3.3",
"ruff>=0.7.4",
]
5 changes: 5 additions & 0 deletions src/cytnx_core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cytnx_core._core import hello_from_bin


def hello() -> str:
return hello_from_bin()
3 changes: 3 additions & 0 deletions src/cytnx_core/_core.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import annotations

def hello_from_bin() -> str: ...
Empty file added src/cytnx_core/py.typed
Empty file.
13 changes: 13 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <pybind11/pybind11.h>

std::string hello_from_bin() { return "Hello from test-build!"; }

namespace py = pybind11;

PYBIND11_MODULE(_core, m) {
m.doc() = "pybind11 hello module";

m.def("hello_from_bin", &hello_from_bin, R"pbdoc(
A function that returns a Hello string.
)pbdoc");
}
5 changes: 5 additions & 0 deletions test/test_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cytnx_core import hello


def test_str():
assert isinstance(hello(), str)
Loading

0 comments on commit c6a51e8

Please sign in to comment.