This is an automated email from the ASF dual-hosted git repository.

willayd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new f8a67600 python: Use meson-python instead of setuptools (#644)
f8a67600 is described below

commit f8a676009914fa7572800af342e18f003155bec6
Author: William Ayd <[email protected]>
AuthorDate: Tue Oct 29 17:16:30 2024 -0400

    python: Use meson-python instead of setuptools (#644)
---
 .github/workflows/build-and-test-device.yaml       |   3 +-
 .github/workflows/python-wheels.yaml               |  37 ++++-
 .gitignore                                         |   3 +
 dev/release/rat_exclude_files.txt                  |   1 +
 dev/release/source_build.sh                        |   2 +-
 meson.build                                        |   6 +-
 python/.gitignore                                  |   1 -
 python/bootstrap.py                                |  57 +++-----
 python/generate_dist.py                            |  59 ++++++++
 python/{tests/test_version.py => meson.build}      |  30 +++--
 python/pyproject.toml                              |  12 +-
 python/setup.py                                    | 149 ---------------------
 python/src/nanoarrow/_ipc_lib.pyx                  |   2 +-
 python/src/nanoarrow/_version.py                   |   4 +-
 python/src/nanoarrow/meson.build                   | 117 ++++++++++++++++
 python/subprojects/arrow-nanoarrow                 |   1 +
 .../test_version.py => subprojects/flatcc.wrap}    |  20 ++-
 .../packagefiles/flatcc/meson.build}               |  30 +++--
 python/tests/test_version.py                       |   5 +
 19 files changed, 307 insertions(+), 232 deletions(-)

diff --git a/.github/workflows/build-and-test-device.yaml 
b/.github/workflows/build-and-test-device.yaml
index 5a7cb8a1..10ecaf70 100644
--- a/.github/workflows/build-and-test-device.yaml
+++ b/.github/workflows/build-and-test-device.yaml
@@ -28,7 +28,8 @@ on:
       - 'CMakeLists.txt'
       - '.github/workflows/build-and-test-device.yaml'
       - 'src/nanoarrow/**'
-      - 'python/setup.py'
+      - 'python/meson.build'
+      - 'python/src/nanoarrow/meson.build'
 
 permissions:
   contents: read
diff --git a/.github/workflows/python-wheels.yaml 
b/.github/workflows/python-wheels.yaml
index 5c3ff6a6..dfa244a9 100644
--- a/.github/workflows/python-wheels.yaml
+++ b/.github/workflows/python-wheels.yaml
@@ -24,9 +24,11 @@ on:
       - main
     paths:
       - '.github/workflows/python-wheels.yaml'
-      - 'python/setup.py'
+      - 'python/meson.build'
+      - 'python/src/nanoarrow/meson.build'
       - 'python/pyproject.toml'
       - 'python/bootstrap.py'
+      - 'python/generate_dist.py'
       - 'python/MANIFEST.in'
   push:
     branches:
@@ -93,12 +95,13 @@ jobs:
     strategy:
       matrix:
         config:
-          - {os: "ubuntu-20.04", label: "pyodide", platform: "pyodide"}
-          - {os: "ubuntu-20.04", label: "linux", platform: "auto"}
-          - {os: "windows-2019", label: "windows", platform: "auto"}
-          - {os: "macOS-13", label: "macOS", platform: "auto"}
-          - {os: "macOS-14", label: "macOS-arm64", platform: "auto"}
-          - {os: ["self-hosted", "arm"], label: "linux-arm64", platform: 
"auto"}
+          - {os: "ubuntu-20.04", label: "pyodide", platform: "pyodide", arch: 
"auto"}
+          - {os: "ubuntu-20.04", label: "linux", platform: "auto", arch: 
"auto"}
+          - {os: "windows-2019", label: "windows-x86", platform: "auto", arch: 
"x86"}
+          - {os: "windows-2019", label: "windows-amd64", platform: "auto", 
arch: "AMD64"}
+          - {os: "macOS-13", label: "macOS", platform: "auto", arch: "auto"}
+          - {os: "macOS-14", label: "macOS-arm64", platform: "auto", arch: 
"auto"}
+          - {os: ["self-hosted", "arm"], label: "linux-arm64", platform: 
"auto", arch: "auto"}
 
     steps:
       - uses: actions/checkout@v4
