MCPcopy Create free account
hub / github.com/apache/arrow / get_library_dirs

Function get_library_dirs

python/pyarrow/__init__.py:400–457  ·  view source on GitHub ↗

Return lists of directories likely to contain Arrow C++ libraries for linking C or Cython extensions using pyarrow

()

Source from the content-addressed store, hash-verified

398
399
400def get_library_dirs():
401 """
402 Return lists of directories likely to contain Arrow C++ libraries for
403 linking C or Cython extensions using pyarrow
404 """
405 # Use pyarrow.lib location instead of just __file__. That works
406 # for both editable and non-editable builds as it points
407 # to the actual location of the compiled C++ extension.
408 from pyarrow import lib as _lib
409 package_cwd = _os.path.dirname(_lib.__file__)
410 library_dirs = [package_cwd]
411
412 def append_library_dir(library_dir):
413 if library_dir not in library_dirs:
414 library_dirs.append(library_dir)
415
416 # Search library paths via pkg-config. This is necessary if the user
417 # installed libarrow and the other shared libraries manually and they
418 # are not shipped inside the pyarrow package (see also ARROW-2976).
419 pkg_config_executable = _os.environ.get('PKG_CONFIG') or 'pkg-config'
420 for pkgname in ["arrow", "arrow_python"]:
421 if _has_pkg_config(pkgname):
422 library_dir = _read_pkg_config_variable(pkgname,
423 ["--libs-only-L"])
424 # pkg-config output could be empty if Arrow is installed
425 # as a system package.
426 if library_dir:
427 if not library_dir.startswith("-L"):
428 raise ValueError(
429 "pkg-config --libs-only-L returned unexpected "
430 f"value {library_dir!r}")
431 append_library_dir(library_dir[2:])
432
433 if _sys.platform == 'win32':
434 # TODO(wesm): Is this necessary, or does setuptools within a conda
435 # installation add Library\lib to the linker path for MSVC?
436 python_base_install = _os.path.dirname(_sys.executable)
437 library_dir = _os.path.join(python_base_install, 'Library', 'lib')
438
439 if _os.path.exists(_os.path.join(library_dir, 'arrow.lib')):
440 append_library_dir(library_dir)
441
442 # GH-45530: Add pyarrow.libs dir containing delvewheel-mangled
443 # msvcp140.dll
444 pyarrow_libs_dir = _os.path.abspath(
445 _os.path.join(_os.path.dirname(__file__), _os.pardir, "pyarrow.libs")
446 )
447 if _os.path.exists(pyarrow_libs_dir):
448 append_library_dir(pyarrow_libs_dir)
449
450 # ARROW-4074: Allow for ARROW_HOME to be set to some other directory
451 if _os.environ.get('ARROW_HOME'):
452 append_library_dir(_os.path.join(_os.environ['ARROW_HOME'], 'lib'))
453 else:
454 # Python wheels bundle the Arrow libraries in the pyarrow directory.
455 append_library_dir(_os.path.dirname(_os.path.abspath(__file__)))
456
457 return library_dirs

Callers

nothing calls this directly

Calls 5

_has_pkg_configFunction · 0.85
append_library_dirFunction · 0.85
getMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected