Skip to content

Commit

Permalink
Merge pull request #1264 from pelson/cython_optional
Browse files Browse the repository at this point in the history
Always use cythonized files in sdist.
  • Loading branch information
QuLogic authored Jan 16, 2019
2 parents 427de4f + 76386a5 commit 81e40e6
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:
PACKAGES: "cython numpy matplotlib-base proj4 pykdtree scipy"
- PYTHON_VERSION: "2.7"
CONDA_INSTALL_LOCN: "C:\\Miniconda-x64"
PACKAGES: "cython=0.17 numpy=1.10.0 matplotlib=1.5.1 nose proj4=4.9.1 scipy=0.16.0 mock msinttypes futures"
PACKAGES: "cython=0.28 numpy=1.10.0 matplotlib=1.5.1 nose proj4=4.9.1 scipy=0.16.0 mock msinttypes futures"

install:
# Install miniconda
Expand Down
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.28 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.28 numpy=1.10.0 matplotlib=1.5.1 nose proj4=4.9.1 scipy=0.16.0 libgfortran=1"
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.28 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
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ include CHANGES
include COPYING*
include INSTALL
include README.rst
include pyproject.toml
include requirements/*.txt
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
4 changes: 2 additions & 2 deletions lib/cartopy/trace.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2011 - 2018, Met Office
# (C) British Crown Copyright 2011 - 2019, Met Office
#
# This file is part of cartopy.
#
Expand Down Expand Up @@ -170,7 +170,7 @@ cdef class LineAccumulator:
&geoms[0], geoms.size())
return geom

cdef list[Line].size_type size(self):
cdef size_t size(self):
return self.lines.size()


Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml

This file was deleted.

111 changes: 70 additions & 41 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2011 - 2018, Met Office
# (C) British Crown Copyright 2011 - 2019, Met Office
#
# This file is part of cartopy.
#
Expand Down Expand Up @@ -36,10 +36,20 @@
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:
import Cython
if Cython.__version__ < '0.28':
raise ImportError(
"Cython 0.28+ is required to install cartopy from source.")

from Cython.Distutils import build_ext as cy_build_ext


try:
import numpy as np
except ImportError:
Expand All @@ -52,8 +62,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 +288,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 +330,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': cy_build_ext})


# Main setup
Expand Down Expand Up @@ -368,36 +426,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

0 comments on commit 81e40e6

Please sign in to comment.