-
Notifications
You must be signed in to change notification settings - Fork 394
/
Copy pathsetup.py
247 lines (223 loc) · 7.88 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#! /usr/bin/env python
# -*- coding: utf8 -*-
# flake8: noqa: E122
"""basemap -- Plot data on map projections with matplotlib."""
import io
import os
import sys
import glob
import warnings
from setuptools import setup
from setuptools import find_packages
from setuptools.command.sdist import sdist
from setuptools.dist import Distribution
from setuptools.extension import Extension
def get_content(name, splitlines=False):
"""Return the file contents with project root as root folder."""
here = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(here, name)
with io.open(path, encoding="utf-8") as fd:
content = fd.read()
if splitlines:
content = [row for row in content.splitlines() if row]
return content
def get_geos_install_prefix():
"""Return GEOS installation prefix or None if not found."""
env_candidate = os.environ.get("GEOS_DIR", None)
if env_candidate is not None:
candidates = [env_candidate]
else:
candidates = [os.path.expanduser("~/local"), os.path.expanduser("~"),
"/usr/local", "/usr", "/opt/local", "/opt", "/sw"]
for prefix in candidates:
libfiles = []
libdirs = ["bin", "lib", "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)
return None
class basemap_sdist(sdist):
"""Custom `sdist` so that it will not pack DLLs on Windows if present."""
def run(self):
"""Custom `run` command."""
# Replace DLL data files and add GEOS build script.
orig_data_files = self.distribution.data_files
self.distribution.data_files = [
(".", glob.glob(os.path.join("utils", "*.py")))]
# Run the original `run` method and leave `data_files` as it was found.
try:
sdist.run(self)
finally:
self.distribution.data_files = orig_data_files
def initialize_options(self):
"""Call `initialize_options` and then set zip as default format."""
sdist.initialize_options(self)
self._default_to_zip()
def _default_to_zip(self):
self.formats = ["zip"]
# Initialise include and library dirs.
data_files = []
include_dirs = []
library_dirs = []
runtime_library_dirs = []
# Define NumPy include dirs.
numpy_include_path = os.environ.get("NUMPY_INCLUDE_PATH", None)
if numpy_include_path is not None:
include_dirs.append(numpy_include_path)
else:
try:
import numpy
include_dirs.append(numpy.get_include())
except ImportError as err:
warnings.warn("unable to locate NumPy headers", RuntimeWarning)
# Define GEOS include, library and runtime dirs.
geos_install_prefix = get_geos_install_prefix()
if geos_install_prefix is not None:
include_dirs.append(os.path.join(geos_install_prefix, "include"))
library_dirs.append(os.path.join(geos_install_prefix, "lib"))
library_dirs.append(os.path.join(geos_install_prefix, "lib64"))
runtime_library_dirs = library_dirs
if os.name == "nt":
# On Windows:
# - DLLs get installed under `bin`.
# - We need to inject later the DLL in the wheel using `data_files`.
# - We do not use `runtime_library_dirs` as workaround for a
# `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"))
if dlls:
data_files.append(("../..", sorted(dlls)))
# Define `_geoslib` extension module. It cannot be installed in the
# `mpl_toolkits.basemap` namespace or `Basemap` objects will not be pickleable.
ext_modules = [
Extension(**{
"name":
"_geoslib",
"sources": [
"src/_geoslib.pyx",
],
"libraries": [
"geos_c",
],
"include_dirs":
include_dirs,
"library_dirs":
library_dirs,
"runtime_library_dirs":
runtime_library_dirs,
}),
]
# Define all the different requirements.
dev_requires = get_content("requirements-dev.txt", splitlines=True)
doc_requires = get_content("requirements-doc.txt", splitlines=True)
setup_requires = get_content("requirements-setup.txt", splitlines=True)
install_requires = get_content("requirements.txt", splitlines=True)
if sys.version_info[:2] == (3, 2):
# Hack for Python 3.2 because pip < 8 cannot handle version markers.
marker = '; python_version == "3.2"'
dev_requires = [
item.replace(marker, "") for item in dev_requires
if item.endswith(marker) or "python_version" not in item]
doc_requires = [
item.replace(marker, "") for item in doc_requires
if item.endswith(marker) or "python_version" not in item]
setup_requires = [
item.replace(marker, "") for item in setup_requires
if item.endswith(marker) or "python_version" not in item]
install_requires = [
item.replace(marker, "") for item in install_requires
if item.endswith(marker) or "python_version" not in item]
setup(**{
"name":
"basemap",
"version":
"1.3.0",
"license":
"MIT",
"description":
"Plot data on map projections with matplotlib",
"long_description":
get_content("README.md"),
"long_description_content_type":
"text/markdown",
"url":
"https://matplotlib.org/basemap",
"author":
"Jeff Whitaker",
"author_email":
"maintainer":
"Víctor Molina García",
"maintainer_email":
"classifiers": [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Software Development :: Libraries :: Python Modules",
],
"keywords": [
"GIS",
"maps",
"plots",
],
"namespace_packages": [
"mpl_toolkits",
],
"package_dir":
{"": "src"},
"packages":
find_packages(where="src"),
"ext_modules":
ext_modules,
"data_files":
data_files,
"python_requires":
", ".join([
">=2.6",
"!=3.0.*",
"!=3.1.*",
"<4",
]),
"setup_requires":
setup_requires,
"install_requires":
install_requires,
"extras_require": {
"dev":
dev_requires,
"doc":
doc_requires,
},
"cmdclass": {
"sdist": basemap_sdist,
},
"project_urls": {
"Bug Tracker":
"https://github.com/matplotlib/basemap/issues",
"Documentation":
"https://matplotlib.org/basemap/",
"Source":
"https://github.com/matplotlib/basemap",
},
})