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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
import os
import errno
import subprocess
import sys
from setuptools import setup, find_packages
from setuptools.extension import Extension
from setuptools.command.build_ext import build_ext
from distutils.errors import DistutilsPlatformError
install_requires = [
'imposm.parser',
'psycopg2',
'Shapely',
]
if sys.version_info < (2, 6):
install_requires.append('multiprocessing')
class build_ext_with_cython(build_ext):
def generate_c_file(self):
try:
if (os.path.exists('imposm/cache/tc.c') and
os.path.getmtime('imposm/cache/tc.pyx') < os.path.getmtime('imposm/cache/tc.c')):
print 'imposm/cache/tc.c up to date'
return
print 'creating imposm/cache/tc.c'
proc = subprocess.Popen(
['cython', 'imposm/cache/tc.pyx'],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except OSError, ex:
if ex.errno == errno.ENOENT:
print "Could not find cython command."
raise DistutilsPlatformError("Failed to generate "
"C files with cython.")
else:
raise
out = proc.communicate()[0]
result = proc.wait()
if result != 0:
print "Error during C files generation with cython:"
print out
raise DistutilsPlatformError("Failed to generate "
"C files with cython.")
def generate_protoc(self):
try:
if (os.path.exists('imposm/cache/internal.pb.cc') and
os.path.getmtime('internal.proto') < os.path.getmtime('imposm/cache/internal.pb.cc')):
print 'imposm/cache/internal.pb.cc up to date'
return
print 'creating protofiles'
proc = subprocess.Popen(
['protoc', '--cpp_out', 'imposm/cache/', 'internal.proto'],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except OSError, ex:
if ex.errno == errno.ENOENT:
print ("Could not find protoc command. Make sure protobuf is "
"installed and your PATH environment is set.")
raise DistutilsPlatformError("Failed to generate protbuf "
"CPP files with protoc.")
else:
raise
out = proc.communicate()[0]
result = proc.wait()
if result != 0:
print "Error during protbuf files generation with protoc:"
print out
raise DistutilsPlatformError("Failed to generate protbuf "
"CPP files with protoc.")
def run(self):
self.generate_protoc()
try:
self.generate_c_file()
except DistutilsPlatformError:
if os.path.exists('imposm/cache/tc.c'):
print 'Found existing C file. Ignoring previous error.'
else:
raise
build_ext.run(self)
import imposm.version
version = imposm.version.__version__
setup(
name = "imposm",
version = version,
description='OpenStreetMap importer for PostGIS.',
long_description=open('README.rst').read() + open('CHANGES').read(),
author = "Oliver Tonnhofer",
author_email = "olt@omniscale.de",
url='http://imposm.org/',
license='Apache Software License 2.0',
packages=find_packages(),
namespace_packages = ['imposm'],
include_package_data=True,
package_data = {'': ['*.xml']},
install_requires=install_requires,
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: C",
"Programming Language :: C++",
"Programming Language :: Python :: 2.5",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Topic :: Scientific/Engineering :: GIS",
],
ext_modules=[
Extension("imposm.cache.tc", ["imposm/cache/tc.c"], libraries = ["tokyocabinet"]),
Extension("imposm.cache.internal", ["imposm/cache/internal.cc", "imposm/cache/internal.pb.cc"], libraries = ["protobuf"]),
],
entry_points = {
'console_scripts': [
'imposm = imposm.app:main',
'imposm-psqldb = imposm.psqldb:main',
],
},
cmdclass={'build_ext':build_ext_with_cython},
)
|