From b17ed5c39ef623af1e4ce144edd0c4fce2e47433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Molina=20Garc=C3=ADa?= Date: Wed, 13 Apr 2022 23:45:58 +0200 Subject: [PATCH 1/4] Reimplement GEOS search to find dylib files on MacOS --- packages/basemap/setup.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/basemap/setup.py b/packages/basemap/setup.py index 17cc473f6..67a015ae8 100644 --- a/packages/basemap/setup.py +++ b/packages/basemap/setup.py @@ -37,12 +37,14 @@ 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") @@ -111,7 +113,7 @@ def run(self): # `distutils` bug (http://bugs.python.org/issue2437). library_dirs.append(os.path.join(geos_install_prefix, "bin")) runtime_library_dirs = [] - dlls = glob.glob(os.path.join(geos_install_prefix, "*", "geos_c.dll")) + dlls = glob.glob(os.path.join(geos_install_prefix, "*", "*geos_c.dll")) if dlls: data_files.append(("../..", sorted(dlls))) From 4f71542f31af9aaffaa5c74305c0d9b679d57e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Molina=20Garc=C3=ADa?= Date: Wed, 13 Apr 2022 23:58:21 +0200 Subject: [PATCH 2/4] Ensure setup warnings are only printed if building --- packages/basemap/setup.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/basemap/setup.py b/packages/basemap/setup.py index 67a015ae8..8ba30224b 100644 --- a/packages/basemap/setup.py +++ b/packages/basemap/setup.py @@ -51,15 +51,19 @@ def get_geos_install_prefix(): 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 @@ -96,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() From a28c99f5fa9c1dbacb1a484d43e34eefa9bdb71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Molina=20Garc=C3=ADa?= Date: Thu, 14 Apr 2022 00:43:01 +0200 Subject: [PATCH 3/4] Reduce GeosLibrary verbosity on Windows + NMake --- packages/basemap/utils/GeosLibrary.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) 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 From 02340ee6210749ca88da27e2ee3446891c3a0c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Molina=20Garc=C3=ADa?= Date: Sat, 16 Apr 2022 13:24:34 +0200 Subject: [PATCH 4/4] Revert setup of data files on Windows We are only interested in bundling the DLL file for GEOS on Windows for standard installations but not for MinGW64 or Cygwin. Therefore, the filename pattern matching needs to be more restrictive because otherwise we will find `libgeos_c.dll` as valid file to bundle. --- packages/basemap/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/basemap/setup.py b/packages/basemap/setup.py index 8ba30224b..da0b8b6dc 100644 --- a/packages/basemap/setup.py +++ b/packages/basemap/setup.py @@ -119,7 +119,7 @@ def run(self): # `distutils` bug (http://bugs.python.org/issue2437). library_dirs.append(os.path.join(geos_install_prefix, "bin")) runtime_library_dirs = [] - dlls = glob.glob(os.path.join(geos_install_prefix, "*", "*geos_c.dll")) + dlls = glob.glob(os.path.join(geos_install_prefix, "*", "geos_c.dll")) if dlls: data_files.append(("../..", sorted(dlls)))