Skip to content

Commit c2529b9

Browse files
authored
Break circular import (#1639)
Sometime I'm seeing this: ``` ImportError while loading conftest '/home/runner/work/iceberg-python/iceberg-python/tests/conftest.py'. tests/conftest.py:52: in <module> from pyiceberg.catalog import Catalog, load_catalog pyiceberg/catalog/__init__.py:51: in <module> from pyiceberg.serializers import ToOutputFile pyiceberg/serializers.py:25: in <module> from pyiceberg.table.metadata import TableMetadata, TableMetadataUtil pyiceberg/table/__init__.py:65: in <module> from pyiceberg.io.pyarrow import ArrowScan, schema_to_pyarrow pyiceberg/io/pyarrow.py:141: in <module> from pyiceberg.table.locations import load_location_provider pyiceberg/table/locations.py:25: in <module> from pyiceberg.table import TableProperties E ImportError: cannot import name 'TableProperties' from partially initialized module 'pyiceberg.table' (most likely due to a circular import) (/home/runner/work/iceberg-python/iceberg-python/pyiceberg/table/__init__.py) ``` Also observed in: #1388 I prefer the imports at the top, but I think this is a small price to pay to avoid having circular imports.
1 parent ec4e65f commit c2529b9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pyiceberg/table/locations.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import mmh3
2323

2424
from pyiceberg.partitioning import PartitionKey
25-
from pyiceberg.table import TableProperties
2625
from pyiceberg.typedef import Properties
2726
from pyiceberg.utils.properties import property_as_bool
2827

@@ -46,6 +45,8 @@ def __init__(self, table_location: str, table_properties: Properties):
4645
self.table_location = table_location
4746
self.table_properties = table_properties
4847

48+
from pyiceberg.table import TableProperties
49+
4950
if path := table_properties.get(TableProperties.WRITE_DATA_PATH):
5051
self.data_path = path.rstrip("/")
5152
else:
@@ -85,6 +86,8 @@ class ObjectStoreLocationProvider(LocationProvider):
8586

8687
def __init__(self, table_location: str, table_properties: Properties):
8788
super().__init__(table_location, table_properties)
89+
from pyiceberg.table import TableProperties
90+
8891
self._include_partition_paths = property_as_bool(
8992
self.table_properties,
9093
TableProperties.WRITE_OBJECT_STORE_PARTITIONED_PATHS,
@@ -131,6 +134,8 @@ def _import_location_provider(
131134
try:
132135
path_parts = location_provider_impl.split(".")
133136
if len(path_parts) < 2:
137+
from pyiceberg.table import TableProperties
138+
134139
raise ValueError(
135140
f"{TableProperties.WRITE_PY_LOCATION_PROVIDER_IMPL} should be full path (module.CustomLocationProvider), got: {location_provider_impl}"
136141
)
@@ -144,6 +149,8 @@ def _import_location_provider(
144149

145150

146151
def load_location_provider(table_location: str, table_properties: Properties) -> LocationProvider:
152+
from pyiceberg.table import TableProperties
153+
147154
table_location = table_location.rstrip("/")
148155

149156
if location_provider_impl := table_properties.get(TableProperties.WRITE_PY_LOCATION_PROVIDER_IMPL):

0 commit comments

Comments
 (0)