Skip to content

Commit 9b193fa

Browse files
committed
Python: Add checks after building the wheels (#8532)
* Python: Add checks after building the wheels * Improvements
1 parent 76b6517 commit 9b193fa

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

build-module.py

+13-21
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626

2727
def build_cython_extensions() -> None:
28-
import Cython.Compiler.Options # pyright: ignore [reportMissingImports]
29-
from Cython.Build import build_ext, cythonize # pyright: ignore [reportMissingImports]
28+
import Cython.Compiler.Options
29+
from Cython.Build import build_ext, cythonize
3030
from setuptools import Extension
3131
from setuptools.dist import Distribution
3232

@@ -40,28 +40,20 @@ def build_cython_extensions() -> None:
4040
extra_compile_args = [
4141
"-O3",
4242
]
43-
# Relative to project root directory
44-
include_dirs = {
45-
"pyiceberg/",
46-
}
4743

48-
extensions = [
49-
Extension(
50-
# Your .pyx file will be available to cpython at this location.
51-
"pyiceberg.avro.decoder_fast",
52-
[
53-
"pyiceberg/avro/decoder_fast.pyx",
54-
],
55-
include_dirs=list(include_dirs),
56-
extra_compile_args=extra_compile_args,
57-
language="c",
58-
),
59-
]
44+
package_path = "pyiceberg"
6045

61-
for extension in extensions:
62-
include_dirs.update(extension.include_dirs)
46+
extension = Extension(
47+
# Your .pyx file will be available to cpython at this location.
48+
name="pyiceberg.avro.decoder_fast",
49+
sources=[
50+
os.path.join(package_path, "avro", "decoder_fast.pyx"),
51+
],
52+
extra_compile_args=extra_compile_args,
53+
language="c",
54+
)
6355

64-
ext_modules = cythonize(extensions, include_path=list(include_dirs), language_level=3, annotate=True)
56+
ext_modules = cythonize([extension], include_path=list(package_path), language_level=3, annotate=True)
6557
dist = Distribution({"ext_modules": ext_modules})
6658
cmd = build_ext(dist)
6759
cmd.ensure_finalized()

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ packages = [
4141
]
4242
include = [
4343
{ path = "dev", format = "sdist" },
44-
{ path = "pyiceberg/**/*.so", format = "wheel" }
44+
{ path = "pyiceberg/**/*.so", format = "wheel" },
45+
{ path = "pyiceberg/**/*.pyd", format = "wheel" },
4546
]
4647

4748
[tool.poetry.dependencies]

tests/conftest.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from random import choice
3333
from tempfile import TemporaryDirectory
3434
from typing import (
35+
TYPE_CHECKING,
3536
Any,
3637
Callable,
3738
Dict,
@@ -50,10 +51,8 @@
5051
import boto3
5152
import botocore.awsrequest
5253
import botocore.model
53-
import pyarrow as pa
5454
import pytest
5555
from moto import mock_dynamodb, mock_glue, mock_s3
56-
from pyarrow import parquet as pq
5756

5857
from pyiceberg import schema
5958
from pyiceberg.catalog import Catalog
@@ -69,7 +68,6 @@
6968
load_file_io,
7069
)
7170
from pyiceberg.io.fsspec import FsspecFileIO
72-
from pyiceberg.io.pyarrow import PyArrowFile, PyArrowFileIO
7371
from pyiceberg.manifest import DataFile, FileFormat
7472
from pyiceberg.schema import Schema
7573
from pyiceberg.serializers import ToOutputFile
@@ -91,6 +89,9 @@
9189
)
9290
from pyiceberg.utils.datetime import datetime_to_millis
9391

92+
if TYPE_CHECKING:
93+
from pyiceberg.io.pyarrow import PyArrowFile, PyArrowFileIO
94+
9495

9596
def pytest_collection_modifyitems(items: List[pytest.Item]) -> None:
9697
for item in items:
@@ -421,6 +422,8 @@ def example_table_metadata_v2() -> Dict[str, Any]:
421422

422423
@pytest.fixture(scope="session")
423424
def metadata_location(tmp_path_factory: pytest.TempPathFactory) -> str:
425+
from pyiceberg.io.pyarrow import PyArrowFileIO
426+
424427
metadata_location = str(tmp_path_factory.mktemp("metadata") / f"{uuid.uuid4()}.metadata.json")
425428
metadata = TableMetadataV2(**EXAMPLE_TABLE_METADATA_V2)
426429
ToOutputFile.table_metadata(metadata, PyArrowFileIO().new_output(location=metadata_location), overwrite=True)
@@ -429,6 +432,8 @@ def metadata_location(tmp_path_factory: pytest.TempPathFactory) -> str:
429432

430433
@pytest.fixture(scope="session")
431434
def metadata_location_gz(tmp_path_factory: pytest.TempPathFactory) -> str:
435+
from pyiceberg.io.pyarrow import PyArrowFileIO
436+
432437
metadata_location = str(tmp_path_factory.mktemp("metadata") / f"{uuid.uuid4()}.gz.metadata.json")
433438
metadata = TableMetadataV2(**EXAMPLE_TABLE_METADATA_V2)
434439
ToOutputFile.table_metadata(metadata, PyArrowFileIO().new_output(location=metadata_location), overwrite=True)
@@ -1146,7 +1151,9 @@ def __len__(self) -> int:
11461151
def exists(self) -> bool:
11471152
return os.path.exists(self._path)
11481153

1149-
def to_input_file(self) -> PyArrowFile:
1154+
def to_input_file(self) -> "PyArrowFile":
1155+
from pyiceberg.io.pyarrow import PyArrowFileIO
1156+
11501157
return PyArrowFileIO().new_input(location=self.location)
11511158

11521159
def create(self, overwrite: bool = False) -> OutputStream:
@@ -1399,7 +1406,9 @@ def fsspec_fileio_gcs(request: pytest.FixtureRequest) -> FsspecFileIO:
13991406

14001407

14011408
@pytest.fixture
1402-
def pyarrow_fileio_gcs(request: pytest.FixtureRequest) -> PyArrowFileIO:
1409+
def pyarrow_fileio_gcs(request: pytest.FixtureRequest) -> "PyArrowFileIO":
1410+
from pyiceberg.io.pyarrow import PyArrowFileIO
1411+
14031412
properties = {
14041413
GCS_ENDPOINT: request.config.getoption("--gcs.endpoint"),
14051414
GCS_TOKEN: request.config.getoption("--gcs.oauth2.token"),
@@ -1620,6 +1629,9 @@ def clean_up(test_catalog: Catalog) -> None:
16201629

16211630
@pytest.fixture
16221631
def data_file(table_schema_simple: Schema, tmp_path: str) -> str:
1632+
import pyarrow as pa
1633+
from pyarrow import parquet as pq
1634+
16231635
table = pa.table(
16241636
{"foo": ["a", "b", "c"], "bar": [1, 2, 3], "baz": [True, False, None]},
16251637
metadata={"iceberg.schema": table_schema_simple.model_dump_json()},

0 commit comments

Comments
 (0)