Skip to content

Commit 8de1826

Browse files
authored
infra: improve python binding setup (#2178)
## Which issue does this PR close? - Closes #. ## What changes are included in this PR? While reviewing #1997, i noticed a couple of improvements we can make 1. `make install` should install the local editable `pyiceberg-core` so that i can do `make install && make test` 2. CI should fail on warnings 3. test should not read local env files (we made a similar fix in pyiceberg apache/iceberg-python#3006). Otherwise, tests were reading `~/.pyiceberg.yaml` and polluting the runs ## Are these changes tested? Yes. For (2), see that [it fails in CI](https://github.com/apache/iceberg-rust/actions/runs/22410058261/job/64880767855?pr=2178) before removing the use of deprecated `register_table_provider`
1 parent 709a244 commit 8de1826

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

bindings/python/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
19-
install:
20-
uv sync --group dev --no-install-project
18+
.PHONY: build install test
2119

2220
build:
2321
uv run maturin develop
2422

23+
# uv sync may remove local editable pyiceberg-core, so install rebuilds it afterwards.
24+
install:
25+
uv sync --group dev --no-install-project
26+
$(MAKE) build
27+
2528
test:
2629
uv run --no-sync pytest

bindings/python/pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ include = [
5151
[tool.ruff.lint]
5252
ignore = ["F403", "F405"]
5353

54+
[tool.pytest.ini_options]
55+
filterwarnings = [
56+
"error",
57+
]
58+
5459
[dependency-groups]
5560
dev = [
5661
"maturin>=1.0,<2.0",

bindings/python/tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import pytest
2727
from pydantic_core import to_json
28+
from pyiceberg.utils.config import Config
2829

2930
from pyiceberg.partitioning import PartitionField, PartitionSpec
3031
from pyiceberg.schema import Schema
@@ -36,6 +37,20 @@
3637
)
3738

3839

40+
@pytest.fixture(scope="session", autouse=True)
41+
def isolate_pyiceberg_config() -> Generator[None, None, None]:
42+
monkeypatch = pytest.MonkeyPatch()
43+
with TemporaryDirectory() as empty_home_dir:
44+
monkeypatch.setenv("HOME", empty_home_dir)
45+
monkeypatch.setenv("PYICEBERG_HOME", empty_home_dir)
46+
47+
import pyiceberg.catalog as catalog
48+
49+
monkeypatch.setattr(catalog, "_ENV_CONFIG", Config())
50+
yield
51+
monkeypatch.undo()
52+
53+
3954
@pytest.fixture(scope="session")
4055
def avro_schema_manifest_entry() -> Dict[str, Any]:
4156
return {

bindings/python/tests/test_datafusion_table_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_register_iceberg_table_provider(
106106
)
107107

108108
ctx = SessionContext()
109-
ctx.register_table_provider("test", iceberg_table_provider)
109+
ctx.register_table("test", iceberg_table_provider)
110110

111111
datafusion_table = ctx.table("test")
112112
assert datafusion_table is not None
@@ -154,7 +154,7 @@ def __datafusion_table_provider__(self):
154154
)
155155

156156
ctx = SessionContext()
157-
ctx.register_table_provider("test", iceberg_table)
157+
ctx.register_table("test", iceberg_table)
158158

159159
datafusion_table = ctx.table("test")
160160
assert datafusion_table is not None

0 commit comments

Comments
 (0)