Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setup.py to identify GEOS dylib on MacOS #541

Merged
merged 4 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions packages/basemap/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand Down
26 changes: 19 additions & 7 deletions packages/basemap/utils/GeosLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down