MCPcopy Create free account
hub / github.com/shapely/shapely / get_ext_options

Function get_ext_options

setup.py:56–127  ·  view source on GitHub ↗

Get Extension options to build using GEOS and NumPy C API. First the presence of the GEOS_INCLUDE_PATH and GEOS_INCLUDE_PATH environment variables is checked. If they are both present, these are taken. If one of the two paths was not present, geos-config is called (it should be on the

()

Source from the content-addressed store, hash-verified

54
55
56def get_ext_options():
57 """Get Extension options to build using GEOS and NumPy C API.
58
59 First the presence of the GEOS_INCLUDE_PATH and GEOS_INCLUDE_PATH environment
60 variables is checked. If they are both present, these are taken.
61
62 If one of the two paths was not present, geos-config is called (it should be on the
63 PATH variable). geos-config provides all the paths.
64
65 If geos-config was not found, no additional paths are provided to the extension.
66 It is still possible to compile in this case using custom arguments to setup.py.
67 """
68 import numpy
69
70 opts = {
71 "define_macros": [
72 # avoid accidental use of non-reentrant functions
73 ("GEOS_USE_ONLY_R_API", None),
74 # silence warnings
75 ("NPY_NO_DEPRECATED_API", "0"),
76 # minimum numpy version
77 ("NPY_TARGET_VERSION", "NPY_1_20_API_VERSION"),
78 ],
79 "include_dirs": ["./src"],
80 "library_dirs": [],
81 "extra_link_args": [],
82 "libraries": [],
83 }
84
85 if include_dir := numpy.get_include():
86 opts["include_dirs"].append(include_dir)
87
88 # Without geos-config (e.g. MSVC), specify these two vars
89 include_dir = os.environ.get("GEOS_INCLUDE_PATH")
90 library_dir = os.environ.get("GEOS_LIBRARY_PATH")
91 if include_dir and library_dir:
92 opts["include_dirs"].append(include_dir)
93 opts["library_dirs"].append(library_dir)
94 opts["libraries"].append("geos_c")
95 return opts
96
97 geos_version = get_geos_config("--version")
98 if not geos_version:
99 log.warning(
100 "Could not find geos-config executable. Either append the path to "
101 "geos-config to PATH or manually provide the include_dirs, library_dirs, "
102 "libraries and other link args for compiling against a GEOS version >=%s.",
103 MIN_GEOS_VERSION,
104 )
105 return {}
106
107 def version_tuple(ver):
108 return tuple(int(itm) if itm.isnumeric() else itm for itm in ver.split("."))
109
110 if version_tuple(geos_version) < version_tuple(MIN_GEOS_VERSION):
111 raise ImportError(
112 f"GEOS version should be >={MIN_GEOS_VERSION}, found {geos_version}"
113 )

Callers 1

setup.pyFile · 0.85

Calls 3

get_geos_configFunction · 0.85
version_tupleFunction · 0.85
splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…