[xiph-cvs] cvs commit: ao-python config_unix.py prebuild.sh setup.cfg .cvsignore ChangeLog MANIFEST.in setup.py

Andrew Catham Master of Python andrew at xiph.org
Wed Jan 31 10:35:10 PST 2001



andrew      01/01/31 10:35:10

  Modified:    .        .cvsignore ChangeLog MANIFEST.in setup.py
  Added:       .        config_unix.py prebuild.sh setup.cfg
  Log:
  2001-01-31  Andrew H. Chatham <andrew.chatham at duke.edu>
          * setup.py, config_unix.py, setup.cfg: Went back to an older way
          of configuring things, which seems to be the only maintainable way
          to do it until distutils has better configuration
          support. "./setup.py bdist_rpm" should work fine now.

Revision  Changes    Path
1.2       +0 -1      ao-python/.cvsignore

Index: .cvsignore
===================================================================
RCS file: /usr/local/cvsroot/ao-python/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- .cvsignore	2001/01/21 22:11:54	1.1
+++ .cvsignore	2001/01/31 18:35:09	1.2
@@ -1,5 +1,4 @@
 Setup
-config.ao
 MANIFEST
 build
 dist

1.2       +6 -0      ao-python/ChangeLog

Index: ChangeLog
===================================================================
RCS file: /usr/local/cvsroot/ao-python/ChangeLog,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ChangeLog	2001/01/21 22:11:54	1.1
+++ ChangeLog	2001/01/31 18:35:09	1.2
@@ -1,3 +1,9 @@
+2001-01-31  Andrew H. Chatham <andrew.chatham at duke.edu>
+	* setup.py, config_unix.py, setup.cfg: Went back to an older way
+	of configuring things, which seems to be the only maintainable way
+	to do it until distutils has better configuration
+	support. "./setup.py bdist_rpm" should work fine now.
+	
 2001-01-21  Andrew H. Chatham <andrew.chatham at duke.edu>
         * src/aomodule.c (dict_to_options): Size checking removed; no
         longer necessary

1.2       +1 -1      ao-python/MANIFEST.in

Index: MANIFEST.in
===================================================================
RCS file: /usr/local/cvsroot/ao-python/MANIFEST.in,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MANIFEST.in	2001/01/21 22:11:54	1.1
+++ MANIFEST.in	2001/01/31 18:35:09	1.2
@@ -1,3 +1,3 @@
-include ChangeLog README COPYING AUTHORS NEWS setup.py test.py MANIFEST.in
+include ChangeLog README COPYING AUTHORS NEWS setup.py test.py config_unix.py prebuild.sh
 recursive-include src/ *.c *.h
 

1.3       +27 -85    ao-python/setup.py

Index: setup.py
===================================================================
RCS file: /usr/local/cvsroot/ao-python/setup.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- setup.py	2001/01/21 22:11:54	1.2
+++ setup.py	2001/01/31 18:35:09	1.3
@@ -3,95 +3,38 @@
 """Setup script for the Ao module distribution.
 Configuration in particular could use some work."""
 
-import os, sys
+import os, sys, re, string
 from distutils.core import setup
 from distutils.extension import Extension
 from distutils.command.config import config
 from distutils.command.build import build
 
-def load_config():
-    '''This is still a bit creaky. Hopefully distutils will
-    offer better configuration support in the future.'''
-
-    if not os.path.isfile('config.ao'):
-        print "File config.ao not found"
-        return {}
-    f = open('config.ao', 'r')
-    dict = eval(f.read())
-    return dict
-
-
-class config_ao (config):
-
-    added_variables = ('ao_include_dirs', 'ao_library_dirs', 'ao_libraries')
-
-    user_options = config.user_options + [
-        ('ao-prefix=', None,
-         'prefix in which to find ao headers and libraries'),
-        ('ao-include-dirs=', None,
-         "directories to search for ao header files"),
-        ('ao-library-dirs=', None,
-         "directories to search for ao library files"),
-        ]
+def get_setup():
+    data = {}
+    r = re.compile(r'(\S+)\s*?=\s*?(.+)')
+    
+    if not os.path.isfile('Setup'):
+        print "No 'Setup' file. Perhaps you need to run the configure script."
+        sys.exit(1)
 
-    def _save(self):
-        '''Save the variables I want as the representation of a dictionary'''
-        
-        dict = {}
-        for v in self.added_variables:
-            dict[v] = getattr(self, v)
-        f = open('config.ao', 'w')
-        f.write(repr(dict))
-        f.write('\n')
-
-    def initialize_options (self):
-        config.initialize_options(self)
-        self.ao_prefix = '/usr/local'
-        self.ao_include_dirs = []
-        self.ao_library_dirs = []
-        self.ao_libraries = ['ao', 'dl']
-
-
-    def finalize_options (self):
-        if not self.ao_include_dirs:
-            self.ao_include_dirs = [os.path.join(self.ao_prefix, 'include')]
-        if not self.ao_library_dirs:
-            self.ao_library_dirs = [os.path.join(self.ao_prefix, 'lib')]
-                
-    def run (self):
-        self.have_ao = self.check_lib("ao", self.ao_library_dirs,
-                                 ['ao/ao.h'], self.ao_include_dirs, ['dl'])
-
-        if not self.have_ao:
-            print "*** ao check failed ***"
-            print "You may need to install the ao library"
-            print "or pass the paths where it can be found"
-            print "(setup.py --help)"
+    f = open('Setup', 'r')
+    
+    for line in f.readlines():
+        m = r.search(line)
+        if not m:
+            print "Error in setup file:", line
             sys.exit(1)
