Skip to content

Commit

Permalink
fix: python version in wheels (#31)
Browse files Browse the repository at this point in the history
[skip ci]

---------

Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
  • Loading branch information
dolfim-ibm authored Oct 2, 2024
1 parent c342951 commit 8d903ba
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
7 changes: 5 additions & 2 deletions .github/actions/setup-poetry/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ runs:
- name: Install poetry
run: pipx install poetry==1.8.3
shell: bash
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
id: py
with:
python-version: ${{ inputs.python-version }}
update-environment: false
cache: 'poetry'
- name: Setup poetry env with correct python
run: poetry env use python3
run: |
poetry env use ${{ steps.py.outputs.python-path }}
poetry run python --version
shell: bash
- name: Install only dependencies and not the package itself
run: poetry install --all-extras --no-root
Expand Down
53 changes: 46 additions & 7 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
# list of github vm: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]

os:
- name: "ubuntu-latest"
Expand Down Expand Up @@ -51,11 +51,21 @@ jobs:

- name: Setup Python
uses: actions/setup-python@v5
id: py
with:
python-version: ${{ matrix.python-version }}
update-environment: false

- name: Install Poetry
run: python -m pip install poetry==1.8.3
run: |
which python
python --version
which python3
python3 --version
echo "pythonpath: ${{ steps.py.outputs.python-path }}"
${{ steps.py.outputs.python-path }} --version
pipx install poetry==1.8.3
poetry env use ${{ steps.py.outputs.python-path }}
- name: Set up custom PATH and set py version to cpXYZ [windows]
if: ${{matrix.os.platform_id == 'win_amd64'}}
Expand Down Expand Up @@ -97,9 +107,15 @@ jobs:
CIBW_ENVIRONMENT: "MACOSX_DEPLOYMENT_TARGET=${{ matrix.os.macos_version }}.0"
ARCHFLAGS: -arch x86_64
BUILD_THREADS: "4"
PYTORCH_MPS_HIGH_WATERMARK_RATIO: "0.0"
run: |
echo "Building wheel ${CIBW_BUILD}"
PY_CACHE_TAG=$(poetry run python -c 'import sys;print(sys.implementation.cache_tag)')
echo "Building wheel ${CIBW_BUILD} ${{ env.CIBW_BUILD }}"
echo "Building cp: ${{ env.python_cp_version }}"
echo "Building cache_tag: ${PY_CACHE_TAG}"
echo "Building platform_id: ${{ matrix.os.platform_id }}"
poetry run python --version
poetry run python --version | grep ${{ matrix.python-version }}
poetry install --no-root --only=build
cat ./pyproject.toml
poetry run python -m cibuildwheel --output-dir wheelhouse
Expand All @@ -115,6 +131,10 @@ jobs:
for file in ./wheelhouse/*.whl; do
echo "Inspecting $file"
poetry run python -m zipfile --list "$file"
echo "Checking if .so is contained in the wheel"
poetry run python -m zipfile --list "$file" | grep \\.so
echo "Checking if the correct python version is contained in the wheel"
poetry run python -m zipfile --list "$file" | grep ${PY_CACHE_TAG}
done
mkdir -p ./dist
cp wheelhouse/*.whl ./dist/
Expand All @@ -137,9 +157,16 @@ jobs:
CIBW_ENVIRONMENT: "MACOSX_DEPLOYMENT_TARGET=${{ matrix.os.macos_version }}.0"
ARCHFLAGS: -arch arm64
BUILD_THREADS: "4"
PYTORCH_MPS_HIGH_WATERMARK_RATIO: "0.0"
CUDA_VISIBLE_DEVICES: "cpu"
run: |
echo "Building wheel ${CIBW_BUILD}"
PY_CACHE_TAG=$(poetry run python -c 'import sys;print(sys.implementation.cache_tag)')
echo "Building wheel ${CIBW_BUILD} ${{ env.CIBW_BUILD }}"
echo "Building cp: ${{ env.python_cp_version }}"
echo "Building cache_tag: ${PY_CACHE_TAG}"
echo "Building platform_id: ${{ matrix.os.platform_id }}"
poetry run python --version
poetry run python --version | grep ${{ matrix.python-version }}
poetry install --no-root --only=build
cat ./pyproject.toml
poetry run python -m cibuildwheel --output-dir wheelhouse
Expand All @@ -155,6 +182,10 @@ jobs:
for file in ./wheelhouse/*.whl; do
echo "Inspecting $file"
poetry run python -m zipfile --list "$file"
echo "Checking if .so is contained in the wheel"
poetry run python -m zipfile --list "$file" | grep \\.so
echo "Checking if the correct python version is contained in the wheel"
poetry run python -m zipfile --list "$file" | grep ${PY_CACHE_TAG}
done
mkdir -p ./dist
cp wheelhouse/*.whl ./dist/
Expand Down Expand Up @@ -183,15 +214,23 @@ jobs:
CIBW_BUILD_VERBOSITY: 3
BUILD_THREADS: "8"
run: |
echo "Building wheel ${CIBW_BUILD}"
PY_CACHE_TAG=$(poetry run python -c 'import sys;print(sys.implementation.cache_tag)')
echo "Building cp: ${{ env.python_cp_version }}"
echo "Building cache_tag: ${PY_CACHE_TAG}"
echo "Building platform_id: ${{ matrix.os.platform_id }}"
poetry run python --version
poetry run python --version | grep ${{ matrix.python-version }}
poetry install --no-root --only=build
cat ./pyproject.toml
poetry run python -m cibuildwheel --output-dir ./wheelhouse
ls -l ./wheelhouse
for file in ./wheelhouse/*.whl; do
echo "Inspecting $file"
poetry run python -m zipfile --list "$file"
echo "Checking if .so is contained in the wheel"
poetry run python -m zipfile --list "$file" | grep \\.so
echo "Checking if the correct python version is contained in the wheel"
poetry run python -m zipfile --list "$file" | grep ${PY_CACHE_TAG}
done
mkdir -p ./dist
cp wheelhouse/*.whl ./dist/
Expand Down Expand Up @@ -256,9 +295,9 @@ jobs:
- name: publish wheels (dry run)
run: |
poetry publish --dry-run --no-interaction -vvv
poetry publish --skip-existing --dry-run --no-interaction -vvv
- name: publish wheels (on publishing) [for releases only]
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
poetry publish --no-interaction -vvv
poetry publish --skip-existing --no-interaction -vvv
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.12..3.26)

project(docling_parse VERSION 1.0.0 LANGUAGES CXX C)
#set(CMAKE_VERBOSE_MAKEFILE off)
Expand Down Expand Up @@ -147,7 +147,7 @@ target_link_libraries(parse ${LIB_LINK})
# ***************************

# https://pybind11.readthedocs.io/en/stable/compiling.html
find_package (Python COMPONENTS Interpreter Development)
# https://pybind11.readthedocs.io/en/stable/compiling.html#configuration-variables
find_package(pybind11 CONFIG REQUIRED)

pybind11_add_module(docling_parse "${TOPLEVEL_PREFIX_PATH}/app/pybind_parse.cpp")
Expand Down
4 changes: 2 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def run(cmd: List[str], cwd: str="./"):
def build_local(num_threads: int):

print("python prefix: ", sys.exec_prefix)
print("python executable: ", sys.executable)
config_cmd = [
"cmake",
"-B", f"{BUILD_DIR}",
f"-DPython_ROOT_DIR={sys.exec_prefix}",
f"-DPython3_ROOT_DIR={sys.exec_prefix}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
]
config_cmd.extend(get_pybind11_cmake_args())
success = run(config_cmd, cwd=ROOT_DIR)
Expand Down

0 comments on commit 8d903ba

Please sign in to comment.