diff --git a/packages/basemap/setup.py b/packages/basemap/setup.py index 17cc473f6..da0b8b6dc 100644 --- a/packages/basemap/setup.py +++ b/packages/basemap/setup.py @@ -37,27 +37,33 @@ def get_geos_install_prefix(): candidates = [os.path.expanduser("~/local"), os.path.expanduser("~"), "/usr/local", "/usr", "/opt/local", "/opt", "/sw"] + # Prepare filename pattern to find the GEOS library. + extensions = {"win32": "dll", "cygwin": "dll", "darwin": "dylib"} + libext = extensions.get(sys.platform, "so*") + libname = "*geos_c*.{0}".format(libext) + libdirs = ["bin", "lib", "lib/x86_64-linux-gnu", "lib64"] + for prefix in candidates: libfiles = [] - libdirs = ["bin", "lib", "lib/x86_64-linux-gnu", "lib64"] - libext = "dll" if os.name == "nt" else "so" - libcode = "{0}geos_c".format("" if os.name == "nt" else "lib") - libname = "{0}*.{1}*".format(libcode, libext) for libdir in libdirs: libfiles.extend(glob.glob(os.path.join(prefix, libdir, libname))) hfile = os.path.join(prefix, "include", "geos_c.h") if os.path.isfile(hfile) and libfiles: return prefix - warnings.warn(" ".join([ - "Cannot find GEOS library and/or headers in standard locations", - "('{0}'). Please install the corresponding packages using your", - "software management system or set the environment variable", - "GEOS_DIR to point to the location where GEOS is installed", - "(for example, if 'geos_c.h' is in '/usr/local/include'", - "and 'libgeos_c' is in '/usr/local/lib', then you need to", - "set GEOS_DIR to '/usr/local'", - ]).format("', '".join(candidates)), RuntimeWarning) + # At this point, the GEOS library was not found, so we throw a warning if + # the user is trying to build the library. + build_cmds = ("bdist_wheel", "build", "install") + if any(cmd in sys.argv[1:] for cmd in build_cmds): + warnings.warn(" ".join([ + "Cannot find GEOS library and/or headers in standard locations", + "('{0}'). Please install the corresponding packages using your", + "software management system or set the environment variable", + "GEOS_DIR to point to the location where GEOS is installed", + "(for example, if 'geos_c.h' is in '/usr/local/include'", + "and 'libgeos_c' is in '/usr/local/lib', then you need to", + "set GEOS_DIR to '/usr/local'", + ]).format("', '".join(candidates)), RuntimeWarning) return None @@ -94,7 +100,9 @@ def run(self): import numpy include_dirs.append(numpy.get_include()) except ImportError as err: - warnings.warn("unable to locate NumPy headers", RuntimeWarning) + build_cmds = ("bdist_wheel", "build", "install") + if any(cmd in sys.argv[1:] for cmd in build_cmds): + warnings.warn("unable to locate NumPy headers", RuntimeWarning) # Define GEOS include, library and runtime dirs. geos_install_prefix = get_geos_install_prefix() diff --git a/packages/basemap/utils/GeosLibrary.py b/packages/basemap/utils/GeosLibrary.py index ffbcfd1f4..c7e9460e0 100644 --- a/packages/basemap/utils/GeosLibrary.py +++ b/packages/basemap/utils/GeosLibrary.py @@ -147,12 +147,24 @@ def extract(self, overwrite=True): for line in lines: fd.write(line.replace(oldtext, newtext).encode()) - # The SVN revision file is not created on the fly before 3.6.0. - svn_hfile = os.path.join(zipfold, "geos_svn_revision.h") - if self.version_tuple < (3, 6, 0) and not os.path.exists(svn_hfile): - with io.open(svn_hfile, "wb") as fd: - text = "#define GEOS_SVN_REVISION 0" - fd.write(text.encode()) + # Apply specific patches for GEOS < 3.6.0. + if self.version_tuple < (3, 6, 0): + # The SVN revision file is not created on the fly before 3.6.0. + svn_hfile = os.path.join(zipfold, "geos_svn_revision.h") + if not os.path.exists(svn_hfile): + with io.open(svn_hfile, "wb") as fd: + text = "#define GEOS_SVN_REVISION 0" + fd.write(text.encode()) + # Reduce warnings when compiling with `nmake` on Windows. + cmakefile = os.path.join(zipfold, "CMakeLists.txt") + if os.path.exists(cmakefile): + with io.open(cmakefile, "r", encoding="utf-8") as fd: + lines = fd.readlines() + with io.open(cmakefile, "wb") as fd: + oldtext = 'string(REGEX REPLACE "/W[0-9]" "/W4"' + newtext = oldtext.replace("W4", "W1") + for line in lines: + fd.write(line.replace(oldtext, newtext).encode()) def build(self, installdir=None, njobs=1): """Build and install GEOS from source.""" @@ -191,7 +203,7 @@ def build(self, installdir=None, njobs=1): build_opts.extend([ "--", "WIN64={0}".format("YES" if win64 else "NO"), - "BUILD_BATCH={0}".format("YES" if njobs > 1 else "NO") + "BUILD_BATCH={0}".format("YES" if njobs > 1 else "NO"), ]) else: build_opts = ["-j", "{0:d}".format(njobs)] + build_opts