Skip to content

Commit 61c6917

Browse files
authored
chore(python): Update Python packaging (#625)
This PR updates the Python packaging to build a single nanoarrow library that is shared amongst the various extension modules and updates the version of cibuildwheel such that we can release Python 3.13 wheels in our upcoming release. I'm not sure where the mechanism used to build a "shared" library is documented, nor am I sure that it is truly a "shared" library (may be static); however, it seems conceptually better than the existing system of compiling the source files more than once for each module that needed them.
1 parent 120a8e1 commit 61c6917

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

.github/workflows/python-wheels.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
python-version: "3.12"
112112

113113
- name: Install cibuildwheel
114-
run: python -m pip install cibuildwheel==2.19.1
114+
run: python -m pip install cibuildwheel==2.21.1
115115

116116
- name: Set nanoarrow Python dev version
117117
if: github.ref == 'refs/heads/main'

python/setup.py

+38-37
Original file line numberDiff line numberDiff line change
@@ -94,55 +94,56 @@ def get_version(pkg_path):
9494
device_library_dirs.append(str(lib_dirs[0].parent))
9595

9696

97-
def nanoarrow_extension(
98-
name, *, nanoarrow_c=False, nanoarrow_device=False, nanoarrow_ipc=False
99-
):
100-
sources = ["src/" + name.replace(".", "/") + ".pyx"]
101-
libraries = []
102-
library_dirs = []
103-
include_dirs = ["src/nanoarrow", "vendor"]
104-
define_macros = list(extra_define_macros)
105-
106-
if nanoarrow_c:
107-
sources.append("vendor/nanoarrow.c")
108-
109-
if nanoarrow_device:
110-
sources.append("vendor/nanoarrow_device.c")
111-
include_dirs.extend(device_include_dirs)
112-
libraries.extend(device_libraries)
113-
library_dirs.extend(device_library_dirs)
114-
define_macros.extend(device_define_macros)
115-
116-
if nanoarrow_ipc:
117-
sources.extend(["vendor/nanoarrow_ipc.c", "vendor/flatcc.c"])
97+
# This mechanism to build a static c library against which extensions
98+
# can be linked is not well documented but is a better solution than
99+
# simply including these files as sources to the extensions that need
100+
# them. A more robust solution would be to use Meson or CMake to build
101+
# the Python extensions since they can both build a shared nanoarrow
102+
# and link it. This mechanism is the build_clib command available in
103+
# setuptools (and previously from distutils).
104+
common_libraries = [
105+
[
106+
"nanoarrow_python_shared",
107+
{
108+
"sources": [
109+
"vendor/nanoarrow.c",
110+
"vendor/nanoarrow_device.c",
111+
"vendor/nanoarrow_ipc.c",
112+
"vendor/flatcc.c",
113+
],
114+
"include_dirs": ["vendor"] + device_include_dirs,
115+
"libraries": device_libraries,
116+
"library_dirs": device_library_dirs,
117+
"macros": extra_define_macros + device_define_macros,
118+
},
119+
]
120+
]
121+
118122

123+
def nanoarrow_extension(name, *, link_device=False):
119124
return Extension(
120125
name=name,
121-
include_dirs=include_dirs,
126+
include_dirs=["vendor", "src/nanoarrow"],
122127
language="c",
123-
sources=sources,
128+
sources=["src/" + name.replace(".", "/") + ".pyx"],
124129
extra_compile_args=extra_compile_args,
125130
extra_link_args=extra_link_args,
126-
define_macros=define_macros,
127-
library_dirs=library_dirs,
128-
libraries=libraries,
131+
define_macros=extra_define_macros + device_define_macros,
132+
libraries=["nanoarrow_python_shared"] + device_libraries if link_device else [],
129133
)
130134

131135

132136
setup(
133137
ext_modules=[
134138
nanoarrow_extension("nanoarrow._types"),
135-
nanoarrow_extension("nanoarrow._utils", nanoarrow_c=True),
136-
nanoarrow_extension(
137-
"nanoarrow._device", nanoarrow_c=True, nanoarrow_device=True
138-
),
139-
nanoarrow_extension(
140-
"nanoarrow._array", nanoarrow_c=True, nanoarrow_device=True
141-
),
142-
nanoarrow_extension("nanoarrow._array_stream", nanoarrow_c=True),
143-
nanoarrow_extension("nanoarrow._buffer", nanoarrow_c=True),
144-
nanoarrow_extension("nanoarrow._ipc_lib", nanoarrow_c=True, nanoarrow_ipc=True),
145-
nanoarrow_extension("nanoarrow._schema", nanoarrow_c=True),
139+
nanoarrow_extension("nanoarrow._utils"),
140+
nanoarrow_extension("nanoarrow._device", link_device=True),
141+
nanoarrow_extension("nanoarrow._array", link_device=True),
142+
nanoarrow_extension("nanoarrow._array_stream"),
143+
nanoarrow_extension("nanoarrow._buffer"),
144+
nanoarrow_extension("nanoarrow._ipc_lib"),
145+
nanoarrow_extension("nanoarrow._schema"),
146146
],
147147
version=version,
148+
libraries=common_libraries,
148149
)

0 commit comments

Comments
 (0)