Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use cythonized files in sdist. #1264

Merged
merged 6 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ env:
# These ancient versions are linked to an old libgfortran, but that version
# isn't pinned in the package metadata
- PYTHON_VERSION=2.7
PACKAGES="cython=0.17 numpy=1.10.0 matplotlib=1.5.1 nose proj4=4.9.1 scipy=0.16.0 libgfortran=1 mock futures"
PACKAGES="cython=0.* numpy=1.10.0 matplotlib=1.5.1 nose proj4=4.9.1 scipy=0.16.0 libgfortran=1 mock futures"
- PYTHON_VERSION=3.5
PACKAGES="cython=0.23.1 numpy=1.10.0 matplotlib=1.5.1 nose proj4=4.9.1 scipy=0.16.0 libgfortran=1"
PACKAGES="cython=0.* numpy=1.10.0 matplotlib=1.5.1 nose proj4=4.9.1 scipy=0.16.0 libgfortran=1"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future-proofing for Cython 3.

PYTHONHASHSEED=0 # So pytest-xdist works.
- NAME="Latest everything."
PYTHON_VERSION=3.6
Expand Down
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The recipes for these can be found at https://github.com/conda-forge/feedstocks.
**Python** 2.7 or later (https://www.python.org/)
Cartopy requires Python 2.7 or later.

**Cython** 0.17 or later (https://pypi.python.org/pypi/Cython/)
**Cython** 0.29 or later (https://pypi.python.org/pypi/Cython/)

**NumPy** 1.10 or later (http://www.numpy.org/)
Python package for scientific computing including a powerful N-dimensional
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ include lib/cartopy/data/*
include lib/cartopy/io/srtm.npz
include lib/cartopy/tests/lakes_shapefile/*
recursive-include lib *.py
recursive-include lib *.pyx *.pxd *.h
recursive-include lib *.pyx *.pxd *.h *.c *.cpp
include versioneer.py
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["setuptools", "wheel", "numpy>=1.10", "Cython>=0.17"]
requires = ["setuptools", "wheel", "numpy>=1.10"]
107 changes: 67 additions & 40 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@
import versioneer


try:
from Cython.Distutils import build_ext
except ImportError:
raise ImportError('Cython 0.17+ is required to install cartopy.')
# The existence of a PKG-INFO directory is enough to tell us whether this is a
# source installation or not (sdist).
HERE = os.path.dirname(__file__)
IS_SDIST = os.path.exists(os.path.join(HERE, 'PKG-INFO'))

if not IS_SDIST:
try:
from Cython.Distutils import build_ext
except ImportError:
raise ImportError(
"Cython 0.17+ is required to install cartopy from source.")

try:
import numpy as np
except ImportError:
Expand All @@ -52,8 +60,6 @@
GEOS_MIN_VERSION = (3, 3, 3)
PROJ_MIN_VERSION = (4, 9, 0)

HERE = os.path.dirname(__file__)


def file_walk_relative(top, remove=''):
"""
Expand Down Expand Up @@ -280,8 +286,9 @@ def find_proj_version_by_program(conda=None):
proj_includes = proj_includes.decode()
proj_clibs = proj_clibs.decode()

proj_includes = [proj_include[2:] if proj_include.startswith('-I') else
proj_include for proj_include in proj_includes.split()]
proj_includes = [
proj_include[2:] if proj_include.startswith('-I') else
proj_include for proj_include in proj_includes.split()]

proj_libraries = []
proj_library_dirs = []
Expand Down Expand Up @@ -321,13 +328,62 @@ def get_config_var(name):

# Description
# ===========

with open(os.path.join(HERE, 'README.md'), 'r') as fh:
description = ''.join(fh.readlines())


extensions = [
Extension(
'cartopy.trace',
['lib/cartopy/trace.pyx'],
include_dirs=([include_dir, './lib/cartopy', np.get_include()] +
proj_includes + geos_includes),
libraries=proj_libraries + geos_libraries,
library_dirs=[library_dir] + proj_library_dirs + geos_library_dirs,
language='c++',
**extra_extension_args),
Extension(
'cartopy._crs',
['lib/cartopy/_crs.pyx'],
include_dirs=[include_dir, np.get_include()] + proj_includes,
libraries=proj_libraries,
library_dirs=[library_dir] + proj_library_dirs,
**extra_extension_args),
# Requires proj v4.9
Extension(
'cartopy.geodesic._geodesic',
['lib/cartopy/geodesic/_geodesic.pyx'],
include_dirs=[include_dir, np.get_include()] + proj_includes,
libraries=proj_libraries,
library_dirs=[library_dir] + proj_library_dirs,
**extra_extension_args),
]


def decythonize(extensions, **_ignore):
# Remove pyx sources from extensions.
# Note: even if there are changes to the pyx files, they will be ignored.
for extension in extensions:
sources = []
for sfile in extension.sources:
path, ext = os.path.splitext(sfile)
if ext in ('.pyx',):
if extension.language == 'c++':
ext = '.cpp'
else:
ext = '.c'
sfile = path + ext
sources.append(sfile)
extension.sources[:] = sources
return extensions


cmdclass = versioneer.get_cmdclass()
cmdclass.update({'build_ext': build_ext})

if IS_SDIST:
extensions = decythonize(extensions)
else:
cmdclass.update({'build_ext': build_ext})


# Main setup
Expand Down Expand Up @@ -368,36 +424,7 @@ def get_config_var(name):


# requires proj headers
ext_modules=[
Extension(
'cartopy.trace',
['lib/cartopy/trace.pyx'],
include_dirs=([include_dir, './lib/cartopy', np.get_include()] +
proj_includes + geos_includes),
libraries=proj_libraries + geos_libraries,
library_dirs=[library_dir] + proj_library_dirs + geos_library_dirs,
language='c++',
**extra_extension_args
),
Extension(
'cartopy._crs',
['lib/cartopy/_crs.pyx'],
include_dirs=[include_dir, np.get_include()] + proj_includes,
libraries=proj_libraries,
library_dirs=[library_dir] + proj_library_dirs,
**extra_extension_args
),
# Requires proj v4.9
Extension(
'cartopy.geodesic._geodesic',
['lib/cartopy/geodesic/_geodesic.pyx'],
include_dirs=[include_dir, np.get_include()] + proj_includes,
libraries=proj_libraries,
library_dirs=[library_dir] + proj_library_dirs,
**extra_extension_args
),
],

ext_modules=extensions,
cmdclass=cmdclass,
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
classifiers=[
Expand Down