forked from pyproj4/pyproj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
242 lines (213 loc) · 8.09 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
import os
import subprocess
import sys
from distutils.spawn import find_executable
from glob import glob
from pkg_resources import parse_version
from setuptools import Extension, setup
PROJ_MIN_VERSION = parse_version("7.1.0")
CURRENT_FILE_PATH = os.path.dirname(os.path.abspath(__file__))
BASE_INTERNAL_PROJ_DIR = "proj_dir"
INTERNAL_PROJ_DIR = os.path.join(CURRENT_FILE_PATH, "pyproj", BASE_INTERNAL_PROJ_DIR)
def check_proj_version(proj_dir):
"""checks that the PROJ library meets the minimum version"""
proj = os.path.join(proj_dir, "bin", "proj")
proj_ver_bytes = subprocess.check_output(proj, stderr=subprocess.STDOUT)
proj_ver_bytes = (proj_ver_bytes.decode("ascii").split()[1]).strip(",")
proj_version = parse_version(proj_ver_bytes)
if proj_version < PROJ_MIN_VERSION:
sys.exit(
f"ERROR: Minimum supported proj version is {PROJ_MIN_VERSION}, installed "
f"version is {proj_version}. For more information see: "
"https://pyproj4.github.io/pyproj/stable/installation.html"
)
return proj_version
def get_proj_dir():
"""
This function finds the base PROJ directory.
"""
proj_dir = os.environ.get("PROJ_DIR")
if proj_dir is None and os.path.exists(INTERNAL_PROJ_DIR):
proj_dir = INTERNAL_PROJ_DIR
print(f"Internally compiled directory being used {INTERNAL_PROJ_DIR}.")
elif proj_dir is None and not os.path.exists(INTERNAL_PROJ_DIR):
proj = find_executable("proj", path=sys.prefix)
if proj is None:
proj = find_executable("proj")
if proj is None:
sys.exit(
"proj executable not found. Please set the PROJ_DIR variable."
"For more information see: "
"https://pyproj4.github.io/pyproj/stable/installation.html"
)
proj_dir = os.path.dirname(os.path.dirname(proj))
elif proj_dir is not None and os.path.exists(proj_dir):
print("PROJ_DIR is set, using existing proj4 installation..\n")
else:
sys.exit(f"ERROR: Invalid path for PROJ_DIR {proj_dir}")
# check_proj_version
check_proj_version(proj_dir)
return proj_dir
def get_proj_libdirs(proj_dir):
"""
This function finds the library directories
"""
proj_libdir = os.environ.get("PROJ_LIBDIR")
libdirs = []
if proj_libdir is None:
libdir_search_paths = (
os.path.join(proj_dir, "lib"),
os.path.join(proj_dir, "lib64"),
)
for libdir_search_path in libdir_search_paths:
if os.path.exists(libdir_search_path):
libdirs.append(libdir_search_path)
if not libdirs:
sys.exit("ERROR: PROJ_LIBDIR dir not found. Please set PROJ_LIBDIR.")
else:
libdirs.append(proj_libdir)
return libdirs
def get_proj_incdirs(proj_dir):
"""
This function finds the include directories
"""
proj_incdir = os.environ.get("PROJ_INCDIR")
incdirs = []
if proj_incdir is None:
if os.path.exists(os.path.join(proj_dir, "include")):
incdirs.append(os.path.join(proj_dir, "include"))
else:
sys.exit("ERROR: PROJ_INCDIR dir not found. Please set PROJ_INCDIR.")
else:
incdirs.append(proj_incdir)
return incdirs
def get_cythonize_options():
"""
This function gets the options to cythonize with
"""
# Configure optional Cython coverage.
cythonize_options = {
"language_level": sys.version_info[0],
"compiler_directives": {"embedsignature": True},
}
if os.environ.get("PYPROJ_FULL_COVERAGE"):
cythonize_options["compiler_directives"].update(linetrace=True)
cythonize_options["annotate"] = True
return cythonize_options
def get_libraries(libdirs):
"""
This function gets the libraries to cythonize with
"""
libraries = ["proj"]
if os.name == "nt":
for libdir in libdirs:
projlib = glob(os.path.join(libdir, "proj*.lib"))
if projlib:
libraries = [os.path.basename(projlib[0]).split(".lib")[0]]
break
return libraries
def get_extension_modules():
"""
This function retrieves the extension modules
"""
if "clean" in sys.argv:
return None
# make sure cython is available
try:
from Cython.Build import cythonize
except ImportError:
sys.exit(
"ERROR: Cython.Build.cythonize not found. "
"Cython is required to build from a repo."
)
# By default we'll try to get options PROJ_DIR or the local version of proj
proj_dir = get_proj_dir()
library_dirs = get_proj_libdirs(proj_dir)
include_dirs = get_proj_incdirs(proj_dir)
# setup extension options
ext_options = {
"include_dirs": include_dirs,
"library_dirs": library_dirs,
"runtime_library_dirs": library_dirs if os.name != "nt" else None,
"libraries": get_libraries(library_dirs),
}
# setup cythonized modules
return cythonize(
[
Extension("pyproj._geod", ["pyproj/_geod.pyx"], **ext_options),
Extension("pyproj._crs", ["pyproj/_crs.pyx"], **ext_options),
Extension(
"pyproj._transformer", ["pyproj/_transformer.pyx"], **ext_options
),
Extension("pyproj._datadir", ["pyproj/_datadir.pyx"], **ext_options),
Extension("pyproj._list", ["pyproj/_list.pyx"], **ext_options),
Extension("pyproj._sync", ["pyproj/_sync.pyx"], **ext_options),
],
quiet=True,
**get_cythonize_options(),
)
def get_package_data():
"""
This function retrieves the package data
"""
# setup package data
package_data = {"pyproj": ["*.pyi", "py.typed"]}
if os.environ.get("PROJ_WHEEL") is not None and os.path.exists(INTERNAL_PROJ_DIR):
package_data["pyproj"].append(
os.path.join(BASE_INTERNAL_PROJ_DIR, "share", "proj", "*")
)
if os.environ.get("PROJ_WHEEL") is not None and os.path.exists(
os.path.join(CURRENT_FILE_PATH, "pyproj", ".lib")
):
package_data["pyproj"].append(os.path.join(".lib", "*"))
return package_data
def get_version():
"""
retreive pyproj version information (stored in _proj.pyx) in version variable
(taken from Fiona)
"""
with open(os.path.join("pyproj", "__init__.py"), "r") as f:
for line in f:
if line.find("__version__") >= 0:
# parse __version__ and remove surrounding " or '
return line.split("=")[1].strip()[1:-1]
sys.exit("ERROR: pyproj version not fount.")
def get_long_description():
"""
Get the long description for the file.
"""
with open("README.md", encoding="utf-8") as ld_file:
return ld_file.read()
setup(
name="pyproj",
version=get_version(),
description="Python interface to PROJ (cartographic projections "
"and coordinate transformations library)",
long_description=get_long_description(),
long_description_content_type="text/markdown",
url="https://github.com/pyproj4/pyproj",
download_url="http://python.org/pypi/pyproj",
author="Jeff Whitaker",
author_email="jeffrey.s.whitaker@noaa.gov",
platforms=["any"],
license="MIT",
entry_points={"console_scripts": ["pyproj=pyproj.__main__:main"]},
keywords=["python", "map projections", "GIS", "mapping", "maps"],
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Scientific/Engineering :: GIS",
"Topic :: Scientific/Engineering :: Mathematics",
"Operating System :: OS Independent",
],
packages=["pyproj", "pyproj.crs"],
python_requires=">=3.6",
ext_modules=get_extension_modules(),
package_data=get_package_data(),
zip_safe=False, # https://mypy.readthedocs.io/en/stable/installed_packages.html
)