Repository: SciTools/cartopy

Issue:
build error: looking for lib/cartopy/trace.c when building 0.12.0 or 0.13.0
Trying to build cartopy-0.12.0 or cartopy-0.13.0 gives 

```
gcc -pthread -fno-strict-aliasing -O2 -g -D_GNU_SOURCE -fPIC -DNDEBUG -O2 -g -D_GNU_SOURCE -fPIC -fPIC -I/usr/include -I./lib/cartopy -I/usr/include -I/usr/include/python2.7 -c lib/cartopy/trace.c -o build/temp.linux-x86_64-2.7/lib/cartopy/trace.o
gcc: lib/cartopy/trace.c: No such file or directory
```

(This was build on 64-bit linux using python2.7.)

No such problem with 0.11.2 or earlier.

This might perhaps be trivial, as I have spent zero time investigating (other than to note that 0.11.2 doesn't have trace.c in the tarball either, but apparently not causing a problem). I will just use 0.11.2 for now and leave it to you.



Discussion:
The file `trace.c` should be generated by Cython at build time I think, rather than included with the distribution. Were there any other errors or warnings in the build?

Actually that isn't true, it should be `trace.cpp` generated by cython...

No other errors. Pasting some lines leading up to it

```
+ python2.7 setup.py build
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/cartopy

[... snip ...]

creating build/lib.linux-x86_64-2.7/cartopy/data/shapefiles/gshhs/c
copying lib/cartopy/data/shapefiles/gshhs/c/GSHHS_c_L1.shp -> build/lib.linux-x86_64-2.7/cartopy/data/shapefiles/gshhs/c
copying lib/cartopy/data/shapefiles/gshhs/c/GSHHS_c_L1.dbf -> build/lib.linux-x86_64-2.7/cartopy/data/shapefiles/gshhs/c
copying lib/cartopy/data/shapefiles/gshhs/c/GSHHS_c_L1.shx -> build/lib.linux-x86_64-2.7/cartopy/data/shapefiles/gshhs/c
copying lib/cartopy/io/srtm.json -> build/lib.linux-x86_64-2.7/cartopy/io
running build_ext
building 'cartopy.trace' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/lib
creating build/temp.linux-x86_64-2.7/lib/cartopy
gcc -pthread -fno-strict-aliasing -O2 -g -D_GNU_SOURCE -fPIC -DNDEBUG -O2 -g -D_GNU_SOURCE -fPIC -fPIC -I/usr/include -I./lib/cartopy -I/usr/include -I/usr/include/python2.7 -c lib/cartopy/trace.c -o build/temp.linux-x86_64-2.7/lib/cartopy/trace.o
gcc: lib/cartopy/trace.c: No such file or directory
gcc: no input files
error: command 'gcc' failed with exit status 1
```

Do you have setuptools installed?

Version 0.11.2 didn't use setuptools for build, but later versions can. I think it is supposed to be optional, falling back to distutils if not found, but it is possible there is a problem associated with this.

Yes, setuptools is installed for the python in question (python 2.7).

(Also noting that the system default python, /usr/bin/python, which I am not using here, is 2.6 and does not have setuptools. Using 'strace' confirms that there is no attempt to run this 2.6 executable.)

strace also confirms that it is finding and using the setuptools in question. For example:

```
[pid  5703] open("/usr/lib/python2.7/site-packages/setuptools/__init__.py", O_RDONLY) = 3
```

OK thanks. I'm struggling to reproduce the issue, which version of setuptools do you have installed?

`__version__` reports '0.6c12', and the full filename of the tarball is setuptools-0.6c12dev-r88846.tar.gz

(I am using it in the form of an RPM built for use with 2.7, which was necessarily home-built because the RPMs in standard repositories are for use with the default python 2.6. This is part of what we call the JASMIN Analysis Platform.)

setuptools and cartopy both built (or attempted to be built) just with vanilla:

```
python2.7 setup.py build
python2.7 setup.py install
```

(plus from a `--root` option on the install to write to a temporary directory, as required by the RPM build process, though after installation of the resulting RPM it ends up back in the default location)

OK I can reproduce the issue with an older version of setuptools (0.6c11). It looks like something is going wrong when this version of setuptools tries to build the module. A work-around is to edit the `setup.py` script to force it to use use `distutils` instead of `setuptools` (comment out the try/except block and just import `setup` and `Extension` from `distutils`).

Version 0.6c12 of setuptools is very old, in fact it was the version before setuptools and distribute were merged, the current version is 18.0.1. It is possible that the error is because we need features that were actually present in distribute at the time of the 0.6c12 setuptools release... I'm not sure if a workaround will be put in cartopy, what do you think @pelson? We could work out which version is required and fall back, or just be clearer when stating our requirements?

It looks like the JASMIN Analysis Platform is on RHEL6. Instead of building your own Python, can you not enable the [RedHat Software Collection for Python 2.7](https://www.softwarecollections.org/en/scls/rhscl/python27/) (also available for Python 3)? It contains Python 2.7 and a new-ish setuptools.

Thank you.  At a later point, we can use a later setuptools (probably which I will build to go with my existing Python, as changing the Python would require everything else to be rebuilt) and then try to install the later cartopy. For now, cartopy 0.11.2 is sufficient to support a user request for updated Iris, so upgrading beyond this is not an urgent priority. I am now closing this issue on the assumption that a later setuptools will enable us to upgrade cartopy when required. Thanks again for your help.

Noting that cartopy 0.13 builds cleanly using setuptools 18.2 (under python 2.7).

Noting also that upgrading to cartopy > 0.11 has hit a snag unrelated to cartopy itself, as described at https://github.com/cedadev/jasmin_scivm/issues/27, that I'll deal with when I have time.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -21,14 +21,11 @@
 
 """
 
-try:
-    from setuptools import setup, Extension
-except ImportError:
-    from distutils.core import setup, Extension
-from distutils.core import Command
+from setuptools import setup, Extension
+from setuptools import Command
+from setuptools import convert_path
 from distutils.spawn import find_executable
 from distutils.sysconfig import get_config_var
-from distutils.util import convert_path
 import fnmatch
 import os
 import subprocess
@@ -382,8 +379,8 @@ def get_config_var(name):
 	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    
+            library_dirs=[library_dir] + proj_library_dirs,
+            **extra_extension_args
         ),
     ],
 


Test patch: