source: trunk/setup_no_autotools.py

Last change on this file was 354, checked in by bas, 8 years ago

added another way to install pbs_python. Thanks to

  • stijn.deweirdt@… and ewan.higgs@…

sligtly modifiied, see #41

File size: 3.7 KB
Line 
1#!/usr/bin/env python
2#
3# $Id: setup.py 434 2005-11-04 15:02:07Z bas $
4#
5# set ts=4
6#
7
8"""
9Based on setup.py from https://github.com/ehiggs/pbs-python
10@author: Ewan Higgs
11"""
12
13import sys
14import os
15import glob
16import subprocess
17import re
18
19from distutils.core import setup, Extension
20from distutils.version import LooseVersion
21
22SOURCE_DIR = 'src'
23
24def pbs_config():
25    return 'pbs-config'
26
27def pbs_library_compile_line(pbs_conf):
28    out, err = subprocess.Popen([pbs_conf,  '--libs'], stdout=subprocess.PIPE).communicate()
29    return out.rstrip()
30
31def pbs_library(pbs_conf):
32    out, err = subprocess.Popen([pbs_conf, '--libs'], stdout=subprocess.PIPE).communicate()
33    stripped_prefix = out[2:].rstrip() #'-l'
34    return stripped_prefix
35
36def pbs_library_dir(pbs_conf):
37    out, err = subprocess.Popen([pbs_conf, '--libdir'], stdout=subprocess.PIPE).communicate()
38    return out.rstrip()
39
40def pbs_version(pbs_conf):
41    out, err = subprocess.Popen([pbs_conf, '--version'], stdout=subprocess.PIPE).communicate()
42    return out.rstrip()
43
44def my_version():
45    """Extract current version from configure.in"""
46    conf_in = os.path.join(os.path.dirname(__file__), 'configure.in')
47    txt = open(conf_in).read()
48    # patttern is AC_INIT([pbs-python], [4.6.1])
49    reg =  re.compile(r'^AC_INIT\(\[pbs-python\],\s*\[(\d+\.\d+(?:\.\d+)?)\]\)', re.M)
50    found = reg.search(txt)
51    if found:
52        return found.group(1)
53    else:
54        raise Exception("Unable to determine pbs_python version from configure.in at %s" % conf_in)
55
56if __name__ == '__main__':
57    pbs_conf = pbs_config()
58    PBS_LIB_COMPILE_LINE=pbs_library_compile_line(pbs_conf)
59    PBS_LIB_DIR=pbs_library_dir(pbs_conf)
60    PBS_LIBS = pbs_library(pbs_conf)
61
62    PBS_VERSION = pbs_version(pbs_conf)
63    VERSION = my_version()
64
65    try:
66        os.unlink('src/pbs.py')
67    except OSError:
68        pass
69
70    if LooseVersion(PBS_VERSION) >= LooseVersion('5.0'):
71        TORQUE_VERSION='TORQUE_5'
72        SOURCE_FILE='src/5.x/pbs_wrap.cxx'
73        PBS_PYTHON_INCLUDE_DIR = 'src/5.x'
74
75        if not os.path.exists(os.path.join(PBS_PYTHON_INCLUDE_DIR,'log.h')):
76            print 'Failed to find log.h in include dir %s. (Set include dir via PBS_PYTHON_INCLUDEDIR variable)'%inc
77            sys.exit(2)
78
79        for fn in glob.glob('*.h'):
80            os.remove(fn)
81
82        os.symlink('5.x/pbs.py', 'src/pbs.py')
83
84    elif LooseVersion(PBS_VERSION) >= LooseVersion('4.2'):
85        TORQUE_VERSION='TORQUE_4'
86        SOURCE_FILE='src/C++/pbs_wrap.cxx'
87        PBS_PYTHON_INCLUDE_DIR = 'src/C++'
88
89        os.symlink('C++/pbs.py', 'src/pbs.py')
90
91    elif LooseVersion(PBS_VERSION) >= LooseVersion('2.4'):
92        TORQUE_VERSION='TORQUE_2'
93        SOURCE_FILE='src/C/pbs_wrap.c'
94        PBS_PYTHON_INCLUDE_DIR = 'src/C'
95        # Older pbs-config yielded some link line info instead of just the libraries
96        PBS_LIBS = 'torque'
97
98        os.symlink('C/pbs.py', 'src/pbs.py')
99
100    else:
101        print "Version: %s is not supported" %(PBS_VERSION)
102        sys.exit(1)
103
104    INCLUDE_DIR = '/usr/include/torque'
105
106    setup (
107        name = 'pbs_python',
108        version = VERSION,
109        description = 'openpbs/torque python interface',
110        license = 'LGPLV3',
111        author = 'Bas van der Vlies',
112        author_email = 'bas.vandervlies@surfsara.nl',
113        url = 'http://oss.trac.surfsara.nl/pbs_python',
114
115
116        extra_path = 'pbs',
117            package_dir = { '' : SOURCE_DIR },
118            py_modules = [ 'pbs',  'PBSQuery' ],
119
120        ext_modules = [
121            Extension( '_pbs', [SOURCE_FILE],
122                define_macros =  [ (TORQUE_VERSION, None) ],
123                include_dirs = [ INCLUDE_DIR, PBS_PYTHON_INCLUDE_DIR ],
124                library_dirs = [ PBS_LIB_DIR ],
125                libraries = [ PBS_LIBS ],
126                )
127        ]
128    )
Note: See TracBrowser for help on using the repository browser.