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

Fix bug in setup.py #747

Merged
merged 1 commit into from
Mar 31, 2016
Merged

Fix bug in setup.py #747

merged 1 commit into from
Mar 31, 2016

Conversation

ltiao
Copy link
Contributor

@ltiao ltiao commented Mar 30, 2016

On Mac OS X 10.11.4, with both Python 2.7.11 and Python 3.5.1, and the requirements installed (Cython 0.23.5, NumPy 1.11.0, geos 3.5.0, proj 4.9.2):

$ brew install geos
$ brew install proj
$ mkvirtualenv cartopy
(cartopy)$ pip install cython
(cartopy)$ pip install numpy

We get:

(cartopy)$ pip install cartopy
    [...]
    clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/include -I./lib/cartopy -I-I/usr/local/Cellar/proj/4.9.2/include -I/usr/local/Cellar/geos/3.5.0/include -I/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c lib/cartopy/trace.cpp -o build/temp.macosx-10.11-x86_64-2.7/lib/cartopy/trace.o
    lib/cartopy/trace.cpp:249:10: fatal error: 'proj_api.h' file not found
    #include "proj_api.h"
             ^
    1 error generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------

Note the relevant --include-dir (-I) flags above:

  • -I/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/include
  • -I./lib/cartopy
  • -I-I/usr/local/Cellar/proj/4.9.2/include
  • -I/usr/local/Cellar/geos/3.5.0/include
  • -I/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/include/python2.7

We see that the directory /usr/local/Cellar/proj/4.9.2/include has -I prepended twice.

Also, upon further inspection, proj_api.h does in fact exist in that directory:

$ ls /usr/local/Cellar/proj/4.9.2/include
geodesic.h              org_proj4_PJ.h          org_proj4_Projections.h proj_api.h              projects.h

Looking at line 260 of setup.py in the latest commit, we have

proj_includes = subprocess.check_output(['pkg-config', '--cflags', 'proj'])

Executing the command gives

$ pkg-config --cflags proj
-I/usr/local/Cellar/proj/4.9.2/include

And we find that we're able to install cartopy with no problems by supplying the following flags to pip:

$ pip install --global-option=build_ext --global-option=`pkg-config --cflags proj` cartopy
[...]
Installing collected packages: cartopy
  Running setup.py install for cartopy ... done
Successfully installed cartopy-0.13.0

It definitely looks like -I is being prepended to all elements of include_dirs on line 372:

include_dirs=[include_dir, './lib/cartopy'] + proj_includes + geos_includes,

and a look at the value of geos_includes (line 168) would confirm this:

>>> import subprocess
>>> geos_includes = subprocess.check_output(['geos-config', '--includes'])
>>> geos_includes.split()
['/usr/local/Cellar/geos/3.5.0/include']
>>> proj_includes = subprocess.check_output(['pkg-config', '--cflags', 'proj'])
>>> proj_includes.split()
['-I/usr/local/Cellar/proj/4.9.2/include']

Perhaps this behaviour of pkg-config specific to Mac OS X?

In any case, this PR would catch if the -I has been prepended and strip it first.

@ltiao
Copy link
Contributor Author

ltiao commented Mar 30, 2016

It seems the Travis builds all pass. Note that I have also tested this in my environment:

$ pip install git+https://github.com/ltiao/cartopy.git@patch-1#egg=cartopy
Collecting cartopy from git+https://github.com/ltiao/cartopy.git@patch-1#egg=cartopy
  Cloning https://github.com/ltiao/cartopy.git (to patch-1) to /private/var/folders/kh/ssj3c51d1xggf55cjdf61sb80000gp/T/pip-build-NAg5wD/cartopy
    [...]
Installing collected packages: cartopy
  Running setup.py install for cartopy ... done
Successfully installed cartopy-0.14.0

And all seems well :)

@@ -286,7 +286,10 @@ def find_proj_version_by_program(conda=None):
proj_includes = proj_includes.decode()
proj_clibs = proj_clibs.decode()

if proj_includes.startswith('-I'):
Copy link
Member

Choose a reason for hiding this comment

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

This only handles the case of the first path starting with -I, but what if there's more than one? You need to do this on each element of the list.

@ltiao
Copy link
Contributor Author

ltiao commented Mar 30, 2016

Fixed.

@QuLogic
Copy link
Member

QuLogic commented Mar 30, 2016

Thanks @ltiao; I believe you will need to sign the CLA before this is accepted.

Also, if you are comfortable with it, I think some of these commits could be squashed together.

Update contributors.rst
@ltiao
Copy link
Contributor Author

ltiao commented Mar 31, 2016

No probs. I squashed those commits and also I signed the CLA and emailed it to [email protected] just now. It there anything else I need to do?

@@ -31,6 +31,7 @@ the package wouldn't be as rich or diverse as it is today:
* Laura Dreyer
* Daniel Atton Beckmann
* Joseph Hogg
* Louis Tiao
Copy link
Member

Choose a reason for hiding this comment

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

👍

@pelson
Copy link
Member

pelson commented Mar 31, 2016

Thanks @ltiao! I think we just need confirmation in https://github.com/SciTools/scitools.org.uk/blob/gh-pages/contributors.json from the CLA body, and we are good to go.

👍

@marqh
Copy link
Member

marqh commented Mar 31, 2016

CLA processed

see
SciTools/scitools.org.uk#130

@pelson pelson merged commit 7998f87 into SciTools:master Mar 31, 2016
@pelson
Copy link
Member

pelson commented Mar 31, 2016

Thanks @marqh

@ltiao ltiao deleted the patch-1 branch March 31, 2016 13:03
@QuLogic QuLogic added this to the 0.14 milestone Mar 31, 2016
@QuLogic QuLogic modified the milestones: 0.14, 0.14.2 Apr 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants