Skip to content

Commit 3bff544

Browse files
committed
Hatchlings build
1 parent 4089b35 commit 3bff544

3 files changed

Lines changed: 55 additions & 59 deletions

File tree

build-module.py

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,49 @@
1818
import os
1919
import shutil
2020
from pathlib import Path
21+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
2122

2223
allowed_to_fail = os.environ.get("CIBUILDWHEEL", "0") != "1"
2324

25+
class CythonBuildHook(BuildHookInterface):
26+
def initialize(self, version, build_data):
27+
import Cython.Compiler.Options
28+
from Cython.Build import build_ext, cythonize
29+
from setuptools import Extension
30+
from setuptools.dist import Distribution
2431

25-
def build_cython_extensions() -> None:
26-
import Cython.Compiler.Options
27-
from Cython.Build import build_ext, cythonize
28-
from setuptools import Extension
29-
from setuptools.dist import Distribution
32+
Cython.Compiler.Options.annotate = True
3033

31-
Cython.Compiler.Options.annotate = True
34+
if os.name == "nt": # Windows
35+
extra_compile_args = [
36+
"/O2",
37+
]
38+
else: # UNIX-based systems
39+
extra_compile_args = [
40+
"-O3",
41+
]
3242

33-
if os.name == "nt": # Windows
34-
extra_compile_args = [
35-
"/O2",
36-
]
37-
else: # UNIX-based systems
38-
extra_compile_args = [
39-
"-O3",
40-
]
43+
package_path = "pyiceberg"
4144

42-
package_path = "pyiceberg"
45+
extension = Extension(
46+
# Your .pyx file will be available to cpython at this location.
47+
name="pyiceberg.avro.decoder_fast",
48+
sources=[
49+
os.path.join(package_path, "avro", "decoder_fast.pyx"),
50+
],
51+
extra_compile_args=extra_compile_args,
52+
language="c",
53+
)
4354

44-
extension = Extension(
45-
# Your .pyx file will be available to cpython at this location.
46-
name="pyiceberg.avro.decoder_fast",
47-
sources=[
48-
os.path.join(package_path, "avro", "decoder_fast.pyx"),
49-
],
50-
extra_compile_args=extra_compile_args,
51-
language="c",
52-
)
55+
ext_modules = cythonize([extension], include_path=list(package_path), language_level=3, annotate=True)
56+
dist = Distribution({"ext_modules": ext_modules})
57+
cmd = build_ext(dist)
58+
cmd.ensure_finalized()
5359

54-
ext_modules = cythonize([extension], include_path=list(package_path), language_level=3, annotate=True)
55-
dist = Distribution({"ext_modules": ext_modules})
56-
cmd = build_ext(dist)
57-
cmd.ensure_finalized()
60+
cmd.run()
5861

59-
cmd.run()
62+
for output in cmd.get_outputs():
63+
output = Path(output)
64+
relative_extension = output.relative_to(cmd.build_lib)
65+
shutil.copyfile(output, relative_extension)
6066

61-
for output in cmd.get_outputs():
62-
output = Path(output)
63-
relative_extension = output.relative_to(cmd.build_lib)
64-
shutil.copyfile(output, relative_extension)
65-
66-
67-
try:
68-
build_cython_extensions()
69-
except Exception:
70-
if not allowed_to_fail:
71-
raise

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,11 @@ include = [
164164
"vendor/fb303" = "fb303"
165165
"vendor/hive_metastore" = "hive_metastore"
166166

167+
[tool.hatch.build.hooks.custom]
168+
path = "build-module.py"
169+
167170
[build-system]
168-
requires = ["hatchling"]
171+
requires = ["hatchling", "Cython>=3.0.0", "setuptools", "wheel"]
169172
build-backend = "hatchling.build"
170173

171174
[[tool.mypy.overrides]]

uv.lock

Lines changed: 16 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)