active-cubiomes/setup.py
2026-10-12 10:23:10 +00:00

105 lines
3.2 KiB
Python

"""Build script for active_cubiomes.
The Cython extension compiles all cubiomes C sources directly into a single
shared object — no separate libcubiomes.so is required.
Usage::
pip install -e . # editable install
pip install . # regular install
python -m build --no-isolation # build sdist + wheel
python setup.py build_ext --inplace # quick in-place build
"""
import glob
import os
import subprocess
import sys
from setuptools import Extension, setup
from Cython.Build import cythonize
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
SRC_DIR = os.path.join(BASE_DIR, "_cubiomes_src")
def _check_flag(flag):
"""Return True if the C compiler accepts the given flag."""
try:
r = subprocess.run(
["gcc", flag, "-x", "c", "-", "-o", os.devnull],
input=b"int main(void){return 0;}",
capture_output=True,
)
return r.returncode == 0
except FileNotFoundError:
return False
# Gather cubiomes C sources as paths relative to this setup.py file.
# Using relative paths is required by setuptools when building from an sdist.
_all_c = glob.glob(os.path.join(SRC_DIR, "**", "*.c"), recursive=True)
c_sources = sorted(
os.path.relpath(f, BASE_DIR)
for f in _all_c
if os.sep + "tests" + os.sep not in f
and not os.path.basename(f).startswith("test_")
and os.path.basename(f) != "tests.c"
)
extra_compile_args = [
"-O3",
"-fno-semantic-interposition",
"-fvisibility=hidden",
]
if _check_flag("-mpopcnt"): # x86 only
extra_compile_args.append("-mpopcnt")
ext = Extension(
name="cubiomes._wrapper",
sources=["cubiomes/_wrapper.pyx"] + c_sources,
include_dirs=[SRC_DIR],
extra_compile_args=extra_compile_args,
extra_link_args=["-lm"],
)
setup(
name="active_cubiomes",
version="0.1.0",
description=(
"Python/Cython bindings for cubiomes — "
"fast Minecraft biome and structure generator"
),
long_description=(
open(os.path.join(BASE_DIR, "README.md"), encoding="utf-8").read()
if os.path.exists(os.path.join(BASE_DIR, "README.md"))
else ""
),
long_description_content_type="text/markdown",
packages=["cubiomes"],
package_data={
# Ship .pxd and .pyx so downstream packages can cimport cubiomes
"cubiomes": ["_cubiomes.pxd", "_wrapper.pyx", "_wrapper.c"],
},
python_requires=">=3.8",
ext_modules=cythonize(
[ext],
compiler_directives={
"language_level": 3,
"boundscheck": False,
"wraparound": False,
"cdivision": True,
"embedsignature": True,
},
# Include pre-generated .c so users don't need Cython to build from sdist
include_path=["cubiomes"],
annotate=False,
),
entry_points={
"console_scripts": [
"cubiomes-search = cubiomes.search:main",
],
},
project_urls={ 'Documentation': 'https://git.wihuk.pro/Arigadam/active-cubiomes', 'Source': 'https://git.wihuk.pro/Arigadam/active-cubiomes', 'Bug Tracker': 'https://git.wihuk.pro/Arigadam/active-cubiomes/issues'},
zip_safe=False,
)