forked from SciTools/cartopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
181 lines (146 loc) · 6.18 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
# (C) British Crown Copyright 2011 - 2012, Met Office
#
# This file is part of cartopy.
#
# cartopy is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cartopy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with cartopy. If not, see <http://www.gnu.org/licenses/>.
"""
Distribution definition for Cartopy.
"""
from distutils.core import setup, Command, Extension
from distutils.sysconfig import get_config_var
from distutils.util import convert_path
import fnmatch
import os
import sys
from Cython.Distutils import build_ext
import numpy as np
if sys.platform.startswith('win'):
def get_config_var(name):
return '.'
geos = 'geos'
extra_extension_args = {}
else:
geos = 'geos_c'
extra_extension_args = dict(runtime_library_dirs=[get_config_var('LIBDIR')])
def file_walk_relative(top, remove=''):
"""
Returns a generator of files from the top of the tree, removing
the given prefix from the root/file result.
"""
for root, dirs, files in os.walk(top):
for file in files:
yield os.path.join(root, file).replace(remove, '')
def find_package_tree(root_path, root_package):
"""
Returns the package and all its sub-packages.
Automated package discovery - extracted/modified from Distutils Cookbook:
http://wiki.python.org/moin/Distutils/Cookbook/AutoPackageDiscovery
"""
packages = [root_package]
root_count = len(root_path.split('/'))
for (dir_path, dir_names, _) in os.walk(convert_path(root_path)):
# Prune dir_names *in-place* to prevent unwanted directory recursion
for dir_name in list(dir_names):
if not os.path.isfile(os.path.join(dir_path, dir_name, '__init__.py')):
dir_names.remove(dir_name)
if dir_names:
prefix = dir_path.split('/')[root_count:]
packages.extend(['.'.join([root_package] + prefix + [dir_name]) for dir_name in dir_names])
return packages
class MissingHeaderError(Exception):
"""
Raised when one or more files do not have the required copyright
and licence header.
"""
pass
class HeaderCheck(Command):
"""
Checks that all the necessary files have the copyright and licence
header.
"""
description = "check for copyright/licence headers"
user_options = []
exclude_patterns = ('./setup.py',
'./build/*',
'./docs/build/*',
'./dist/*',
'./lib/cartopy/examples/*.py')
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
check_paths = []
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.py') or file.endswith('.c'):
path = os.path.join(root, file)
check_paths.append(path)
for pattern in self.exclude_patterns:
exclude = lambda path: not fnmatch.fnmatch(path, pattern)
check_paths = list(filter(exclude, check_paths))
bad_paths = list(filter(self._header_bad, check_paths))
if bad_paths:
raise MissingHeaderError(bad_paths)
def _header_bad(self, path):
target = '(C) British Crown Copyright 2011 - 2012, Met Office'
with open(path, 'rt') as text_file:
# Check for the header on the first line.
line = text_file.readline().rstrip()
bad = target not in line
# Check if it was an executable script, with the header
# starting on the second line.
if bad and line == '#!/usr/bin/env python':
line = text_file.readline().rstrip()
bad = target not in line
return bad
setup(
name='Cartopy',
version='0.12.x',
url='http://github.com/SciTools/cartopy',
author='UK Met Office',
packages=find_package_tree('lib/cartopy', 'cartopy'),
package_dir={'': 'lib'},
package_data={'cartopy': list(file_walk_relative('lib/cartopy/tests/mpl/baseline_images/',
remove='lib/cartopy/')) +\
list(file_walk_relative('lib/cartopy/data/raster',
remove='lib/cartopy/')) +\
list(file_walk_relative('lib/cartopy/data/netcdf',
remove='lib/cartopy/')) +\
list(file_walk_relative('lib/cartopy/data/wmts',
remove='lib/cartopy/')) +\
list(file_walk_relative('lib/cartopy/data/shapefiles/natural_earth',
remove='lib/cartopy/')) +\
list(file_walk_relative('lib/cartopy/data/shapefiles/gshhs',
remove='lib/cartopy/')) +\
['io/srtm.json']
},
# requires proj4 headers
ext_modules=[
Extension('cartopy.trace', ['lib/cartopy/trace.pyx', 'lib/cartopy/_trace.cpp'],
include_dirs=[get_config_var('INCLUDEDIR'), './lib/cartopy'],
libraries=[geos, 'proj'],
library_dirs=[get_config_var('LIBDIR')],
language='c++',
**extra_extension_args
),
Extension('cartopy._crs', ['lib/cartopy/_crs.pyx'],
include_dirs=[get_config_var('INCLUDEDIR'), np.get_include()],
libraries=['proj'],
library_dirs=[get_config_var('LIBDIR')],
**extra_extension_args
),
],
cmdclass={'build_ext': build_ext, 'header_check': HeaderCheck},
)