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
|
# Copyright Crown and Cartopy Contributors
#
# This file is part of Cartopy and is released under the BSD 3-clause license.
# See LICENSE in the root of the repository for full licensing details.
import os
from pathlib import Path
import numpy as np
from setuptools import Extension, setup
# The existence of a PKG-INFO directory is enough to tell us whether this is a
# source installation or not (sdist).
HERE = Path(__file__).parent
IS_SDIST = (HERE / 'PKG-INFO').exists()
FORCE_CYTHON = os.environ.get('FORCE_CYTHON', False)
USE_CYTHON = not IS_SDIST or FORCE_CYTHON
if USE_CYTHON:
import Cython
if Cython.__version__ < '0.29':
raise ImportError(
"Cython 0.29+ is required to install cartopy from source.")
ext = '.pyx'
else:
ext = '.cpp'
# Macros to enable Cython coverage
define_macros = []
if os.environ.get('CYTHON_COVERAGE'):
define_macros.append(('CYTHON_TRACE_NOGIL', '1'))
extensions = [
Extension(
'cartopy.trace',
[f'lib/cartopy/trace{ext}'],
include_dirs=[np.get_include()],
language='c++',
define_macros=define_macros),
]
if USE_CYTHON:
# We need to explicitly cythonize the extension in order
# to control the Cython compiler_directives.
from Cython.Build import cythonize
compiler_directives = {"profile": True, "linetrace": True}
extensions = cythonize(extensions, compiler_directives=compiler_directives)
# Main setup
# ==========
setup(
ext_modules=extensions,
)
|