Skip to content

Commit db3b421

Browse files
committed
initial commit
0 parents  commit db3b421

File tree

12 files changed

+269
-0
lines changed

12 files changed

+269
-0
lines changed

.github/workflows/format.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: format
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
pre-commit:
11+
name: black
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.x"
18+
- run: pip install black
19+
- run: black src/pyodr
20+
- run: git diff --exit-code

.github/workflows/pip.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: pip
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
platform: [windows-latest, macos-13, ubuntu-latest]
15+
python-version: ["3.7", "3.11"]
16+
runs-on: ${{ matrix.platform }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Add requirements
23+
run: python -m pip install --upgrade wheel setuptools
24+
- name: Build and install
25+
run: pip install --verbose .[test]
26+
- name: Test
27+
run: python -m pytest

.github/workflows/wheels.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: wheels
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
release:
9+
types:
10+
- published
11+
12+
jobs:
13+
build_sdist:
14+
name: Build SDist
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Build SDist
19+
run: pipx run build --sdist
20+
- name: Check metadata
21+
run: pipx run twine check dist/*
22+
- uses: actions/upload-artifact@v4
23+
with:
24+
name: cibw-sdist
25+
path: dist/*.tar.gz
26+
27+
build_wheels:
28+
name: Wheels on ${{ matrix.os }}
29+
runs-on: ${{ matrix.os }}
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
os: [ubuntu-latest, windows-latest, macos-13]
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: pypa/cibuildwheel@v2.17
37+
env:
38+
CIBW_ARCHS_MACOS: auto universal2
39+
- name: Verify clean directory
40+
run: git diff --exit-code
41+
shell: bash
42+
- name: Upload wheels
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: cibw-wheels-${{ matrix.os }}
46+
path: wheelhouse/*.whl
47+
48+
upload_all:
49+
name: Upload if release
50+
needs: [build_wheels, build_sdist]
51+
runs-on: ubuntu-latest
52+
if: github.event_name == 'release' && github.event.action == 'published'
53+
steps:
54+
- uses: actions/setup-python@v5
55+
with:
56+
python-version: "3.x"
57+
- uses: actions/download-artifact@v4
58+
with:
59+
pattern: cibw-*
60+
path: dist
61+
merge-multiple: true
62+
- uses: pypa/gh-action-pypi-publish@release/v1
63+
with:
64+
password: ${{ secrets.pypi_password }}

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build/
2+
dist/
3+
_build/
4+
_generate/
5+
*.so
6+
*.py[cod]
7+
*.egg-info
8+
*env*

pyproject.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=42",
4+
"wheel",
5+
"ninja",
6+
"cmake>=3.12",
7+
]
8+
build-backend = "setuptools.build_meta"
9+
10+
[tool.mypy]
11+
files = "setup.py"
12+
python_version = "3.7"
13+
strict = true
14+
show_error_codes = true
15+
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
16+
warn_unreachable = true
17+
18+
[[tool.mypy.overrides]]
19+
module = ["ninja"]
20+
ignore_missing_imports = true
21+
22+
23+
[tool.pytest.ini_options]
24+
minversion = "6.0"
25+
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
26+
xfail_strict = true
27+
filterwarnings = [
28+
"error",
29+
"ignore:(ast.Str|Attribute s|ast.NameConstant|ast.Num) is deprecated:DeprecationWarning:_pytest",
30+
]
31+
testpaths = ["tests"]
32+
33+
[tool.cibuildwheel]
34+
test-command = "pytest {project}/tests"
35+
test-extras = ["test"]
36+
test-skip = ["*universal2:arm64"]
37+
# Setuptools bug causes collision between pypy and cpython artifacts
38+
before-build = "rm -rf {project}/build"
39+
40+
[tool.ruff]
41+
target-version = "py37"
42+
43+
[tool.ruff.lint]
44+
extend-select = [
45+
"B", # flake8-bugbear
46+
"I", # isort
47+
"PGH", # pygrep-hooks
48+
"RUF", # Ruff-specific
49+
"UP", # pyupgrade
50+
]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
black

setup.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import subprocess
3+
import sys
4+
from pathlib import Path
5+
6+
from setuptools import Extension, setup
7+
from setuptools.command.build_ext import build_ext
8+
9+
10+
class CMakeExtension(Extension):
11+
def __init__(self, name: str, sourcedir: str = "") -> None:
12+
super().__init__(name, sources=[])
13+
self.sourcedir = os.fspath(Path(sourcedir).resolve())
14+
15+
16+
class CMakeBuild(build_ext):
17+
def build_extension(self, ext: CMakeExtension) -> None:
18+
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
19+
extdir = ext_fullpath.parent.resolve()
20+
21+
build_temp = Path(self.build_temp) / ext.name
22+
build_temp.mkdir(parents=True, exist_ok=True)
23+
24+
conan_args = [
25+
f"--output-folder={build_temp}",
26+
"--build=missing",
27+
"-s", "build_type=Release",
28+
]
29+
30+
subprocess.run(
31+
["/Users/andreas/.local/pipx/venvs/conan/bin/conan", "install", ext.sourcedir, *conan_args], check=True
32+
)
33+
34+
cmake_args = [
35+
f"-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake",
36+
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
37+
f"-DPYTHON_EXECUTABLE={sys.executable}",
38+
f"-DCMAKE_BUILD_TYPE=Release",
39+
]
40+
41+
build_args = []
42+
43+
subprocess.run(
44+
["cmake", "-S", ext.sourcedir, "-B", build_temp, *cmake_args], check=True
45+
)
46+
subprocess.run(
47+
["cmake", "--build", build_temp, *build_args], check=True
48+
)
49+
50+
51+
setup(
52+
name="pyodr",
53+
version="0.0.1",
54+
author="Andreas Stefl",
55+
author_email="stefl.andreas@gmail.com",
56+
description="C++ library that translates office documents to HTML",
57+
long_description="",
58+
ext_modules=[CMakeExtension("pyodr", "src/cpp")],
59+
cmdclass={"build_ext": CMakeBuild},
60+
zip_safe=False,
61+
extras_require={"test": ["pytest>=6.0"]},
62+
python_requires=">=3.7",
63+
)

src/cpp/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cmake_minimum_required(VERSION 3.18.1)
2+
project(pyodr CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_EXTENSIONS OFF)
7+
8+
find_package(odrcore REQUIRED)
9+
find_package(pybind11 REQUIRED)
10+
11+
pybind11_add_module(pyodr pyodr.cpp)
12+
target_link_libraries(pyodr PRIVATE odrcore::odrcore pybind11::module)

src/cpp/CMakeUserPresets.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": 4,
3+
"vendor": {
4+
"conan": {}
5+
},
6+
"include": [
7+
"../../../../../../var/folders/44/dm0p2bkj6_gb2nnj2lg2pyph0000gn/T/tmp28rzux6t.build-temp/pybind/CMakePresets.json",
8+
"../../../../../../var/folders/44/dm0p2bkj6_gb2nnj2lg2pyph0000gn/T/tmpm5jfqij4.build-temp/pyodr/CMakePresets.json"
9+
]
10+
}

src/cpp/conanfile.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[requires]
2+
odrcore/4.1.1
3+
pybind11/2.13.1
4+
5+
[generators]
6+
CMakeToolchain
7+
CMakeDeps

src/cpp/pyodr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <pybind11/pybind11.h>
2+
3+
namespace py = pybind11;
4+
5+
PYBIND11_MODULE(pyodr, m) {
6+
m.attr("__version__") = "dev";
7+
}

src/pyodr/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)