Commits

Ronald Oussoren committed 52390aa

Fix build issue with python2.5

We use PyPIRCCommand, and that's only available in 2.6 or later.

Comments (0)

Files changed (6)

doc/changelog.rst

 
 - Issue #9: Add support for recent Python 3.2 pre-releases.
 
+- Fix build issues with python 2.5 (due to usage of too modern distutils
+  command subclasses)
+
 py2app 0.5.2
 ------------
 

py2app/bootstrap/import_encodings.py

     encodings.__path__ = pkgutil.extend_path(
             encodings.__path__,
             encodings.__name__)
-    imp.reload(encodings)
+    #imp.reload(encodings)
 
     import encodings.mac_roman
     encodings.aliases.__file__ = os.path.join(

py2app/build_app.py

             self.argv_inject = shlex.split(self.argv_inject)
         self.includes = set(fancy_split(self.includes))
         self.includes.add('encodings.*')
-        #if sys.version_info[:2] >= (3,2):
+        #if sys.version_info[:2] >= (3, 2):
         #    self.includes.add('pkgutil')
         #    self.includes.add('imp')
         self.packages = set(fancy_split(self.packages))
 
     def initialize_prescripts(self):
         prescripts = []
-        if sys.version_info[:2] >= (3, 2):
+        if 0 and sys.version_info[:2] >= (3, 2) and not self.alias:
             # Python 3.2 or later requires a more complicated
             # bootstrap
             prescripts.append('import_encodings')
 
 
         if includedir is None:
-            includedir = 'python%s'%(info['version'])
+            includedir = 'python%d.%d'%(sys.version_info[:2])
         else:
             includedir = os.path.basename(includedir)
 
             self.mkpath(os.path.dirname(fn))
             copy_file(copyext.filename, fn, dry_run=self.dry_run)
 
-        if sys.version_info[:2] >= (3, 2):
+        if 0 and sys.version_info[:2] >= (3, 2) and not self.alias:
             import encodings
             import encodings.cp437
             import encodings.utf_8

py2app_tests/basic_plugin/main.py

 
 class BasicPlugin (Foundation.NSObject):
     def performCommand_(self, cmd):
-        print "+ %s"%(cmd,)
+        print ("+ %s"%(cmd,))
         sys.stdout.flush()

py2app_tests/test_basic_plugin.py

         p.stdin.flush()
 
         v = p.stdout.readline()
-        self.assertEquals(v.strip(), '+ test startup')
+        self.assertEqual(v.strip(), '+ test startup')
 
         p.stdin.close()
         p.stdout.close()
 
 import sys, os
 from setuptools import setup, find_packages
-from distutils.core import PyPIRCCommand
 from distutils.errors  import DistutilsError
 from distutils import log
 from setuptools.command import test
+try:
+    from distutils.core import PyPIRCCommand
+except ImportError:
+    from distutils.core import Command
 
 LONG_DESCRIPTION = open('README.txt').read()
 LONG_DESCRIPTION += '\n' + open('doc/changelog.rst').read()
 
     return unittest.TestSuite(suites)
 
-class upload_docs (PyPIRCCommand):
-    description = "upload sphinx documentation"
-    user_options = PyPIRCCommand.user_options
+if PyPIRCCommand is None:
+    class upload_docs (Command):
+        description = "upload sphinx documentation"
+        user_options = []
 
-    def initialize_options(self):
-        PyPIRCCommand.initialize_options(self)
-        self.username = ''
-        self.password = ''
+        def initialize_options(self):
+            pass
 
+        def finalize_options(self):
+            pass
 
-    def finalize_options(self):
-        PyPIRCCommand.finalize_options(self)
-        config = self._read_pypirc()
-        if config != {}:
-            self.username = config['username']
-            self.password = config['password']
+        def run(self):
+            raise DistutilsError("not supported on this version of python")
 
+else:
+    class upload_docs (PyPIRCCommand):
+        description = "upload sphinx documentation"
+        user_options = PyPIRCCommand.user_options
 
-    def run(self):
-        import subprocess
-        import shutil
-        import zipfile
-        import os
-        import urllib
-        import StringIO
-        from base64 import standard_b64encode
-        import httplib
-        import urlparse
+        def initialize_options(self):
+            PyPIRCCommand.initialize_options(self)
+            self.username = ''
+            self.password = ''
 
-        # Extract the package name from distutils metadata
-        meta = self.distribution.metadata
-        name = meta.get_name()
 
-        # Run sphinx
-        if os.path.exists('doc/_build'):
-            shutil.rmtree('doc/_build')
-        os.mkdir('doc/_build')
+        def finalize_options(self):
+            PyPIRCCommand.finalize_options(self)
+            config = self._read_pypirc()
+            if config != {}:
+                self.username = config['username']
+                self.password = config['password']
 
-        p = subprocess.Popen(['make', 'html'],
-            cwd='doc')
-        exit = p.wait()
-        if exit != 0:
-            raise DistutilsError("sphinx-build failed")
 
-        # Collect sphinx output
-        if not os.path.exists('dist'):
-            os.mkdir('dist')
-        zf = zipfile.ZipFile('dist/%s-docs.zip'%(name,), 'w', 
-                compression=zipfile.ZIP_DEFLATED)
+        def run(self):
+            import subprocess
+            import shutil
+            import zipfile
+            import os
+            import urllib
+            import StringIO
+            from base64 import standard_b64encode
+            import httplib
+            import urlparse
 
-        for toplevel, dirs, files in os.walk('doc/_build/html'):
-            for fn in files:
-                fullname = os.path.join(toplevel, fn)
-                relname = os.path.relpath(fullname, 'doc/_build/html')
+            # Extract the package name from distutils metadata
+            meta = self.distribution.metadata
+            name = meta.get_name()
 
-                print ("%s -> %s"%(fullname, relname))
+            # Run sphinx
+            if os.path.exists('doc/_build'):
+                shutil.rmtree('doc/_build')
+            os.mkdir('doc/_build')
 
-                zf.write(fullname, relname)
+            p = subprocess.Popen(['make', 'html'],
+                cwd='doc')
+            exit = p.wait()
+            if exit != 0:
+                raise DistutilsError("sphinx-build failed")
 
-        zf.close()
+            # Collect sphinx output
+            if not os.path.exists('dist'):
+                os.mkdir('dist')
+            zf = zipfile.ZipFile('dist/%s-docs.zip'%(name,), 'w', 
+                    compression=zipfile.ZIP_DEFLATED)
 
-        # Upload the results, this code is based on the distutils
-        # 'upload' command.
-        content = open('dist/%s-docs.zip'%(name,), 'rb').read()
-        
-        data = {
-            ':action': 'doc_upload',
-            'name': name,
-            'content': ('%s-docs.zip'%(name,), content),
-        }
-        auth = "Basic " + standard_b64encode(self.username + ":" +
-             self.password)
+            for toplevel, dirs, files in os.walk('doc/_build/html'):
+                for fn in files:
+                    fullname = os.path.join(toplevel, fn)
+                    relname = os.path.relpath(fullname, 'doc/_build/html')
 
+                    print ("%s -> %s"%(fullname, relname))
 
-        boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
-        sep_boundary = '\n--' + boundary
-        end_boundary = sep_boundary + '--'
-        body = StringIO.StringIO()
-        for key, value in data.items():
-            if not isinstance(value, list):
-                value = [value]
+                    zf.write(fullname, relname)
 
-            for value in value:
-                if isinstance(value, tuple):
-                    fn = ';filename="%s"'%(value[0])
-                    value = value[1]
-                else:
-                    fn = ''
+            zf.close()
 
-                body.write(sep_boundary)
-                body.write('\nContent-Disposition: form-data; name="%s"'%key)
-                body.write(fn)
-                body.write("\n\n")
-                body.write(value)
+            # Upload the results, this code is based on the distutils
+            # 'upload' command.
+            content = open('dist/%s-docs.zip'%(name,), 'rb').read()
+            
+            data = {
+                ':action': 'doc_upload',
+                'name': name,
+                'content': ('%s-docs.zip'%(name,), content),
+            }
+            auth = "Basic " + standard_b64encode(self.username + ":" +
+                 self.password)
 
-        body.write(end_boundary)
-        body.write('\n')
-        body = body.getvalue()
 
-        self.announce("Uploading documentation to %s"%(self.repository,), log.INFO)
+            boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
+            sep_boundary = '\n--' + boundary
+            end_boundary = sep_boundary + '--'
+            body = StringIO.StringIO()
+            for key, value in data.items():
+                if not isinstance(value, list):
+                    value = [value]
 
-        schema, netloc, url, params, query, fragments = \
-                urlparse.urlparse(self.repository)
+                for value in value:
+                    if isinstance(value, tuple):
+                        fn = ';filename="%s"'%(value[0])
+                        value = value[1]
+                    else:
+                        fn = ''
 
+                    body.write(sep_boundary)
+                    body.write('\nContent-Disposition: form-data; name="%s"'%key)
+                    body.write(fn)
+                    body.write("\n\n")
+                    body.write(value)
 
-        if schema == 'http':
-            http = httplib.HTTPConnection(netloc)
-        elif schema == 'https':
-            http = httplib.HTTPSConnection(netloc)
-        else:
-            raise AssertionError("unsupported schema "+schema)
+            body.write(end_boundary)
+            body.write('\n')
+            body = body.getvalue()
 
-        data = ''
-        loglevel = log.INFO
-        try:
-            http.connect()
-            http.putrequest("POST", url)
-            http.putheader('Content-type',
-                'multipart/form-data; boundary=%s'%boundary)
-            http.putheader('Content-length', str(len(body)))
-            http.putheader('Authorization', auth)
-            http.endheaders()
-            http.send(body)
-        except socket.error:
-            e = socket.exc_info()[1]
-            self.announce(str(e), log.ERROR)
-            return
+            self.announce("Uploading documentation to %s"%(self.repository,), log.INFO)
 
-        r = http.getresponse()
-        if r.status in (200, 301):
-            self.announce('Upload succeeded (%s): %s' % (r.status, r.reason),
-                log.INFO)
-        else:
-            self.announce('Upload failed (%s): %s' % (r.status, r.reason),
-                log.ERROR)
+            schema, netloc, url, params, query, fragments = \
+                    urlparse.urlparse(self.repository)
 
-            print ('-'*75) 
-            print (r.read())
-            print ('-'*75)
+
+            if schema == 'http':
+                http = httplib.HTTPConnection(netloc)
+            elif schema == 'https':
+                http = httplib.HTTPSConnection(netloc)
+            else:
+                raise AssertionError("unsupported schema "+schema)
+
+            data = ''
+            loglevel = log.INFO
+            try:
+                http.connect()
+                http.putrequest("POST", url)
+                http.putheader('Content-type',
+                    'multipart/form-data; boundary=%s'%boundary)
+                http.putheader('Content-length', str(len(body)))
+                http.putheader('Authorization', auth)
+                http.endheaders()
+                http.send(body)
+            except socket.error:
+                e = socket.exc_info()[1]
+                self.announce(str(e), log.ERROR)
+                return
+
+            r = http.getresponse()
+            if r.status in (200, 301):
+                self.announce('Upload succeeded (%s): %s' % (r.status, r.reason),
+                    log.INFO)
+            else:
+                self.announce('Upload failed (%s): %s' % (r.status, r.reason),
+                    log.ERROR)
+
+                print ('-'*75) 
+                print (r.read())
+                print ('-'*75)
 
 setup(
     # metadata