Skip to content

Commit f3febc5

Browse files
authored
fix: sdist and wheels content (#28)
* missing sdist in pypi index * installing pybind11 as a build time python package dependency * add missing windows pyd files --------- Signed-off-by: Michele Dolfi <[email protected]>
1 parent f69f960 commit f3febc5

File tree

6 files changed

+70
-39
lines changed

6 files changed

+70
-39
lines changed

.github/actions/setup-poetry/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ runs:
1313
- uses: actions/setup-python@v4
1414
with:
1515
python-version: ${{ inputs.python-version }}
16+
update-environment: false
1617
cache: 'poetry'
18+
- name: Setup poetry env with correct python
19+
run: poetry env use python3
20+
shell: bash
1721
- name: Install only dependencies and not the package itself
1822
run: poetry install --all-extras --no-root
1923
shell: bash

.github/workflows/checks.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ jobs:
1212
python-version: ['3.9', '3.10', '3.11', '3.12']
1313
steps:
1414
- uses: actions/checkout@v4
15-
# - name: Install dependencies [linux]
16-
# run: sudo apt-get install -y libldap-common
17-
# shell: bash
1815
- uses: ./.github/actions/setup-poetry
1916
with:
2017
python-version: ${{ matrix.python-version }}
2118
- name: Run styling check
2219
run: poetry run pre-commit run --all-files
2320
- name: Install with poetry
24-
run: poetry install --all-extras
21+
run: |
22+
poetry install --all-extras
23+
ls -l
24+
ls -l docling_parse
2525
- name: Testing
2626
run: |
2727
poetry run pytest -v tests

.github/workflows/wheels.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
echo "Inspecting $file"
117117
poetry run python -m zipfile --list "$file"
118118
done
119-
mkdir ./dist
119+
mkdir -p ./dist
120120
cp wheelhouse/*.whl ./dist/
121121
122122
# there is an error with the tagging of wheels for macosx-arm64
@@ -156,7 +156,7 @@ jobs:
156156
echo "Inspecting $file"
157157
poetry run python -m zipfile --list "$file"
158158
done
159-
mkdir ./dist
159+
mkdir -p ./dist
160160
cp wheelhouse/*.whl ./dist/
161161
162162
- name: Set up QEMU [linux]
@@ -165,6 +165,13 @@ jobs:
165165
with:
166166
platforms: all
167167

168+
- name: Build sdist
169+
# build only on Linux to avoid too many duplicates of the sdist
170+
if: matrix.os.name == 'ubuntu-latest'
171+
run: |
172+
echo "Building wheel ${CIBW_BUILD}"
173+
poetry build -f sdist
174+
168175
- name: Build wheels [linux]
169176
if: matrix.os.name == 'ubuntu-latest'
170177
env:
@@ -186,7 +193,7 @@ jobs:
186193
echo "Inspecting $file"
187194
poetry run python -m zipfile --list "$file"
188195
done
189-
mkdir ./dist
196+
mkdir -p ./dist
190197
cp wheelhouse/*.whl ./dist/
191198
192199
- name: Set up MSYS2 [windows]

CMakeLists.txt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ include(cmake/extlib_utf8.git.cmake)
102102
include(cmake/extlib_jpeg.cmake)
103103
# include(cmake/extlib_qpdf_v10.cmake)
104104
include(cmake/extlib_qpdf_v11.cmake)
105-
include(cmake/extlib_pybind11.cmake)
105+
# include(cmake/extlib_pybind11.cmake)
106106

107107
include(cmake/os_opts.cmake)
108108

@@ -146,19 +146,9 @@ target_link_libraries(parse ${LIB_LINK})
146146
# *** Python-binding ***
147147
# ***************************
148148

149-
# inspiration from
150-
# 1. https://github.com/pybind/cmake_example/blob/master/CMakeLists.txt`
151-
# 2. https://blog.devgenius.io/calling-python-and-c-code-using-pybind-99ab7fefa685
152-
# 3. https://github.com/pybind/cmake_example/issues/11
153-
154-
include(FetchContent)
155-
FetchContent_Declare(pybind11
156-
FETCHCONTENT_BASE_DIR extlib_pybind11
157-
GIT_REPOSITORY https://github.com/pybind/pybind11.git
158-
GIT_TAG v2.13.5
159-
GIT_SHALLOW TRUE
160-
)
161-
FetchContent_MakeAvailable(pybind11)
149+
# https://pybind11.readthedocs.io/en/stable/compiling.html
150+
find_package (Python COMPONENTS Interpreter Development)
151+
find_package(pybind11 CONFIG REQUIRED)
162152

163153
pybind11_add_module(docling_parse "${TOPLEVEL_PREFIX_PATH}/app/pybind_parse.cpp")
164154

build.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,30 @@
55
import sys
66

77
import subprocess
8+
from typing import List
9+
import pybind11
810

911
ROOT_DIR = os.path.abspath("./")
1012
BUILD_DIR = os.path.join(ROOT_DIR, "build")
1113

14+
def get_pybind11_cmake_args():
15+
pybind11_sys_path = os.getenv("PYBIND11_SYSPATH")
16+
if pybind11_sys_path:
17+
# pybind11_include_dir = os.path.join(pybind11_sys_path, "include")
18+
pybind11_cmake_dir = os.path.join(pybind11_sys_path, "share", "cmake", "pybind11")
19+
else:
20+
# pybind11_include_dir = pybind11.get_include()
21+
pybind11_cmake_dir = pybind11.get_cmake_dir()
22+
# print(f"{pybind11_include_dir=}")
23+
print(f"{pybind11_cmake_dir=}")
24+
return [f"-Dpybind11_DIR={pybind11_cmake_dir}"]
1225

13-
def run(cmd, cwd="./"):
26+
def run(cmd: List[str], cwd: str="./"):
1427

15-
print(f"\nlaunch: {cmd}")
28+
print_cmd = " ".join(cmd)
29+
print(f"\nlaunch: {print_cmd}")
1630

17-
parts = cmd.split(" ")
18-
message = subprocess.run(parts, cwd=cwd)
31+
message = subprocess.run(cmd, cwd=cwd)
1932

2033
if "returncode=0" in str(message):
2134
print(f" -> SUCCESS")
@@ -27,20 +40,26 @@ def run(cmd, cwd="./"):
2740

2841
def build_local(num_threads: int):
2942

30-
if not os.path.exists(BUILD_DIR):
31-
print("python executable: ", sys.executable)
32-
33-
cmd = f"cmake -B {BUILD_DIR} -DPYTHON_EXECUTABLE={sys.executable}"
34-
success = run(cmd, cwd=ROOT_DIR)
35-
if not success:
36-
raise RuntimeError("Error building.")
37-
else:
38-
print(f"build directory detected: {BUILD_DIR}")
43+
print("python prefix: ", sys.exec_prefix)
44+
config_cmd = [
45+
"cmake",
46+
"-B", f"{BUILD_DIR}",
47+
f"-DPython_ROOT_DIR={sys.exec_prefix}",
48+
f"-DPython3_ROOT_DIR={sys.exec_prefix}",
49+
]
50+
config_cmd.extend(get_pybind11_cmake_args())
51+
success = run(config_cmd, cwd=ROOT_DIR)
52+
if not success:
53+
raise RuntimeError("Error building.")
3954

40-
cmd = f"cmake --build {BUILD_DIR} --target install"
55+
build_cmd = [
56+
"cmake",
57+
"--build", f"{BUILD_DIR}",
58+
"--target=install",
59+
]
4160
if num_threads > 1:
42-
cmd += f" -j {num_threads}"
43-
success = run(cmd, cwd=ROOT_DIR)
61+
build_cmd.extend(["-j", f"{num_threads}"])
62+
success = run(build_cmd, cwd=ROOT_DIR)
4463
if not success:
4564
raise RuntimeError("Error building.")
4665

pyproject.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ readme = "README.md"
2929
packages = [{include = "docling_parse"}]
3030
include = [
3131
{path = "docling_parse/*.so", format = "wheel"},
32-
{path = "docling_parse/pdf_resources", format = "wheel"}
32+
{path = "docling_parse/*.pyd", format = "wheel"},
33+
{path = "docling_parse/pdf_resources", format = ["sdist", "wheel"]},
34+
{path = "docling_parse/pdf_resources", format = ["sdist", "wheel"]},
35+
{path = "CMakeLists.txt", format = "sdist"},
36+
{path = "build.py", format = "sdist"},
37+
{path = "*.md", format = "sdist"},
38+
{path = "poetry.lock", format = "sdist"},
39+
{path = "app/*.cpp", format = "sdist"},
40+
{path = "cmake/", format = "sdist"},
41+
{path = "app/", format = "sdist"},
42+
{path = "src/", format = "sdist"},
43+
{path = "tests/", format = "sdist"},
3344
]
3445
build = "build.py"
3546

@@ -56,7 +67,7 @@ pytest = "^7.4.2"
5667
docling-parse = "docling_parse.run:main"
5768

5869
[build-system]
59-
requires = ["poetry-core"]
70+
requires = ["poetry-core", "pybind11>=2.13.1"]
6071
build-backend = "poetry.core.masonry.api"
6172

6273
[tool.black]

0 commit comments

Comments
 (0)