@@ -27,20 +27,38 @@ def get_content(name, splitlines=False):
27
27
return content
28
28
29
29
30
- def checkversion (directory ):
31
- """Return GEOS version from GEOS C-API header file (geos_c.h)."""
30
+ def get_geos_install_prefix ():
31
+ """Return GEOS installation prefix or None if not found."""
32
+
33
+ env_candidate = os .environ .get ("GEOS_DIR" , None )
34
+ if env_candidate is not None :
35
+ candidates = [env_candidate ]
36
+ else :
37
+ candidates = [os .path .expanduser ("~/local" ), os .path .expanduser ("~" ),
38
+ "/usr/local" , "/usr" , "/opt/local" , "/opt" , "/sw" ]
39
+
40
+ for prefix in candidates :
41
+ libfiles = []
42
+ libdirs = ["bin" , "lib" , "lib64" ]
43
+ libext = "dll" if os .name == "nt" else "so"
44
+ libcode = "{0}geos_c" .format ("" if os .name == "nt" else "lib" )
45
+ libname = "{0}*.{1}*" .format (libcode , libext )
46
+ for libdir in libdirs :
47
+ libfiles .extend (glob .glob (os .path .join (prefix , libdir , libname )))
48
+ hfile = os .path .join (prefix , "include" , "geos_c.h" )
49
+ if os .path .isfile (hfile ) and libfiles :
50
+ return prefix
32
51
33
- version = None
34
- try :
35
- header_path = os .path .join (directory , "include" , "geos_c.h" )
36
- with io .open (header_path , "r" , encoding = "utf-8" ) as fd :
37
- for line in fd :
38
- if line .startswith ("#define GEOS_VERSION" ):
39
- version = line .split ()[2 ]
40
- break
41
- except IOError :
42
- pass
43
- return version
52
+ warnings .warn (" " .join ([
53
+ "Cannot find GEOS library and/or headers in standard locations" ,
54
+ "('{0}'). Please install the corresponding packages using your" ,
55
+ "software management system or set the environment variable" ,
56
+ "GEOS_DIR to point to the location where GEOS is installed" ,
57
+ "(for example, if 'geos_c.h' is in '/usr/local/include'" ,
58
+ "and 'libgeos_c' is in '/usr/local/lib', then you need to" ,
59
+ "set GEOS_DIR to '/usr/local'" ,
60
+ ]).format ("', '" .join (candidates )), RuntimeWarning )
61
+ return None
44
62
45
63
46
64
class basemap_sdist (sdist ):
@@ -56,6 +74,7 @@ def finalize_options(self):
56
74
57
75
58
76
# Initialise include and library dirs.
77
+ data_files = []
59
78
include_dirs = []
60
79
library_dirs = []
61
80
runtime_library_dirs = []
@@ -71,52 +90,22 @@ def finalize_options(self):
71
90
except ImportError as err :
72
91
warnings .warn ("unable to locate NumPy headers" , RuntimeWarning )
73
92
74
- # Define GEOS install directory (from environment variable or trying to guess).
75
- geos_installdir = os .environ .get ("GEOS_DIR" , None )
76
- if geos_installdir is None :
77
- # Define some default locations to find GEOS.
78
- geos_search_locations = [
79
- os .path .expanduser ("~/local" ),
80
- os .path .expanduser ("~" ),
81
- "/usr/local" ,
82
- "/usr" ,
83
- "/opt/local" ,
84
- "/opt" ,
85
- "/sw"
86
- ]
87
- # Loop over the default locations to see if we find something.
88
- for folder in geos_search_locations :
89
- geos_version = checkversion (folder )
90
- if geos_version is not None and geos_version >= '"3.1.1"' :
91
- geos_installdir = folder
92
- break
93
-
94
93
# Define GEOS include, library and runtime dirs.
95
- if geos_installdir is None :
96
- warnings .warn (" " .join ([
97
- "Cannot find GEOS library in standard locations ('{0}')." ,
98
- "Please install the corresponding packages using your" ,
99
- "software management system or set the environment variable" ,
100
- "GEOS_DIR to point to the location where GEOS is installed" ,
101
- "(for example, if 'geos_c.h' is in '/usr/local/include'" ,
102
- "and 'libgeos_c' is in '/usr/local/lib', then you need to" ,
103
- "set GEOS_DIR to '/usr/local'" ,
104
- ]).format ("', '" .join (geos_search_locations )), RuntimeWarning )
105
- else :
106
- include_dirs .append (os .path .join (geos_installdir , "include" ))
107
- library_dirs .append (os .path .join (geos_installdir , "lib" ))
108
- library_dirs .append (os .path .join (geos_installdir , "lib64" ))
94
+ geos_install_prefix = get_geos_install_prefix ()
95
+ if geos_install_prefix is not None :
96
+ include_dirs .append (os .path .join (geos_install_prefix , "include" ))
97
+ library_dirs .append (os .path .join (geos_install_prefix , "lib" ))
98
+ library_dirs .append (os .path .join (geos_install_prefix , "lib64" ))
109
99
runtime_library_dirs = library_dirs
110
- data_files = []
111
100
if os .name == "nt" :
112
101
# On Windows:
113
102
# - DLLs get installed under `bin`.
114
103
# - We need to inject later the DLL in the wheel using `data_files`.
115
104
# - We do not use `runtime_library_dirs` as workaround for a
116
105
# `distutils` bug (http://bugs.python.org/issue2437).
117
- library_dirs .append (os .path .join (geos_installdir , "bin" ))
106
+ library_dirs .append (os .path .join (geos_install_prefix , "bin" ))
118
107
runtime_library_dirs = []
119
- dlls = glob .glob (os .path .join (geos_installdir , "*" , "geos_c.dll" ))
108
+ dlls = glob .glob (os .path .join (geos_install_prefix , "*" , "geos_c.dll" ))
120
109
if dlls :
121
110
data_files .append (("../.." , sorted (dlls )))
122
111
0 commit comments