File: setup.py

package info (click to toggle)
ocempgui 0.2.8-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,464 kB
  • ctags: 1,849
  • sloc: python: 9,304; ansic: 6,849; makefile: 179
file content (289 lines) | stat: -rw-r--r-- 9,764 bytes parent folder | download | duplicates (2)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/env python

# $Id: setup.py,v 1.36.2.15 2007/09/23 07:37:48 marcusva Exp $
# setup script for ocempgui

import distutils.sysconfig
from distutils.core import setup, Extension
from distutils.command.install_data import install_data
import os, sys, glob, time

VERSION = "0.2.8"

# Minimum requirements.
ATK_MINIMUM = "1.18.0"
PYGAME_MINIMUM = (1, 7, 1)
PYTHON_MINIMUM = (2, 3)

PAPI_VERSION = "\"0.0.5\""
PAPI_DEBUG = "1"

##
# General configuration stuff.
##
def check_pkgconfig ():
    """Checks for the pkg-config utility."""
    if sys.platform == "win32":
        return os.system ("pkg-config > NUL") == 0
    else:
        return os.system ("pkg-config 2> /dev/null") == 256

def pkg_get_flags (package, flags, repl=None):
    """Gets the general compiler flags for a specific package using the
    pkg-config utility."""
    pipe = os.popen ("pkg-config %s %s" % (flags, package), "r")
    data = pipe.readline ().strip ()
    pipe.close ()
    if repl:
        return data.replace (repl, "").split ()
    return data.split ()

def pkg_get_all_cflags (name):
    """Gets all necessary flags for a compiler using the pkg-config
    utility."""
    return pkg_get_flags (name, "--cflags-only-I", "-I"), \
           pkg_get_flags (name, "--libs-only-L", "-L"), \
           pkg_get_flags (name, "--libs-only-l", "-l")

def get_directory_list (base):
    """Gets a list of subdirectories for the given base path."""
    # Get the needed ocempgui directory.
    realpath = os.path.split (os.path.abspath (sys.argv[0]))[0]

    # First get all the directories.
    paths = glob.glob (os.path.join (realpath, base, "*"))
    dirpaths = []
    for x in paths:
        if os.path.isdir (x):
            dirpaths += get_directory_list (os.path.join (base, x))

    # Although this should not happen, guarantee, that there is no CVS
    # target.
    dirpaths = [x for x in dirpaths if x.find ("CVS") == -1]

    # Do not forget the main directory.
    dirpaths = [os.path.join (realpath, base)] + dirpaths
    return dirpaths

def get_installation_files (base, installpath, filedict):
    """Create a nice list from it suitable for the data_files section of the
    distutils setup."""
    # Get the needed ocempgui directory.
    realpath = os.path.split (os.path.abspath (sys.argv[0]))[0]

    filelist = []
    for key in filedict:
        # We also need to get rid of the current directory prefix and
        # set it it to the correct installation prefix.
        try:
            path = key.split (os.path.join (realpath, base, ""))[1]
        except IndexError:
            # We got the main directory.
            path = ""
        path = os.path.join (installpath, path)

        # Add the files.
        files = []
        for installfile in filedict[key]:
            installfile = installfile.split (os.path.join (realpath, ""), 1)[1]
            files.append (installfile)
        filelist.append ((path, files))
    return filelist

##
# Installation routines.
##
def adjust_paths (datadir, files):
    """Adjusts the datadir paths in the style using files."""
    path = os.path.join (datadir, "share", "python-ocempgui")

    for f in files:
        fd = open (f, "r+")
        lines = fd.readlines ()
        for i, l in enumerate (lines):
            lines[i] = l.replace ("@DATAPATH@", path)
        fd.seek (0)
        fd.writelines (lines)
        fd.close ()

class InstallData (install_data):
    """Overrides the install_data behaviour to adjust the data paths."""
    def run (self):
        install_lib = self.get_finalized_command ("install_lib")
        bdist = self.get_finalized_command ("bdist")
        files = [os.path.join (install_lib.install_dir, "ocempgui", "widgets",
                               "Constants.py")]

        binary = False
        isrpm = False
        iswininst = False

        print bdist.bdist_base, self.install_dir

        for entry in sys.argv[1:]:
            if entry.startswith ("bdist"):
                binary = True
                if entry == "bdist_wininst":
                    iswininst = True
                elif entry == "bdist_rpm":
                    isrpm = True
            elif entry == "--format=rpm":
                isrpm = True
            elif entry == "--format=wininst":
                iswininst = True
    
        # Binary distribution build.
        if binary:
            path = bdist.bdist_base
            if isrpm:
                path = os.path.join (path, "rpm")
            elif iswininst:
                path = os.path.join (path, "wininst")
            else:
                path = os.path.join (path, "dumb")
            adjust_paths (self.install_dir.replace(path, ""), files)
        else:
            adjust_paths ("/usr", files)
        install_data.run (self)

        # Update the .pyc file (s).
        install_lib.byte_compile (files)

