Skip to content

Commit ccaa99b

Browse files
committed
task: adding cython build support
1 parent 7e5144f commit ccaa99b

File tree

7 files changed

+206
-0
lines changed

7 files changed

+206
-0
lines changed

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11.4

recompile-pyarrow.bash

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/bash
2+
3+
4+
# ------------------------------
5+
# Overview
6+
7+
# This script is meant to be run from the repository root, where there should be two files that
8+
# define builds: `meson.build` for C++ and `setup.py` for python/cython. Unlike
9+
# `scripts/bootstrap-build.bash`, this script should still work regardless of the directory it is
10+
# executed from.
11+
12+
# >> **IMPORTANT** <<
13+
# This script absolutely must be ran in a context with the appropriate python interpreter.
14+
# Specifically, the virtualenv that is to be used for this repository. As an example, this code was
15+
# developed using poetry for python dependency management. So, using poetry we would run `poetry
16+
# shell` and *then* execute this script, or we would run `poetry run bash
17+
# scripts/recompile-pyarrow.bash` which would execute this script witht he appropriate python
18+
# virtualenv activated.
19+
20+
# This script is located in the `scripts/` directory to keep the root directory relatively clean.
21+
22+
23+
# ------------------------------
24+
# Global variables
25+
26+
# NOTE: this should be a parameter
27+
arrow_prefix="/usr/local/arrow-12.0.1"
28+
arrow_version=">=12.0.0"
29+
30+
# where Ubuntu installs it
31+
# default: arrow_prefix=/usr/local
32+
arrow_python_dirpath="${arrow_prefix}/lib/cmake/arrow"
33+
34+
# where ArchLinux installs it
35+
# default: arrow_prefix=/usr
36+
if [[ -f "/etc/os-release" && -n $(grep "Arch Linux" "/etc/os-release") ]]; then
37+
arrow_python_dirpath="${arrow_prefix}/lib/cmake/arrow"
38+
fi
39+
40+
# export PYARROW_CMAKE_OPTIONS="-DArrowPython_DIR=${arrow_python_dirpath}"
41+
42+
43+
# ------------------------------
44+
# Install logic
45+
46+
# uninstall existing binary
47+
python3 -m pip uninstall pyarrow
48+
49+
# so that we can install a re-compiled binary
50+
python3 -m pip install --no-cache-dir --no-binary :all: "pyarrow${arrow_version}"

setup.py

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env python
2+
3+
# ------------------------------
4+
# License
5+
6+
# Copyright 2023 Aldrin Montana
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
21+
# ------------------------------
22+
# Module Docstring
23+
"""
24+
Build script for the mohair module.
25+
26+
This includes how to compile cython bindings for prototyping integration with Faodel.
27+
"""
28+
29+
30+
# ------------------------------
31+
# Dependencies
32+
33+
# >> Modules
34+
from pathlib import Path
35+
36+
# >> Third-party
37+
import pkgconfig
38+
import numpy
39+
import pyarrow
40+
41+
# >> Classes
42+
from setuptools import Extension
43+
44+
# >> Functions
45+
from setuptools import setup
46+
from Cython.Build import cythonize
47+
48+
49+
# ------------------------------
50+
# Module variables
51+
52+
# >> reference variables
53+
cppsrc_dirpath = Path('src') / 'cpp'
54+
pysrc_dirpath = Path('src') / 'python'
55+
56+
# TODO: these will eventually be migrated into skytether components
57+
# and mohair will be more of a leaf dependency
58+
pkgsrc_dirpath = pysrc_dirpath / 'mohair' / 'cybindings'
59+
60+
61+
# ------------------------------
62+
# Extension definitions
63+
64+
# >> Mohair bindings to faodel and acero wrappers
65+
66+
# |> Resources for the extension
67+
pkgsrc_filelist = [
68+
pkgsrc_dirpath / 'scytether.pyx'
69+
,cppsrc_dirpath / 'engines' / 'faodel.cpp'
70+
,cppsrc_dirpath / 'engines' / 'acero.cpp'
71+
]
72+
73+
pkgdep_inclist = [
74+
numpy.get_include()
75+
,pyarrow.get_include()
76+
,pkgconfig.variables('arrow-acero')['includedir']
77+
,pkgconfig.variables('mohair')['includedir']
78+
,f"{pkgconfig.variables('faodel')['includedir']}/faodel"
79+
]
80+
81+
pkgdep_liblist = [
82+
'arrow'
83+
,'arrow_acero'
84+
,'arrow_substrait'
85+
,'arrow_python'
86+
,'mpi'
87+
,'mpi_cxx'
88+
,'faodel-common'
89+
,'faodel-services'
90+
,'dirman'
91+
,'lunasa'
92+
,'kelpie'
93+
]
94+
95+
pkgdep_libdirs = (
96+
pyarrow.get_library_dirs()
97+
+ [
98+
'/usr/lib'
99+
,'/usr/local/faodel-dev/lib'
100+
]
101+
)
102+
103+
# |> The extension itself
104+
scytether_extension = Extension('scytether'
105+
,list(map(str, pkgsrc_filelist))
106+
,include_dirs=pkgdep_inclist
107+
,library_dirs=pkgdep_libdirs
108+
,libraries=pkgdep_liblist
109+
)
110+
111+
112+
# ------------------------------
113+
# Main build logic
114+
115+
# >> use README.md for long description
116+
with open('README.md', mode='r', encoding='utf-8') as readme_handle:
117+
readme_content = readme_handle.read()
118+
119+
120+
# >> simple variables to capture cython configuration
121+
cythonize_modulelist = [ scytether_extension ]
122+
cythonize_compdirs = { 'language_level': 3 }
123+
124+
setup(
125+
name = 'mohair'
126+
,version = '0.1.0'
127+
,zip_safe = False
128+
,author = 'Aldrin Montana'
129+
,author_email = '[email protected]'
130+
,description = ('Query processing for decomposable queries')
131+
,license = 'MPL 2.0'
132+
,keywords = 'example documentation tutorial'
133+
,url = 'https://github.com/drin/mohair-faodel/'
134+
,long_description = readme_content
135+
136+
,package_dir = { '': str(pysrc_dirpath) }
137+
,packages = [
138+
'mohair'
139+
,'mohair.query'
140+
,'mohair.storage'
141+
,'mohair.mohair'
142+
,'mohair.substrait'
143+
,'mohair.substrait.extensions'
144+
]
145+
,ext_modules = cythonize(
146+
module_list=cythonize_modulelist
147+
,compiler_directives=cythonize_compdirs
148+
)
149+
150+
,classifiers = [
151+
'Development Status :: 1 - Planning'
152+
,'Topic :: Utilities'
153+
,'License :: OSI Approved :: Apache Software License'
154+
]
155+
)

src/python/mohair/mohair/__init__.py

Whitespace-only changes.

src/python/mohair/query/__init__.py

Whitespace-only changes.

src/python/mohair/substrait/__init__.py

Whitespace-only changes.

src/python/mohair/substrait/extensions/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)