6
6
import io
7
7
import os
8
8
import sys
9
+ import warnings
9
10
from setuptools import setup
10
11
from setuptools import find_packages
11
12
from setuptools .dist import Distribution
@@ -40,11 +41,24 @@ def checkversion(directory):
40
41
return version
41
42
42
43
44
+ # Initialise include and library dirs.
45
+ include_dirs = []
46
+ library_dirs = []
47
+
48
+ # Define NumPy include dirs.
49
+ numpy_include_path = os .environ .get ("NUMPY_INCLUDE_PATH" , None )
50
+ if numpy_include_path is not None :
51
+ include_dirs .append (numpy_include_path )
52
+ else :
53
+ try :
54
+ import numpy
55
+ include_dirs .append (numpy .get_include ())
56
+ except ImportError as err :
57
+ warnings .warn ("unable to locate NumPy headers" , RuntimeWarning )
58
+
43
59
# Define GEOS install directory (from environment variable or trying to guess).
44
60
geos_installdir = os .environ .get ("GEOS_DIR" , None )
45
- if geos_installdir is not None :
46
- geos_version = checkversion (geos_installdir )
47
- else :
61
+ if geos_installdir is None :
48
62
# Define some default locations to find GEOS.
49
63
geos_search_locations = [
50
64
os .path .expanduser ("~/local" ),
@@ -57,56 +71,31 @@ def checkversion(directory):
57
71
]
58
72
# Loop over the default locations to see if we find something.
59
73
for folder in geos_search_locations :
60
- # sys.stdout.write('checking for GEOS lib in %s ....\n' % folder)
61
74
geos_version = checkversion (folder )
62
75
if geos_version is not None and geos_version >= '"3.1.1"' :
63
- # sys.stdout.write(
64
- # "GEOS lib (version %s) found in %s\n" %
65
- # (geos_version[1:-1], folder))
66
76
geos_installdir = folder
67
77
break
68
- if geos_installdir is None :
69
- raise OSError ("\n " .join ([
70
- "Cannot find GEOS library in standard locations ('{0}')." ,
71
- "Please install the corresponding packages using your" ,
72
- "software management system or set the environment variable" ,
73
- "GEOS_DIR to point to the location where GEOS is installed" ,
74
- "(for example, if 'geos_c.h' is in '/usr/local/include'" ,
75
- "and 'libgeos_c' is in '/usr/local/lib', then you need to" ,
76
- "set GEOS_DIR to '/usr/local'" ,
77
- ]).format ("', '" .join (geos_search_locations )))
78
-
79
- # Define include dirs.
80
- include_dirs = [
81
- os .path .join (geos_installdir , "include" )
82
- ]
83
78
84
- # Define include dirs for NumPy.
85
- # Do not import numpy for querying the package (taken from h5py setup).
86
- if not any ("--" + opt in sys .argv
87
- for opt in Distribution .display_option_names +
88
- ["help-commands" , "help" ]) or sys .argv [1 ] == "egg_info" :
89
- # Try to read NumPy include path from environment variable.
90
- numpy_include_path = os .environ .get ("NUMPY_INCLUDE_PATH" , None )
91
- if numpy_include_path is None :
92
- try :
93
- import numpy
94
- numpy_include_path = numpy .get_include ()
95
- except ImportError as err :
96
- err .args = ("unable to locate NumPy headers" ,)
97
- raise
98
- include_dirs .append (numpy_include_path )
99
-
100
- # Define library dirs.
101
- library_dirs = [
102
- os .path .join (geos_installdir , "lib" ),
103
- os .path .join (geos_installdir , "lib64" ),
104
- ]
79
+ # Define GEOS include and library dirs.
80
+ if geos_installdir is None :
81
+ warnings .warn ("\n " .join ([
82
+ "Cannot find GEOS library in standard locations ('{0}')." ,
83
+ "Please install the corresponding packages using your" ,
84
+ "software management system or set the environment variable" ,
85
+ "GEOS_DIR to point to the location where GEOS is installed" ,
86
+ "(for example, if 'geos_c.h' is in '/usr/local/include'" ,
87
+ "and 'libgeos_c' is in '/usr/local/lib', then you need to" ,
88
+ "set GEOS_DIR to '/usr/local'" ,
89
+ ]).format ("', '" .join (geos_search_locations )), RuntimeWarning )
90
+ else :
91
+ include_dirs .append (os .path .join (geos_installdir , "include" ))
92
+ library_dirs .append (os .path .join (geos_installdir , "lib" ))
93
+ library_dirs .append (os .path .join (geos_installdir , "lib64" ))
105
94
106
95
# Define runtime library dirs.
107
96
# Don't use runtime_library_dirs on windows (workaround for a distutils bug):
108
97
# http://bugs.python.org/issue2437)
109
- if sys .platform = = "win32" :
98
+ if sys .platform ! = "win32" :
110
99
runtime_lib_dirs = []
111
100
else :
112
101
runtime_lib_dirs = library_dirs
@@ -132,6 +121,27 @@ def checkversion(directory):
132
121
}),
133
122
]
134
123
124
+ # Define all the different requirements.
125
+ dev_requires = get_content ("requirements-dev.txt" , splitlines = True )
126
+ doc_requires = get_content ("requirements-doc.txt" , splitlines = True )
127
+ setup_requires = get_content ("requirements-setup.txt" , splitlines = True )
128
+ install_requires = get_content ("requirements.txt" , splitlines = True )
129
+ if sys .version_info [:2 ] == (3 , 2 ):
130
+ # Hack for Python 3.2 because pip < 8 cannot handle version markers.
131
+ marker = '; python_version == "3.2"'
132
+ dev_requires = [
133
+ item .replace (marker , "" ) for item in dev_requires
134
+ if item .endswith (marker ) or "python_version" not in item ]
135
+ doc_requires = [
136
+ item .replace (marker , "" ) for item in doc_requires
137
+ if item .endswith (marker ) or "python_version" not in item ]
138
+ setup_requires = [
139
+ item .replace (marker , "" ) for item in setup_requires
140
+ if item .endswith (marker ) or "python_version" not in item ]
141
+ install_requires = [
142
+ item .replace (marker , "" ) for item in install_requires
143
+ if item .endswith (marker ) or "python_version" not in item ]
144
+
135
145
# To create the source .tar.gz file: python setup.py sdist
136
146
# To create the universal wheel file: python setup.py bdist_wheel --universal
137
147
setup (** {
@@ -190,9 +200,15 @@ def checkversion(directory):
190
200
"<4" ,
191
201
]),
192
202
"setup_requires" :
193
- get_content ( "requirements-setup.txt" , splitlines = True ) ,
203
+ setup_requires ,
194
204
"install_requires" :
195
- get_content ("requirements.txt" , splitlines = True ),
205
+ install_requires ,
206
+ "extras_require" : {
207
+ "dev" :
208
+ dev_requires ,
209
+ "doc" :
210
+ doc_requires ,
211
+ },
196
212
"project_urls" : {
197
213
"Bug Tracker" :
198
214
"https://github.com/matplotlib/basemap/issues" ,
0 commit comments