def get_papi_defines ():
    """Builds the defines list for the C Compiler."""
    val = [("DEBUG", PAPI_DEBUG), ("VERSION", PAPI_VERSION)]
    if sys.platform == "win32":
        val.append (("IS_WIN32", "1"))
    return val

def get_papi_files ():
    """Gets the list of file to use for building the papi accessibility
    module."""
    path = os.path.join ("ocempgui", "access", "papi")
    files = glob.glob (os.path.join (path, "*.c"))
    return files

def get_data_files ():
    """Gets a list of the files beneath data/ to install."""
    installpath = os.path.join ("share", "python-ocempgui")
    path = "data"
    dirs = get_directory_list (path)
    filedict = {}
    for path in dirs:
        files = glob.glob (os.path.join (path, "*.*"))
        if files:
            filedict[path] = files
    return get_installation_files ("data", installpath, filedict)

def get_documentation_files ():
    """Gets a list of files to install as documentation."""
    installpath = os.path.join ("share", "doc", "ocempgui-doc")
    docpaths = get_directory_list ("doc")

    # Traverse all the directories in the docpath an get the needed files.
    # Every file installed from the docs will have a suffix.
    filedict = {}
    for path in docpaths:
        files = glob.glob (os.path.join (path, "*.*"))
        if files:
            filedict[path] = files
    return get_installation_files ("doc", installpath, filedict)

def run_checks ():
    # Python version check.
    if sys.version_info < PYTHON_MINIMUM: # major, minor check
        raise Exception ("You should have at least Python >= %d.%d.x "
                         "installed." % PYTHON_MINIMUM)

    # Pygame versioning checks.
    pygame_version = None
    try:
        import pygame
        if pygame.version.vernum < PYGAME_MINIMUM:
            raise Exception ("You should have at least Pygame >= %d.%d.%d "
                             "installed" % PYGAME_MINIMUM)
	pygame_version = pygame.version.ver
    except ImportError:
        pass

    # Environment checks for the PAPI interfaces.
    papi = False
    atk_version = "not found"
    if not check_pkgconfig ():
        papi = False
    else:
        val = pkg_get_flags ("atk", "--modversion")
        if val:
            atk_version = val[0]
            if atk_version >= ATK_MINIMUM:
                papi = True

    print "\nThe following information will be used to build OcempGUI:"
    print "\t Python:     %d.%d.%d" % sys.version_info[0:3]
    print "\t Pygame:     %s" % pygame_version
    print "\t ATK:        %s" % atk_version
    print "\t Build Papi: %s\n" % papi

    return papi

if __name__ == "__main__":

    want_papi = False
    try:
        want_papi = run_checks ()
    except Exception, detail:
        print "Error:", detail
        sys.exit (1)

    docfiles = get_documentation_files ()
    datafiles = get_data_files ()

    setupdata = {
        "name" :  "OcempGUI",
        "version" : VERSION,
        "description": "Ocean Empire User Interface Library",
        "author": "Marcus von Appen",
        "author_email": "marcus@sysfault.org",
        "license": "BSD license",
        "url": "http://ocemp.sourceforge.net/gui.html",
        "packages": ["ocempgui",
                     "ocempgui.access",
                     "ocempgui.draw",
                     "ocempgui.events",
                     "ocempgui.object",
                     "ocempgui.widgets",
                     "ocempgui.widgets.components",
                     "ocempgui.widgets.images"],
        "data_files" : datafiles + docfiles,
        "cmdclass" : { "install_data" : InstallData },
        }

    if not want_papi:
        # Do not build the accessibility extension.
        setup (**setupdata)
    else:
        # Try to build the setup with the extension.
        includes, libdirs, libs = pkg_get_all_cflags ("atk")
        gmodflags = pkg_get_all_cflags ("gmodule-2.0")
        includes += gmodflags[0]
        libdirs += gmodflags[1]
        libs += gmodflags[2]
        includes += distutils.sysconfig.get_python_inc ()

        defines = get_papi_defines ()
    
        warn_flags = ["-W", "-Wall", "-Wpointer-arith", "-Wcast-qual",
                      "-Winline", "-Wcast-align", "-Wconversion",
                      "-Wstrict-prototypes", "-Wmissing-prototypes",
                      "-Wmissing-declarations", "-Wnested-externs",
                      "-Wshadow", "-Wredundant-decls"
                      ]
        compile_args = warn_flags + ["-std=c99","-g"]
        papi = Extension ("ocempgui.access.papi", sources=get_papi_files (),
                          include_dirs=includes, library_dirs=libdirs,
                          libraries=libs, language="c",
                          define_macros=defines,
                          extra_compile_args=compile_args)
  
        setupdata["ext_modules"] = [papi]
        setup (**setupdata)