in python/bootstrap.py [0:0]
def copy_or_generate_nanoarrow_c():
this_wd = os.getcwd()
this_dir = os.path.abspath(os.path.dirname(__file__))
source_dir = os.path.dirname(this_dir)
maybe_nanoarrow_h = os.path.join(this_dir, "src/nanoarrow/nanoarrow.h")
maybe_nanoarrow_c = os.path.join(this_dir, "src/nanoarrow/nanoarrow.c")
for f in (maybe_nanoarrow_c, maybe_nanoarrow_h):
if os.path.exists(f):
os.unlink(f)
is_cmake_dir = "CMakeLists.txt" in os.listdir(source_dir)
is_in_nanoarrow_repo = "nanoarrow.h" in os.listdir(
os.path.join(source_dir, "src", "nanoarrow")
)
has_cmake = os.system("cmake --version") == 0
build_dir = os.path.join(this_dir, "_cmake")
if has_cmake and is_cmake_dir and is_in_nanoarrow_repo:
try:
os.mkdir(build_dir)
os.chdir(build_dir)
os.system(
"cmake ../.. -DNANOARROW_BUNDLE=ON -DNANOARROW_NAMESPACE=PythonPkg"
)
os.system("cmake --install . --prefix=../src/nanoarrow")
finally:
if os.path.exists(build_dir):
# Can fail on Windows with permission issues
try:
shutil.rmtree(build_dir)
except Exception as e:
print(f"Failed to remove _cmake temp directory: {str(e)}")
os.chdir(this_wd)
elif is_in_nanoarrow_repo:
shutil.copyfile()
else:
raise ValueError(
"Attempt to build source distribution outside the nanoarrow repo"
)
if not os.path.exists(os.path.join(this_dir, "src/nanoarrow/nanoarrow.h")):
raise ValueError("Attempt to vendor nanoarrow.c/h failed")
maybe_nanoarrow_hpp = os.path.join(this_dir, "src/nanoarrow/nanoarrow.hpp")
if os.path.exists(maybe_nanoarrow_hpp):
os.unlink(maybe_nanoarrow_hpp)