-
-        self._save()
-
-
-class nullBuilder (build):
-    '''Prevents building. This is used for when they try to build
-    without having run configure first.'''
-
-    def run(self):
-        print
-        print "*** You must first run 'setup.py config' ***"
-        print
-        sys.exit(1)
+        key = m.group(1)
+        val = m.group(2)
+        data[key] = val
+        
+    return data
 
-cmdclass = {'config' : config_ao}
+data = get_setup()
+ao_include_dir = data['ao_include_dir']
+ao_lib_dir = data['ao_lib_dir']
+ao_libs = string.split(data['ao_libs'])
 
-config_data = load_config()
-if not config_data:
-    cmdclass['build'] = nullBuilder
-    ao_include_dirs = ao_library_dirs = ao_libraries = []
-else:
-    ao_include_dirs = config_data['ao_include_dirs']
-    ao_library_dirs = config_data['ao_library_dirs']
-    ao_libraries = config_data['ao_libraries']
 
 setup (# Distribution meta-data
         name = "pyao",
@@ -100,17 +43,16 @@
         author = "Andrew Chatham",
         author_email = "andrew.chatham at duke.edu",
         url = "http://dulug.duke.edu/~andrew/pyvorbis.html",
-
-        cmdclass = cmdclass,
+        license = 'GPL',
 
         # Description of the modules and packages in the distribution
 
         ext_modules = [Extension(
                 name = 'aomodule',
                 sources = ['src/aomodule.c'],
-                include_dirs = ao_include_dirs,
-		library_dirs = ao_library_dirs,
-                libraries = ao_libraries)]
+                include_dirs = [ao_include_dir],
+		library_dirs = [ao_lib_dir],
+                libraries = ao_libs)]
 )
 
 

1.1                  ao-python/config_unix.py

Index: config_unix.py
===================================================================
#!/usr/bin/env python

import string
import os
import sys

def msg_checking(msg):
    print "Checking", msg, "...",

def execute(cmd, display = 0):
    if display:
        print cmd
    return os.system(cmd)

def run_test(input, flags = ''):
    try:
        f = open('_temp.c', 'w')
        f.write(input)
        f.close()
        compile_cmd = '%s -o _temp _temp.c %s' % (os.environ.get('CC', 'cc'),
                                                  flags)
        if not execute(compile_cmd):
            execute('./_temp')
    finally:
        execute('rm -f _temp.c _temp')
    
ao_test_program = '''
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ao/ao.h>

int main ()
{
  system("touch conf.aotest");
  return 0;
}
'''

def find_ao(ao_prefix = '/usr/local', enable_aotest = 1):
    """A rough translation of ao.m4"""

    ao_cflags = []
    ao_libs = []
    
    ao_include_dir = ao_prefix + '/include'
    ao_lib_dir = ao_prefix + '/lib'
    ao_libs = 'ao'

    msg_checking('for Ao')

    if enable_aotest:
        execute('rm -f conf.aotest', 0)

        try:
            run_test(ao_test_program)
            if not os.path.isfile('conf.aotest'):
                raise RuntimeError, "Did not produce output"
            execute('rm conf.aotest', 0)
            
        except Exception, e:
            print "test program failed"
            return None

    print "success"

    return {'ao_libs' : ao_libs,
            'ao_lib_dir' : ao_lib_dir,
            'ao_include_dir' : ao_include_dir}

def write_data(data):
    f = open('Setup', 'w')
    for item in data.items():
        f.write('%s = %s\n' % item)
    f.close()
    print "Wrote Setup file"
            
def print_help():
    print '''%s
    --prefix      Give the prefix in which ao was installed.''' % sys.argv[0]
    sys.exit(0)

def parse_args():
    data = {}
    argv = sys.argv
    for pos in range(len(argv)):
        if argv[pos] == '--help':
            print_help()
        if argv[pos] == '--prefix':
            pos = pos + 1
            if len(argv) == pos:
                print "Prefix needs an argument"
                sys.exit(1)
            data['prefix'] = argv[pos]

    return data
    
def main():
    args = parse_args()
    prefix = args.get('prefix', '/usr/local')

    data = find_ao(ao_prefix = prefix)
    if not data:
        print "Config failure"
        sys.exit(1)
    write_data(data)

if __name__ == '__main__':
    main()

1.1                  ao-python/prebuild.sh

Index: prebuild.sh
===================================================================
#!/bin/sh

python config_unix.py

1.1                  ao-python/setup.cfg

Index: setup.cfg
===================================================================
[bdist_rpm]
requires=ao
build_script=prebuild.sh

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list