Skip to content

Commit

Permalink
Merge pull request #587 from HEXRD/install-pybind11-if-missing
Browse files Browse the repository at this point in the history
Install pybind11 if it is missing
  • Loading branch information
psavery authored Nov 29, 2023
2 parents 5f742ea + a7ad872 commit 1dc509b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 9 additions & 5 deletions scripts/install/install_build_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ def download_pybind11(path):
md5sum = '90c4946e87c64d8d8fc0ae4edf35d780'
out_dir_name = 'pybind11-2.11.0'

download_and_extract_tgz(url, md5sum, path)
with tempfile.TemporaryDirectory() as temp_dir:
download_and_extract_tgz(url, md5sum, temp_dir)

target_path = Path(path) / 'pybind11'
if target_path.exists():
shutil.rmtree(target_path)
target_path = Path(path) / 'pybind11'
if target_path.exists():
shutil.rmtree(target_path)

os.makedirs(path, exist_ok=True)
shutil.move(str(Path(temp_dir) / out_dir_name / 'include/pybind11'),
str(Path(path) / 'pybind11/pybind11'))

shutil.move(str(Path(path) / out_dir_name), str(Path(path) / 'pybind11'))

return str(target_path)

Expand Down
16 changes: 14 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import sys

import numpy
import pybind11
np_include_dir = numpy.get_include()

install_reqs = [
Expand Down Expand Up @@ -93,6 +92,19 @@ def get_include_path(library_name):
return full_path


def get_pybind11_include_path():
# If we can import pybind11, use that include path
try:
import pybind11
except ImportError:
pass
else:
return pybind11.get_include()

# Otherwise, we will download the source and include that
return get_include_path('pybind11')


def get_cpp_extensions():
cpp_transform_pkgdir = Path('hexrd') / 'transforms/cpp_sublibrary'
src_files = [str(cpp_transform_pkgdir / 'src/inverse_distortion.cpp')]
Expand All @@ -106,7 +118,7 @@ def get_cpp_extensions():
include_dirs = [
get_include_path('eigen3'),
get_include_path('xsimd'),
pybind11.get_include(),
get_pybind11_include_path(),
numpy.get_include(),
]

Expand Down

0 comments on commit 1dc509b

Please sign in to comment.