~ubuntu-branches/ubuntu/gutsy/pygame/gutsy

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Bazaar Package Importer
  • Author(s): Ed Boraas
  • Date: 2002-02-20 06:39:24 UTC
  • Revision ID: james.westby@ubuntu.com-20020220063924-amlzj7tqkeods4eq
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# This is the distutils setup script for pygame.
 
4
# Full instructions are in "docs/fullinstall.txt"
 
5
#
 
6
# To configure, compile, install, just run this script.
 
7
 
 
8
DESCRIPTION = """Pygame is a Python wrapper module for the
 
9
SDL multimedia library. It contains python functions and classes
 
10
that will allow you to use SDL's support for playing cdroms,
 
11
audio and video output, and keyboard, mouse and joystick input."""
 
12
 
 
13
METADATA = {
 
14
    "name":             "pygame",
 
15
    "version":          "1.4",
 
16
    "license":          "LGPL",
 
17
    "url":              "http://www.pygame.org",
 
18
    "author":           "Pete Shinners",
 
19
    "author_email":     "pygame@seul.org",
 
20
    "description":      "Python Game Development",
 
21
    "long_description": DESCRIPTION,
 
22
}
 
23
 
 
24
try:
 
25
    import distutils
 
26
except ImportError:
 
27
    raise SystemExit, "Pygame requires distutils to build and install."
 
28
 
 
29
 
 
30
#get us to the correct directory
 
31
import os, sys
 
32
path = os.path.split(os.path.abspath(sys.argv[0]))[0]
 
33
os.chdir(path)
 
34
 
 
35
 
 
36
 
 
37
import os.path, glob
 
38
import distutils.sysconfig 
 
39
from distutils.core import setup, Extension
 
40
from distutils.extension import read_setup_file
 
41
from distutils.ccompiler import new_compiler
 
42
from distutils.command.install_data import install_data
 
43
 
 
44
 
 
45
#headers to install
 
46
headers = glob.glob(os.path.join('src', '*.h'))
 
47
 
 
48
 
 
49
#sanity check for any arguments
 
50
if len(sys.argv) == 1:
 
51
    reply = raw_input('\nNo Arguments Given, Perform Default Install? [Y/n]')
 
52
    if not reply or reply[0].lower() != 'n':
 
53
        sys.argv.append('install')
 
54
 
 
55
 
 
56
#make sure there is a Setup file
 
57
if not os.path.isfile('Setup'):
 
58
    print '\n\nWARNING, No "Setup" File Exists, Running "config.py"'
 
59
    import config
 
60
    config.main()
 
61
    print '\nContinuing With "setup.py"'
 
62
 
 
63
 
 
64
 
 
65
#get compile info for all extensions
 
66
try:
 
67
    extensions = read_setup_file('Setup')
 
68
except:
 
69
    raise SystemExit, """Error with the "Setup" file,
 
70
perhaps make a clean copy from "Setup.in"."""
 
71
 
 
72
 
 
73
#extra files to install
 
74
data_path = os.path.join(distutils.sysconfig.get_python_lib(), 'pygame')
 
75
data_files = []
 
76
 
 
77
 
 
78
#add non .py files in lib directory
 
79
for f in glob.glob(os.path.join('lib', '*')):
 
80
    if not f[-3:] =='.py' and os.path.isfile(f):
 
81
        data_files.append(f)
 
82
 
 
83
 
 
84
#try to find DLLs and copy them too  (only on windows)
 
85
if sys.platform == 'win32':
 
86
    tempcompiler = new_compiler()
 
87
    for e in extensions:
 
88
        paths = []
 
89
        ext = tempcompiler.shared_lib_extension
 
90
        for d in e.library_dirs:
 
91
             for l in e.libraries:
 
92
                    name = tempcompiler.shared_lib_format%(l, ext)
 
93
                    paths.append(os.path.join(d, name))
 
94
        for p in paths:
 
95
            if os.path.isfile(p) and p not in data_files:
 
96
                data_files.append(p)
 
97
 
 
98
 
 
99
#we can detect the presence of python dependencies, remove any unfound
 
100
pythondeps = {'surfarray': ['Numeric']}
 
101
for e in extensions[:]:
 
102
    modules = pythondeps.get(e.name, [])
 
103
    if modules:
 
104
        try:
 
105
            for module in modules:
 
106
                x = __import__(module)
 
107
                del x
 
108
        except ImportError:
 
109
            print 'NOTE: Not compiling:', e.name, ' (module not found='+module+')'
 
110
            extensions.remove(e)
 
111
 
 
112
 
 
113
#clean up the list of extensions
 
114
for e in extensions[:]:
 
115
    if e.name[:8] == 'COPYLIB_':
 
116
        extensions.remove(e) #don't compile the COPYLIBs, just clean them
 
117
    else:
 
118
        e.name = 'pygame.' + e.name #prepend package name on modules
 
119
 
 
120
 
 
121
 
 
122
#data installer with improved intelligence over distutils
 
123
#data files are copied into the project directory instead
 
124
#of willy-nilly
 
125
class smart_install_data(install_data):   
 
126
    def run(self):
 
127
        #need to change self.install_dir to the library dir
 
128
 
 
129
        install_cmd = self.get_finalized_command('install')
 
130
        self.install_dir = getattr(install_cmd, 'install_lib')
 
131
        return install_data.run(self)
 
132
 
 
133
 
 
134
 
 
135
 
 
136
 
 
137
 
 
138
#finally, 
 
139
#call distutils with all needed info
 
140
PACKAGEDATA = {
 
141
       "cmdclass":    {'install_data': smart_install_data},
 
142
       "packages":    ['pygame'],
 
143
       "package_dir": {'pygame': 'lib'},
 
144
       "headers":     headers,
 
145
       "ext_modules": extensions,
 
146
       "data_files":  [['pygame', data_files]],
 
147
}
 
148
PACKAGEDATA.update(METADATA)
 
149
apply(setup, [], PACKAGEDATA)
 
150