@@ -107,9 +110,28 @@ jobs:
           fetch-tags: true
 
       - uses: actions/setup-python@v5
+        if: matrix.config.arch != 'x86'
         with:
           python-version: "3.12"
 
+      - name: Setup MSVC (64-bit)
+        if: matrix.config.arch == 'AMD64'
+        uses: ilammy/msvc-dev-cmd@v1
+        with:
+          arch: x64
+
+      - uses: actions/setup-python@v5
+        if: matrix.config.arch == 'x86'
+        with:
+          python-version: "3.12"
+          architecture: x86
+
+      - name: Setup MSVC (32-bit)
+        if: matrix.config.arch == 'x86'
+        uses: ilammy/msvc-dev-cmd@v1
+        with:
+          arch: x86
+
       - name: Install cibuildwheel
         run: python -m pip install cibuildwheel==2.21.1
 
@@ -125,6 +147,7 @@ jobs:
           CIBW_TEST_REQUIRES: pytest
           CIBW_TEST_COMMAND: pytest {package}/tests -vv
           CIBW_PLATFORM: ${{ matrix.config.platform }}
+          CIBW_ARCHS: ${{ matrix.config.arch }}
 
       - uses: actions/upload-artifact@v4
         with:
diff --git a/.gitignore b/.gitignore
index 89fb9fe2..1196540f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,5 +33,8 @@ __pycache__
 subprojects/*
 !subprojects/packagefiles
 !subprojects/*.wrap
+python/subprojects/*
+!python/subprojects/packagefiles
+!python/subprojects/*.wrap
 
 compile_commands.json
diff --git a/dev/release/rat_exclude_files.txt 
b/dev/release/rat_exclude_files.txt
index cb0a8340..81986664 100644
--- a/dev/release/rat_exclude_files.txt
+++ b/dev/release/rat_exclude_files.txt
@@ -15,3 +15,4 @@ dist/flatcc.c
 src/nanoarrow/ipc/flatcc_generated.h
 thirdparty/*
 python/src/nanoarrow/dlpack_abi.h
+python/subprojects/arrow-nanoarrow
diff --git a/dev/release/source_build.sh b/dev/release/source_build.sh
index e9fa5697..92d182a5 100755
--- a/dev/release/source_build.sh
+++ b/dev/release/source_build.sh
@@ -43,7 +43,7 @@ main() {
     # Resolve all hard and symbolic links
     rm -rf "${base_name}.tmp/"
     mv "${base_name}/" "${base_name}.tmp/"
-    cp -R -L "${base_name}.tmp" "${base_name}"
+    cp -R -d "${base_name}.tmp" "${base_name}"
     rm -rf "${base_name}.tmp/"
 
     # Create new tarball
diff --git a/meson.build b/meson.build
index ba68167a..144319c7 100644
--- a/meson.build
+++ b/meson.build
@@ -103,7 +103,7 @@ if get_option('ipc')
     )
     nanoarrow_ipc_dep = declare_dependency(include_directories: [incdir],
                                            link_with: nanoarrow_ipc_lib,
-                                           dependencies: [nanoarrow_dep, 
flatcc_dep])
+                                           dependencies: [nanoarrow_dep])
 endif
 
 needs_device = get_option('device') or get_option('metal') or 
get_option('cuda')
@@ -137,6 +137,10 @@ if needs_device
       install: true,
       cpp_args: device_defines,
   )
+
+  nanoarrow_device_dep = declare_dependency(include_directories: [incdir],
+                                            link_with: nanoarrow_device_lib,
+                                            dependencies: device_deps)
 endif
 
 needs_testing = get_option('testing') or get_option('tests')
diff --git a/python/.gitignore b/python/.gitignore
index 49cfce5e..5df1a2b9 100644
--- a/python/.gitignore
+++ b/python/.gitignore
@@ -16,7 +16,6 @@
 # specific language governing permissions and limitations
 # under the License.
 
-vendor/
 src/nanoarrow/_*.c
 
 # Byte-compiled / optimized / DLL files
diff --git a/python/bootstrap.py b/python/bootstrap.py
index 7745013d..19729e07 100644
--- a/python/bootstrap.py
+++ b/python/bootstrap.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import argparse
 import pathlib
 import re
 import subprocess
@@ -222,15 +223,7 @@ class NanoarrowDevicePxdGenerator(PxdGenerator):
         output.write(b"\n")
 
 
-# Runs cmake -DNANOARROW_BUNDLE=ON if cmake exists or copies nanoarrow.c/h
-# from ../dist if it does not. Running cmake is safer because it will sync
-# any changes from nanoarrow C library sources in the checkout but is not
-# strictly necessary for things like installing from GitHub.
-def copy_or_generate_nanoarrow_c():
-    this_dir = pathlib.Path(__file__).parent.resolve()
-    source_dir = this_dir.parent
-    vendor_dir = this_dir / "vendor"
-
+def copy_or_generate_nanoarrow_c(target_dir: pathlib.Path):
     vendored_files = [
         "nanoarrow.h",
         "nanoarrow.c",
@@ -239,37 +232,25 @@ def copy_or_generate_nanoarrow_c():
         "nanoarrow_device.h",
         "nanoarrow_device.c",
     ]
-    dst = {name: vendor_dir / name for name in vendored_files}
-
-    for f in dst.values():
-        f.unlink(missing_ok=True)
+    dst = {name: target_dir / name for name in vendored_files}
 
-    is_cmake_dir = (source_dir / "CMakeLists.txt").exists()
-    is_in_nanoarrow_repo = (
-        is_cmake_dir and (source_dir / "src" / "nanoarrow" / 
"nanoarrow.h").exists()
-    )
-
-    if not is_in_nanoarrow_repo:
-        raise ValueError(
-            "Attempt to build source distribution outside the nanoarrow repo"
-        )
+    this_dir = pathlib.Path(__file__).parent.resolve()
+    arrow_proj_dir = this_dir / "subprojects" / "arrow-nanoarrow"
 
-    vendor_dir.mkdir(exist_ok=True)
     subprocess.run(
         [
             sys.executable,
-            source_dir / "ci" / "scripts" / "bundle.py",
+            arrow_proj_dir / "ci" / "scripts" / "bundle.py",
             "--symbol-namespace",
             "PythonPkg",
             "--header-namespace",
             "",
             "--source-output-dir",
-            vendor_dir,
+            target_dir,
             "--include-output-dir",
-            vendor_dir,
+            target_dir,
             "--with-device",
             "--with-ipc",
-            "--with-flatcc",
         ],
     )
 
@@ -278,18 +259,24 @@ def copy_or_generate_nanoarrow_c():
 
 
 # Runs the pxd generator with some information about the file name
-def generate_nanoarrow_pxds():
-    this_dir = pathlib.Path(__file__).parent.resolve()
-
+def generate_nanoarrow_pxds(target_dir: pathlib.Path):
     NanoarrowPxdGenerator().generate_pxd(
-        this_dir / "vendor" / "nanoarrow.h", this_dir / "vendor" / 
"nanoarrow_c.pxd"
+        target_dir / "nanoarrow.h", target_dir / "nanoarrow_c.pxd"
     )
     NanoarrowDevicePxdGenerator().generate_pxd(
-        this_dir / "vendor" / "nanoarrow_device.h",
-        this_dir / "vendor" / "nanoarrow_device_c.pxd",
+        target_dir / "nanoarrow_device.h",
+        target_dir / "nanoarrow_device_c.pxd",
     )
 
 
 if __name__ == "__main__":
-    copy_or_generate_nanoarrow_c()
-    generate_nanoarrow_pxds()
+    parser = argparse.ArgumentParser()
+    parser.add_argument(
+        "--output-dir", help="Target directory where files should be written"
+    )
+
+    args = parser.parse_args()
+    target_dir = pathlib.Path(args.output_dir).resolve()
+
+    copy_or_generate_nanoarrow_c(target_dir)
+    generate_nanoarrow_pxds(target_dir)
diff --git a/python/generate_dist.py b/python/generate_dist.py
new file mode 100644
index 00000000..abf4104b
--- /dev/null
+++ b/python/generate_dist.py
@@ -0,0 +1,59 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import os
+import pathlib
+import shutil
+
+
+def main():
+    src_dir = pathlib.Path(os.environ["MESON_SOURCE_ROOT"]).parent.resolve()
+    dist_dir = pathlib.Path(os.environ["MESON_DIST_ROOT"]).resolve()
+    subproj_dir = dist_dir / "subprojects" / "arrow-nanoarrow"
+
+    if subproj_dir.is_symlink():
+        subproj_dir.unlink()
+
+    subproj_dir.mkdir(parents=True)
+    shutil.copy(src_dir / "meson.build", subproj_dir / "meson.build")
+    shutil.copy(src_dir / "meson.options", subproj_dir / "meson.options")
+
+    # Copy over any subproject dependency / wrap files
+    subproj_subproj_dir = subproj_dir / "subprojects"
+    subproj_subproj_dir.mkdir()
+    for f in (src_dir / "subprojects").glob("*.wrap"):
+        shutil.copy(f, subproj_subproj_dir / f.name)
+    shutil.copytree(
+        src_dir / "subprojects" / "packagefiles", subproj_subproj_dir / 
"packagefiles"
+    )
+
+    target_src_dir = subproj_dir / "src"
+    shutil.copytree(src_dir / "src", target_src_dir)
+
+    # CMake isn't actually required for building, but the bundle.py script 
reads from
+    # its configuration
+    shutil.copy(src_dir / "CMakeLists.txt", subproj_dir / "CMakeLists.txt")
+
+    subproj_ci_scripts_dir = subproj_dir / "ci" / "scripts"
+    subproj_ci_scripts_dir.mkdir(parents=True)
+    shutil.copy(
+        src_dir / "ci" / "scripts" / "bundle.py", subproj_ci_scripts_dir / 
"bundle.py"
+    )
+
+
+if __name__ == "__main__":
+    main()
diff --git a/python/tests/test_version.py b/python/meson.build
similarity index 53%
copy from python/tests/test_version.py
copy to python/meson.build
index 8de6e2c1..3d1f9d39 100644
--- a/python/tests/test_version.py
+++ b/python/meson.build
@@ -15,16 +15,24 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import re
+project(
+    'nanoarrow',
+    'c', 'cython',
+    version: run_command(['src/nanoarrow/_version.py', '--print'], check: 
true).stdout().strip(),
+    license: 'Apache-2.0',
+    meson_version: '>=1.2.0',
+    default_options: [
+        'warning_level=2',
+        'c_std=c99',
+        'default_library=static',
+        # We need to set these options at the project default_option level
+        # due to https://github.com/mesonbuild/meson/issues/6728
+        'arrow-nanoarrow:ipc=true',
+        'arrow-nanoarrow:device=true',
+        'arrow-nanoarrow:namespace=PythonPkg',
+    ],
+)
 
-import nanoarrow as na
+subdir('src/nanoarrow')
 
-
-def test_version():
-    re_py_version = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+(\.dev[0-9]+)?$")
-    assert re_py_version.match(na.__version__) is not None
-
-
-def test_c_version():
-    re_version = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?$")
-    assert re_version.match(na.c_version()) is not None
+meson.add_dist_script('python', meson.current_source_dir() / 
'generate_dist.py')
diff --git a/python/pyproject.toml b/python/pyproject.toml
index 2be6aebb..acb0398d 100644
--- a/python/pyproject.toml
+++ b/python/pyproject.toml
@@ -38,7 +38,15 @@ Changelog = 
"https://github.com/apache/arrow-nanoarrow/blob/main/CHANGELOG.md";
 
 [build-system]
 requires = [
-    "setuptools >= 61.0.0",
+    "meson>=1.3.0",
+    "meson-python",
     "Cython"
 ]
-build-backend = "setuptools.build_meta"
+build-backend = "mesonpy"
+
+[tool.meson-python.args]
+install = ['--skip-subprojects']
+dist = ['--include-subprojects']
+
+[tool.pytest.ini_options]
+norecursedirs = "subprojects/arrow-nanoarrow"
diff --git a/python/setup.py b/python/setup.py
deleted file mode 100644
index a2335ecc..00000000
--- a/python/setup.py
+++ /dev/null
@@ -1,149 +0,0 @@
-#!/usr/bin/env python
-
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-import os
-import subprocess
-import sys
-from pathlib import Path
-
-from setuptools import Extension, setup
-
-
-# https://github.com/jbweston/miniver
-def get_version(pkg_path):
-    """
-    Load version.py module without importing the whole package.
-
-    Template code from miniver.
-    """
-    from importlib.util import module_from_spec, spec_from_file_location
-
-    spec = spec_from_file_location("version", os.path.join(pkg_path, 
"_version.py"))
-    module = module_from_spec(spec)
-    spec.loader.exec_module(module)
-    return module.__version__
-
-
-version = get_version("src/nanoarrow")
-
-
-# Run bootstrap.py to run cmake generating a fresh bundle based on this
-# checkout or copy from ../dist if the caller doesn't have cmake available.
-# Note that bootstrap.py won't exist if building from sdist.
-this_dir = os.path.dirname(__file__)
-bootstrap_py = os.path.join(this_dir, "bootstrap.py")
-if os.path.exists(bootstrap_py):
-    subprocess.run([sys.executable, bootstrap_py])
-
-
-# Set some extra flags for compiling with coverage support
-extra_compile_args = []
-extra_link_args = []
-extra_define_macros = []
-device_include_dirs = []
-device_library_dirs = []
-device_libraries = []
-device_define_macros = []
-
-if os.getenv("NANOARROW_PYTHON_COVERAGE") == "1":
-    extra_compile_args.append("--coverage")
-    extra_link_args.append("--coverage")
-    extra_define_macros.append(("CYTHON_TRACE", 1))
-
-if os.getenv("NANOARROW_DEBUG_EXTENSION") == "1":
-    extra_compile_args.extend(["-g", "-O0"])
-
-cuda_toolkit_root = os.getenv("NANOARROW_PYTHON_CUDA_HOME")
-if cuda_toolkit_root:
-    cuda_lib = "cuda.lib" if os.name == "nt" else "libcuda.so"
-    include_dir = Path(cuda_toolkit_root) / "include"
-    possible_libs = [
-        Path(cuda_toolkit_root) / "lib" / cuda_lib,
-        Path(cuda_toolkit_root) / "lib64" / cuda_lib,
-        Path(cuda_toolkit_root) / "lib" / "x64" / cuda_lib,
-        Path("/usr/lib/wsl/lib") / cuda_lib,
-    ]
-
-    if not include_dir.is_dir():
-        raise ValueError(f"CUDA include directory does not exist: 
'{include_dir}'")
-
-    device_include_dirs.append(str(include_dir))
-    device_libraries.append("cuda")
-    extra_define_macros.append(("NANOARROW_DEVICE_WITH_CUDA", 1))
-
-    # Library might be already in a system library directory such that no -L 
flag
-    # is needed
-    lib_dirs = [d for d in possible_libs if d.exists()]
-    if lib_dirs:
-        device_library_dirs.append(str(lib_dirs[0].parent))
-
-
-# This mechanism to build a static c library against which extensions
-# can be linked is not well documented but is a better solution than
-# simply including these files as sources to the extensions that need
-# them. A more robust solution would be to use Meson or CMake to build
-# the Python extensions since they can both build a shared nanoarrow
-# and link it. This mechanism is the build_clib command available in
-# setuptools (and previously from distutils).
-common_libraries = [
-    [
-        "nanoarrow_python_shared",
-        {
-            "sources": [
-                "vendor/nanoarrow.c",
-                "vendor/nanoarrow_device.c",
-                "vendor/nanoarrow_ipc.c",
-                "vendor/flatcc.c",
-            ],
-            "include_dirs": ["vendor"] + device_include_dirs,
-            "libraries": device_libraries,
-            "library_dirs": device_library_dirs,
-            "macros": extra_define_macros + device_define_macros,
-        },
-    ]
-]
-
-
-def nanoarrow_extension(name, *, link_device=False):
-    return Extension(
-        name=name,
-        include_dirs=["vendor", "src/nanoarrow"],
-        language="c",
-        sources=["src/" + name.replace(".", "/") + ".pyx"],
-        extra_compile_args=extra_compile_args,
-        extra_link_args=extra_link_args,
-        define_macros=extra_define_macros + device_define_macros,
-        libraries=["nanoarrow_python_shared"] + device_libraries if 
link_device else [],
-    )
-
-
-setup(
-    ext_modules=[
-        nanoarrow_extension("nanoarrow._types"),
-        nanoarrow_extension("nanoarrow._utils"),
-        nanoarrow_extension("nanoarrow._device", link_device=True),
-        nanoarrow_extension("nanoarrow._array", link_device=True),
-        nanoarrow_extension("nanoarrow._array_stream"),
-        nanoarrow_extension("nanoarrow._buffer"),
-        nanoarrow_extension("nanoarrow._ipc_lib"),
-        nanoarrow_extension("nanoarrow._schema"),
-    ],
-    version=version,
-    libraries=common_libraries,
-)
diff --git a/python/src/nanoarrow/_ipc_lib.pyx 
b/python/src/nanoarrow/_ipc_lib.pyx
index fcb6530a..163644d9 100644
--- a/python/src/nanoarrow/_ipc_lib.pyx
+++ b/python/src/nanoarrow/_ipc_lib.pyx
@@ -38,7 +38,7 @@ from nanoarrow._array cimport CArrayView
 from nanoarrow._utils cimport Error
 
 
-cdef extern from "nanoarrow_ipc.h" nogil:
+cdef extern from "nanoarrow/nanoarrow_ipc.h" nogil:
     struct ArrowIpcInputStream:
         ArrowErrorCode (*read)(ArrowIpcInputStream* stream, uint8_t* buf,
                                int64_t buf_size_bytes, int64_t* size_read_out,
diff --git a/python/src/nanoarrow/_version.py b/python/src/nanoarrow/_version.py
index 750dbb5b..fff94035 100644
--- a/python/src/nanoarrow/_version.py
+++ b/python/src/nanoarrow/_version.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -47,4 +49,4 @@ def get_static_version_info(version_file=STATIC_VERSION_FILE):
 __version__ = get_version()
 
 if __name__ == "__main__":
-    print("Version: ", get_version())
+    print(get_version())
diff --git a/python/src/nanoarrow/meson.build b/python/src/nanoarrow/meson.build
new file mode 100644
index 00000000..452cf37a
--- /dev/null
+++ b/python/src/nanoarrow/meson.build
@@ -0,0 +1,117 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+flatcc_dep = dependency('flatcc')
+nanoarrow_proj = subproject('arrow-nanoarrow')
+nanoarrow_dep = nanoarrow_proj.get_variable('nanoarrow_dep')
+nanoarrow_ipc_dep = nanoarrow_proj.get_variable('nanoarrow_ipc_dep')
+nanoarrow_device_dep = nanoarrow_proj.get_variable('nanoarrow_device_dep')
+
+py = import('python').find_installation(pure: false)
+
+vendored_files = custom_target(
+    'generate-pyx',
+    output: [
+        'nanoarrow.c',
+        'nanoarrow_c.pxd',
+        'nanoarrow_device.c',
+        'nanoarrow_device_c.pxd',
+        'nanoarrow_device.h',
+        'nanoarrow_device.hpp',
+        'nanoarrow.h',
+        'nanoarrow.hpp',
+        'nanoarrow_ipc.c',
+        'nanoarrow_ipc.h',
+        'nanoarrow_ipc.hpp',
+    ],
+    command: [
+        py,
+        meson.current_source_dir() + '/../../bootstrap.py',
+        '--output-dir', meson.current_build_dir()
+    ],
+)
+
+nanoarrow_pyx_dep = declare_dependency(
+    sources: vendored_files[1],
+)
+
+cyfiles = [
+    '_array.pyx',
+    '_array_stream.pyx',
+    '_buffer.pyx',
+    '_device.pyx',
+    '_ipc_lib.pyx',
+    '_schema.pyx',
+    '_types.pyx',
+    '_utils.pyx',
+]
+
+cython_args = [
+    '--include-dir',
+    meson.current_source_dir(),
+    '--include-dir',
+    meson.current_build_dir(),
+]
+if get_option('buildtype') in ['debug', 'debugoptimized']
+    cython_args += ['--gdb']
+endif
+
+fs = import('fs')
+foreach cyf : cyfiles
+  cyfile_deps = [nanoarrow_pyx_dep, nanoarrow_dep]
+
+  stem = fs.stem(cyf)
+  if stem in ['_array', '_device']
+    cyfile_deps += [nanoarrow_device_dep]
+  elif stem == '_ipc_lib'
+    cyfile_deps += [nanoarrow_ipc_dep, flatcc_dep]
+  endif
+
+  py.extension_module(
+      stem,
+      sources: [cyf],
+      cython_args: cython_args,
+      dependencies: cyfile_deps,
+      subdir: 'nanoarrow',
+      install: true,
+  )
+endforeach
+
+py_sources = [
+    '__init__.py',
+    '_static_version.py',
+    '_version.py',
+    'array.py',
+    'array_stream.py',
+    'c_array.py',
+    'c_array_stream.py',
+    'c_buffer.py',
+    'c_schema.py',
+    'device.py',
+    'ipc.py',
+    'iterator.py',
+    '_repr_utils.py',
+    'schema.py',
+    'visitor.py',
+]
+
+foreach source: py_sources
+    py.install_sources(
+        source,
+        subdir: 'nanoarrow'
+    )
+endforeach
diff --git a/python/subprojects/arrow-nanoarrow 
b/python/subprojects/arrow-nanoarrow
new file mode 120000
index 00000000..c25bddb6
--- /dev/null
+++ b/python/subprojects/arrow-nanoarrow
@@ -0,0 +1 @@
+../..
\ No newline at end of file
diff --git a/python/tests/test_version.py b/python/subprojects/flatcc.wrap
similarity index 67%
copy from python/tests/test_version.py
copy to python/subprojects/flatcc.wrap
index 8de6e2c1..fdabe179 100644
--- a/python/tests/test_version.py
+++ b/python/subprojects/flatcc.wrap
@@ -15,16 +15,12 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import re
+[wrap-file]
+directory = flatcc-fd3c4ae5cd39f0651eda6a3a1a374278070135d6
+source_url = 
https://github.com/dvidelabs/flatcc/archive/fd3c4ae5cd39f0651eda6a3a1a374278070135d6.tar.gz
+source_filename = flatcc-fd3c4ae5cd39f0651eda6a3a1a374278070135d6.tar.gz
+source_hash = 353cb04a619865383b87c8077eb39b63b01a3fc44f7bebd558a88f139c6b6f77
+patch_directory = flatcc
 
-import nanoarrow as na
-
-
-def test_version():
-    re_py_version = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+(\.dev[0-9]+)?$")
-    assert re_py_version.match(na.__version__) is not None
-
-
-def test_c_version():
-    re_version = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?$")
-    assert re_version.match(na.c_version()) is not None
+[provide]
+flatcc = flatcc_dep
diff --git a/python/tests/test_version.py 
b/python/subprojects/packagefiles/flatcc/meson.build
similarity index 64%
copy from python/tests/test_version.py
copy to python/subprojects/packagefiles/flatcc/meson.build
index 8de6e2c1..9e12be21 100644
--- a/python/tests/test_version.py
+++ b/python/subprojects/packagefiles/flatcc/meson.build
@@ -15,16 +15,26 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import re
+project('flatcc',
+  'c',
+  version : '0.6.1',
+  license : 'Apache-2.0',
+)
 
-import nanoarrow as na
+incdir = include_directories('include')
 
+flatcc_lib = library(
+    'flatcc',
+    sources: [
+        'src/runtime/builder.c',
+        'src/runtime/emitter.c',
+        'src/runtime/verifier.c',
+        'src/runtime/refmap.c',
+    ],
+    include_directories: [incdir],
+)
 
-def test_version():
-    re_py_version = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+(\.dev[0-9]+)?$")
-    assert re_py_version.match(na.__version__) is not None
-
-
-def test_c_version():
-    re_version = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?$")
-    assert re_version.match(na.c_version()) is not None
+flatcc_dep = declare_dependency(
+    include_directories: [incdir],
+    link_with: [flatcc_lib],
+)
diff --git a/python/tests/test_version.py b/python/tests/test_version.py
index 8de6e2c1..9783e15f 100644
--- a/python/tests/test_version.py
+++ b/python/tests/test_version.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import importlib
 import re
 
 import nanoarrow as na
@@ -28,3 +29,7 @@ def test_version():
 def test_c_version():
     re_version = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?$")
     assert re_version.match(na.c_version()) is not None
+
+
+def test_metadata_version():
+    assert importlib.metadata.version("nanoarrow") == na.__version__

Reply via email to