Skip to content

Commit 4954b9d

Browse files
committed
Modify GeosLibrary so that it works in win_amd64
1 parent 88cb7e5 commit 4954b9d

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

packages/basemap/requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pytest >= 3.2, < 5.0; python_version == "3.4"
2020
pytest >= 3.2, < 6.3; python_version >= "3.5"
2121

2222
coverage >= 3.7, < 4.0; python_version == "3.2"
23-
2423
pytest-cov >= 2.5, < 2.6; python_version == "2.6"
2524
pytest-cov >= 2.5, < 3.0; python_version == "2.7"
2625
pytest-cov >= 2.5, < 2.6; python_version == "3.2"

packages/basemap/setup.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io
77
import os
88
import sys
9+
import glob
910
import warnings
1011
from setuptools import setup
1112
from setuptools import find_packages
@@ -76,9 +77,9 @@ def checkversion(directory):
7677
geos_installdir = folder
7778
break
7879

79-
# Define GEOS include and library dirs.
80+
# Define GEOS include, library and runtime dirs.
8081
if geos_installdir is None:
81-
warnings.warn("\n".join([
82+
warnings.warn(" ".join([
8283
"Cannot find GEOS library in standard locations ('{0}').",
8384
"Please install the corresponding packages using your",
8485
"software management system or set the environment variable",
@@ -91,14 +92,19 @@ def checkversion(directory):
9192
include_dirs.append(os.path.join(geos_installdir, "include"))
9293
library_dirs.append(os.path.join(geos_installdir, "lib"))
9394
library_dirs.append(os.path.join(geos_installdir, "lib64"))
94-
95-
# Define runtime library dirs.
96-
# Don't use runtime_library_dirs on windows (workaround for a distutils bug):
97-
# http://bugs.python.org/issue2437)
98-
if sys.platform == "win32":
99-
runtime_lib_dirs = []
100-
else:
101-
runtime_lib_dirs = library_dirs
95+
runtime_library_dirs = library_dirs
96+
data_files = []
97+
if os.name == "nt":
98+
# On Windows:
99+
# - DLLs get installed under `bin`.
100+
# - We need to inject the DLL in the wheel using `data_files`.
101+
# - We do not use `runtime_library_dirs` as workaround for a
102+
# `distutils` bug (http://bugs.python.org/issue2437).
103+
library_dirs.append(os.path.join(geos_installdir, "bin"))
104+
runtime_library_dirs = []
105+
dlls = glob.glob(os.path.join(geos_installdir, "*", "geos_c.dll"))
106+
if dlls:
107+
data_files.append(("../..", sorted(dlls)))
102108

103109
# Define `_geoslib` extension module. It cannot be installed in the
104110
# `mpl_toolkits.basemap` namespace or `Basemap` objects will not be pickleable.
@@ -117,7 +123,7 @@ def checkversion(directory):
117123
"library_dirs":
118124
library_dirs,
119125
"runtime_library_dirs":
120-
runtime_lib_dirs,
126+
runtime_library_dirs,
121127
}),
122128
]
123129

@@ -192,6 +198,8 @@ def checkversion(directory):
192198
find_packages(where="src"),
193199
"ext_modules":
194200
ext_modules,
201+
"data_files":
202+
data_files,
195203
"python_requires":
196204
", ".join([
197205
">=2.6",

packages/basemap/utils/GeosLibrary.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def download(self):
105105
if date is not None:
106106
os.utime(zippath, (date, date))
107107

108-
def decompress(self, overwrite=True):
108+
def extract(self, overwrite=True):
109109
"""Decompress GEOS zip source code into :class:`GeosLibrary` root."""
110110

111111
# Download zip file if not present.
@@ -142,9 +142,9 @@ def decompress(self, overwrite=True):
142142
def build(self, installdir=None):
143143
"""Build and install GEOS from source."""
144144

145-
# Download and decompress zip file if not present.
145+
# Download and extract zip file if not present.
146146
zipfold = os.path.join(self.root, "geos-{0}".format(self.version))
147-
self.decompress(overwrite=True)
147+
self.extract(overwrite=True)
148148

149149
# Define build directory.
150150
builddir = os.path.join(zipfold, "build")
@@ -154,6 +154,17 @@ def build(self, installdir=None):
154154
installdir = os.path.expanduser("~/.local/share/libgeos")
155155
installdir = os.path.abspath(installdir)
156156

157+
# Define configure options.
158+
config_opts = [
159+
"-DCMAKE_INSTALL_PREFIX={0}".format(installdir),
160+
"-DGEOS_ENABLE_TESTS=OFF",
161+
]
162+
if os.name == "nt":
163+
config_opts.append("-DCMAKE_GENERATOR_PLATFORM=x64")
164+
config_opts.append("-DCMAKE_GENERATOR_TOOLSET=host=x64")
165+
else:
166+
config_opts.append("-DCMAKE_BUILD_TYPE=Release")
167+
157168
# Now move to the GEOS source code folder and build with CMake.
158169
cwd = os.getcwd()
159170
try:
@@ -164,10 +175,7 @@ def build(self, installdir=None):
164175
pass
165176
os.chdir(builddir)
166177
# Call cmake configure.
167-
subprocess.call(["cmake", "..",
168-
"-DCMAKE_BUILD_TYPE=Release",
169-
"-DCMAKE_INSTALL_PREFIX={0}".format(installdir),
170-
"-DGEOS_ENABLE_TESTS=OFF"])
178+
subprocess.call(["cmake", ".."] + config_opts)
171179
# Ensure that the install directory exists.
172180
try:
173181
os.makedirs(installdir)
@@ -176,6 +184,7 @@ def build(self, installdir=None):
176184
# Call cmake build and install.
177185
subprocess.call(["cmake",
178186
"--build", ".",
187+
"--config", "Release",
179188
"--target", "install"])
180189
finally:
181190
os.chdir(cwd)

0 commit comments

Comments
 (0)