~libecbufr-dev/libecbufr/trunk

« back to all changes in this revision

Viewing changes to Bindings/python/setup.py

  • Committer: vanh.souvanlasy at canada
  • Date: 2019-11-05 21:50:59 UTC
  • Revision ID: vanh.souvanlasy@canada.ca-20191105215059-0a0yolehj3jcmm67
add python bindings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# build script for 'ecbufr' - Python libecbufr wrapper
 
3
#
 
4
import sys, os
 
5
from distutils.core import setup
 
6
from distutils.extension import Extension
 
7
 
 
8
libecbufrDir = os.path.dirname(os.getcwd())
 
9
libecbufrDir = os.path.dirname(libecbufrDir)
 
10
libecbufrIncludeDir = libecbufrDir + "/API/Headers"
 
11
libecbufrLibDir = libecbufrDir + "/API/Sources/.libs"
 
12
 
 
13
# we'd better have Cython installed, or it's a no-go
 
14
try:
 
15
    from Cython.Distutils import build_ext
 
16
except:
 
17
    print("libecbufr directory:", libecbufrDir )
 
18
    print("You don't seem to have Cython installed. Please get a")
 
19
    print("copy from www.cython.org and install it")
 
20
    sys.exit(1)
 
21
 
 
22
 
 
23
# scan the 'ecbufr' directory for extension files, converting
 
24
# them to extension names in dotted notation
 
25
def scandir(dir, files=[]):
 
26
    for file in os.listdir(dir):
 
27
        path = os.path.join(dir, file)
 
28
        if os.path.isfile(path) and path.endswith(".pyx"):
 
29
            files.append(path.replace(os.path.sep, ".")[:-4])
 
30
        elif os.path.isdir(path):
 
31
            scandir(path, files)
 
32
    return files
 
33
 
 
34
 
 
35
# generate an Extension object from its dotted name
 
36
def makeExtension(extName):
 
37
    extPath = extName.replace(".", os.path.sep)+".pyx"
 
38
    return Extension(
 
39
        extName,
 
40
        [extPath],
 
41
        include_dirs = [libecbufrIncludeDir, "."],   # adding the '.' to include_dirs is CRUCIAL!!
 
42
        library_dirs = [libecbufrLibDir, "."],   # adding the '.' to include_dirs is CRUCIAL!!
 
43
        extra_compile_args = ["-fPIC", "-Wall"],
 
44
        extra_link_args = ['-g'],
 
45
        libraries = ["ecbufr",],
 
46
        )
 
47
 
 
48
# get the list of extensions
 
49
extNames = scandir("ecbufr")
 
50
 
 
51
# and build up the set of Extension objects
 
52
extensions = [makeExtension(name) for name in extNames]
 
53
 
 
54
# finally, we can pass all this to distutils
 
55
setup(
 
56
  name="ecbufr",
 
57
  packages=["ecbufr"],
 
58
  ext_modules=extensions,
 
59
  cmdclass = {'build_ext': build_ext},
 
60
)