Skip to content

Commit

Permalink
Explicit errors message when arrow version mismatch (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-krystianc authored Feb 5, 2025
1 parent fcc96b2 commit eee04d3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ __pycache__
vcpkg_installed
.vscode
/palletjack/palletjack_cython.cpp
/palletjack/package_metadata.py
cython_debug
16 changes: 15 additions & 1 deletion python/palletjack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Importing pyarrow is necessary to load the runtime libraries
import pyarrow
import pyarrow.parquet
from .palletjack_cython import *

from .package_metadata import (
__version__,
__dependencies__
)

try:
from .palletjack_cython import *
except ImportError as e:
if any(x in str(e) for x in ['arrow', 'parquet']):
pyarrow_req = next((r for r in __dependencies__ if r.startswith('pyarrow')), '')
raise ImportError(f"This version of {__package__}={__version__} is built against {pyarrow_req}, please ensure you have it installed. Current pyarrow version is {pyarrow.__version__}. ({str(e)})") from None
else:
raise
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "palletjack"
version = "2.5.0"
version = "2.5.1"
description = "Faster parquet metadata reading"
readme = "README.md"
requires-python = ">=3.9"
Expand Down
37 changes: 36 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import sys
from codecs import open

from setuptools import setup, find_packages
from setuptools import setup
from setuptools.command.build_py import build_py
from distutils.extension import Extension
from Cython.Build import cythonize
import pyarrow
Expand Down Expand Up @@ -62,6 +63,37 @@ def no_cythonize(extensions, **_ignore):
else:
extensions = no_cythonize(extensions)

# Custom build command to dynamically generate metadata file
class GenerateMetadata(build_py):
def run(self):
# Call the original build_py command
super().run()

# Get the distribution object
dist = self.distribution

package_name = dist.get_name()
package_version = dist.get_version()
package_dependencies = dist.install_requires

print (f"package_name = {package_name}")
print (f"package_version = {package_version}")
print (f"package_dependencies = {package_dependencies}")

output_dir = os.path.join(package_name)
os.makedirs(output_dir, exist_ok=True)
metadata_file = os.path.join(output_dir, "package_metadata.py")

# Write metadata to the file
with open(metadata_file, "w") as f:
f.write("# Auto-generated package metadata\n")
f.write(f"__package__ = '{package_name}'\n")
f.write(f"__version__ = '{package_version}'\n")
f.write(f"__dependencies__ = {package_dependencies}\n")

print(f"Generated metadata file: {metadata_file}")
print (os.listdir(output_dir))

# Make default named pyarrow shared libs available.
pyarrow.create_library_symlinks()

Expand All @@ -74,4 +106,7 @@ def no_cythonize(extensions, **_ignore):
"Documentation": "https://github.com/G-Research/PalletJack",
"Source": "https://github.com/G-Research/PalletJack",
},
cmdclass={
"build_py": GenerateMetadata, # Use the custom build command
},
)

0 comments on commit eee04d3

Please sign in to comment.