#!/usr/bin/env python # Relatively generic setup.py that should be easily tailorable to # other python modules. It gets most of the parameters from the # packaged module itself, so this file shouldn't have to be changed # much. import os, sys, distutils, glob, zlib, filecmp from cStringIO import StringIO from distutils.core import setup, Extension, Command from distutils.command.build_py import build_py as _build_py from distutils import util platform = util.get_platform() if sys.version < '2.5': raise SystemExit('Sorry, peppy requires at least Python 2.5.') # Load the root module that contains the version info and descriptive text prog = 'peppy' module = __import__(prog) version = module.__version__ # crunch_data was removed from img2py as of wxPython 2.8.8 def crunch_data(data, compressed): # compress it? if compressed: data = zlib.compress(data, 9) # convert to a printable format, so it can be in a Python source file data = repr(data) # This next bit is borrowed from PIL. It is used to wrap the text intelligently. fp = StringIO() data += " " # buffer for the +1 test c = i = 0 word = "" octdigits = "01234567" hexdigits = "0123456789abcdef" while i < len(data): if data[i] != "\\": word = data[i] i += 1 else: if data[i+1] in octdigits: for n in xrange(2, 5): if data[i+n] not in octdigits: break word = data[i:i+n] i += n elif data[i+1] == 'x': for n in xrange(2, 5): if data[i+n] not in hexdigits: break word = data[i:i+n] i += n else: word = data[i:i+2] i += 2 l = len(word) if c + l >= 78-1: fp.write("\\\n") c = 0 fp.write(word) c += l # return the formatted compressed data return fp.getvalue() class build_extra_peppy(_build_py): def generate_printable_icon(self, filename, remove, out): if filename.endswith('.py') or filename.endswith('.pyc'): return fh = open(filename, 'rb') data = fh.read() printable = crunch_data(data, False) # Change all windows backslashes to forward slashes if filename.startswith(remove): filename = filename[len(remove):] filename = filename.replace('\\', '/') out.write("'%s':\n%s,\n" % (filename, printable)) def process_icons(self, path, remove, out): files = glob.glob('%s/*' % path) for path in files: if os.path.isdir(path): self.process_icons(path, remove, out) else: self.generate_printable_icon(path, remove, out) def create_iconmap(self, filename="peppy/iconmap.py"): print self.build_lib out = StringIO() out.write("""\ from peppy.lib.iconstorage import * icondict = { """) self.process_icons('peppy/icons', 'peppy/', out) out.write("""\ } addIconsFromDict(icondict) """) pathname = os.path.join(self.build_lib, filename) fh = open(pathname, 'wb') fh.write(out.getvalue()) print("created %s" % pathname) def build_package_data(self): self.create_iconmap() _build_py.build_package_data(self) # Find the long description based on the doc string of the root module def findLongDescription(): # skip the opening one-line description and grab the first paragraph # out of the module's docstring to use as the long description. long_description = '' lines = module.__doc__.splitlines() for firstline in range(len(lines)): # skip until we reach a blank line if len(lines[firstline])==0 or lines[firstline].isspace(): break if firstline Peppy - (ap)Proximated (X)Emacs Powered by Python """ platform_kwargs['windows'] = [ {"script": "py2exe/peppy.py", "other_resources": [(24,1,manifest)], "icon_resources": [(2, "py2exe/peppy48.ico")], } ] platform_kwargs['zip_safe'] = False try: import peppy.py2exe_plugins_count packages.extend(peppy.py2exe_plugins_count.setuptools_packages) except ImportError: # skip it if it can't find import the file pass except AttributeError: # skip it if there are no setuptools packages listed in the file pass # Define any extensions in setup_extensions.py save_path = sys.path try: sys.path = ["."] from setup_extensions import * except: ext_modules = None finally: sys.path = save_path setup(cmdclass={'build_py': build_extra_peppy,}, name = prog, version = version, description = module.__description__, long_description = long_description, keywords = module.__keywords__, license = module.__license__, author = module.__author__, author_email = module.__author_email__, url = module.__url__, download_url = module.__download_url__, platforms = 'any', scripts = scripts, packages = packages, package_data = package_data, ext_modules = ext_modules, # FIXME: the excludes option still doesn't work. py2exe still # picks up a bunch of unnecessary stuff that I'm trying to get # rid of. options = {'py2exe': {'unbuffered': True, 'optimize': 2, 'excludes': ['Tkinter', 'Tkconstants', 'tcl', '_tkinter', 'numpy.f2py', 'matplotlib', 'doctest'], } }, data_files = data_files, classifiers=['Development Status :: 3 - Alpha', 'Environment :: MacOS X', 'Environment :: Win32 (MS Windows)', 'Environment :: X11 Applications', 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU General Public License (GPL)', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Operating System :: POSIX :: Linux', 'Operating System :: Unix', 'Programming Language :: Python', 'Topic :: Software Development :: Documentation', 'Topic :: Text Editors', ], **platform_kwargs )