Source

cx_Freeze / setup.py

Full commit
Anthony Tuininga c07b876 



Anthony Tuininga f4c31d7 
Anthony Tuininga c07b876 




Anthony Tuininga 593d319 
Anthony Tuininga c07b876 















Anthony Tuininga 406f779 







Anthony Tuininga 1a5c2b1 
Anthony Tuininga 406f779 



Anthony Tuininga c07b876 






Anthony Tuininga 24f5a17 




Anthony Tuininga c07b876 







Anthony Tuininga 593d319 

Anthony Tuininga c07b876 

Anthony Tuininga 74237e9 
Anthony Tuininga 72f6006 


Anthony Tuininga 30e9347 
Anthony Tuininga 72f6006 








Anthony Tuininga c07b876 
Anthony Tuininga df21867 


Anthony Tuininga c07b876 
Anthony Tuininga 593d319 

Anthony Tuininga c07b876 






Anthony Tuininga 5534145 
Anthony Tuininga c07b876 
Anthony Tuininga 6079e67 

Anthony Tuininga c07b876 
Anthony Tuininga 6079e67 
Anthony Tuininga c07b876 








Anthony Tuininga 87c96b7 

Anthony Tuininga f2050ef 
Anthony Tuininga 73dbfd7 
Anthony Tuininga c07b876 




















Anthony Tuininga 6324c18 
Anthony Tuininga c07b876 









Anthony Tuininga 70ba4bd 
Anthony Tuininga d3296c3 

Anthony Tuininga 70ba4bd 



Anthony Tuininga be7c3f4 
Anthony Tuininga 70ba4bd 



Anthony Tuininga c07b876 






Anthony Tuininga f4c31d7 







Anthony Tuininga c07b876 
Anthony Tuininga b3e037a 
Anthony Tuininga c07b876 



Anthony Tuininga f4c31d7 

Anthony Tuininga c07b876 
Anthony Tuininga f4c31d7 

Anthony Tuininga 24f5a17 

Anthony Tuininga c07b876 
Anthony Tuininga 24f5a17 
Anthony Tuininga c07b876 

Anthony Tuininga 24f5a17 
Anthony Tuininga f4c31d7 
Anthony Tuininga df21867 
Anthony Tuininga c07b876 
Anthony Tuininga 70ba4bd 
Anthony Tuininga ad0bf23 
Anthony Tuininga 70ba4bd 
Anthony Tuininga f4c31d7 
Anthony Tuininga 70ba4bd 
Anthony Tuininga 24f5a17 

Anthony Tuininga 011d786 

Anthony Tuininga 70ba4bd 
Anthony Tuininga c07b876 
Anthony Tuininga 717b080 
Anthony Tuininga c07b876 








Thomas Kluyver 4239580 

Anthony Tuininga c07b876 
Anthony Tuininga a19ad30 
Anthony Tuininga c07b876 






Anthony Tuininga 0f69209 
Anthony Tuininga c07b876 







Anthony Tuininga 9d67b7f 
Anthony Tuininga a19ad30 


Anthony Tuininga c07b876 
"""
Distutils script for cx_Freeze.
"""

import cx_Freeze
import distutils.command.bdist_rpm
import distutils.command.build_ext
import distutils.command.build_scripts
import distutils.command.install
import distutils.command.install_data
import distutils.sysconfig
import os
import sys

from distutils.core import setup
from distutils.extension import Extension

class bdist_rpm(distutils.command.bdist_rpm.bdist_rpm):

    # rpm automatically byte compiles all Python files in a package but we
    # don't want that to happen for initscripts and samples so we tell it to
    # ignore those files
    def _make_spec_file(self):
        specFile = distutils.command.bdist_rpm.bdist_rpm._make_spec_file(self)
        specFile.insert(0, "%define _unpackaged_files_terminate_build 0%{nil}")
        return specFile

    def run(self):
        distutils.command.bdist_rpm.bdist_rpm.run(self)
        specFile = os.path.join(self.rpm_base, "SPECS",
                "%s.spec" % self.distribution.get_name())
        queryFormat = "%{name}-%{version}-%{release}.%{arch}.rpm"
        command = "rpm -q --qf '%s' --specfile %s" % (queryFormat, specFile)
        origFileName = os.popen(command).read()
        parts = origFileName.split("-")
        parts.insert(2, "py%s%s" % sys.version_info[:2])
        newFileName = "-".join(parts)
        self.move_file(os.path.join("dist", origFileName),
                os.path.join("dist", newFileName))


class build_ext(distutils.command.build_ext.build_ext):

    def build_extension(self, ext):
        if ext.name.find("bases") < 0:
            distutils.command.build_ext.build_ext.build_extension(self, ext)
            return
        if sys.platform == "win32":
            if sys.version_info[:2] < (2, 6):
                ext.sources.append("source/bases/dummy.rc")
            elif self.compiler.compiler_type == "mingw32":
                ext.sources.append("source/bases/manifest.rc")
        os.environ["LD_RUN_PATH"] = "${ORIGIN}:${ORIGIN}/../lib"
        objects = self.compiler.compile(ext.sources,
                output_dir = self.build_temp,
                include_dirs = ext.include_dirs,
                debug = self.debug,
                depends = ext.depends)
        fileName = os.path.splitext(self.get_ext_filename(ext.name))[0]
        fullName = os.path.join(self.build_lib, fileName)
        libraryDirs = ext.library_dirs or []
        libraries = self.get_libraries(ext)
        extraArgs = ext.extra_link_args or []
        if sys.platform != "win32":
            vars = distutils.sysconfig.get_config_vars()
            if not vars.get("Py_ENABLE_SHARED", 0):
                libraryDirs.append(vars["LIBPL"])
                libraries.append("python%s.%s" % sys.version_info[:2])
                if vars["LINKFORSHARED"] and sys.platform != "darwin":
                    extraArgs.extend(vars["LINKFORSHARED"].split())
                if vars["LIBS"]:
                    extraArgs.extend(vars["LIBS"].split())
                if vars["LIBM"]:
                    extraArgs.append(vars["LIBM"])
                if vars["BASEMODLIBS"]:
                    extraArgs.extend(vars["BASEMODLIBS"].split())
                if vars["LOCALMODLIBS"]:
                    extraArgs.extend(vars["LOCALMODLIBS"].split())
            extraArgs.append("-s")
        elif ext.name.find("Win32GUI") > 0 \
                and self.compiler.compiler_type == "mingw32":
            extraArgs.append("-mwindows")
        self.compiler.link_executable(objects, fullName,
                libraries = libraries,
                library_dirs = libraryDirs,
                runtime_library_dirs = ext.runtime_library_dirs,
                extra_postargs = extraArgs,
                debug = self.debug)

    def get_ext_filename(self, name):
        fileName = distutils.command.build_ext.build_ext.get_ext_filename(self,
                name)
        if name.endswith("util"):
            return fileName
        vars = distutils.sysconfig.get_config_vars()
        soExt = vars["SO"]
        ext = self.compiler.exe_extension or ""
        return fileName[:-len(soExt)] + ext


class build_scripts(distutils.command.build_scripts.build_scripts):

    def copy_scripts(self):
        distutils.command.build_scripts.build_scripts.copy_scripts(self)
        if sys.platform == "win32":
            for script in self.scripts:
                batFileName = os.path.join(self.build_dir, script + ".bat")
                fullScriptName = r"%s\Scripts\%s" % \
                        (os.path.dirname(sys.executable), script)
                command = "%s %s %%*" % (sys.executable, fullScriptName)
                open(batFileName, "w").write("@echo off\n\n%s" % command)


class install(distutils.command.install.install):

    def get_sub_commands(self):
        subCommands = distutils.command.install.install.get_sub_commands(self)
        subCommands.append("install_packagedata")
        return subCommands


class install_packagedata(distutils.command.install_data.install_data):

    def run(self):
        installCommand = self.get_finalized_command("install")
        installDir = getattr(installCommand, "install_lib")
        sourceDirs = ["samples", "initscripts"]
        while sourceDirs:
            sourceDir = sourceDirs.pop(0)
            targetDir = os.path.join(installDir, "cx_Freeze", sourceDir)
            self.mkpath(targetDir)
            for name in os.listdir(sourceDir):
                if name in ("build", "CVS") or name.startswith("."):
                    continue
                fullSourceName = os.path.join(sourceDir, name)
                if os.path.isdir(fullSourceName):
                    sourceDirs.append(fullSourceName)
                else:
                    fullTargetName = os.path.join(targetDir, name)
                    self.copy_file(fullSourceName, fullTargetName)
                    self.outfiles.append(fullTargetName)


def find_cx_Logging():
    dirName = os.path.dirname(os.getcwd())
    loggingDir = os.path.join(dirName, "cx_Logging")
    if not os.path.exists(loggingDir):
        return
    subDir = "implib.%s-%s" % (distutils.util.get_platform(), sys.version[:3])
    importLibraryDir = os.path.join(loggingDir, "build", subDir)
    if not os.path.exists(importLibraryDir):
        return
    return loggingDir, importLibraryDir


commandClasses = dict(
        build_ext = build_ext,
        build_scripts = build_scripts,
        bdist_rpm = bdist_rpm,
        install = install,
        install_packagedata = install_packagedata)

# generate C source for base frozen modules
subDir = "temp.%s-%s" % (distutils.util.get_platform(), sys.version[:3])
baseModulesDir = os.path.join("build", subDir)
baseModulesFileName = os.path.join(baseModulesDir, "BaseModules.c")
finder = cx_Freeze.ModuleFinder(bootstrap = True)
finder.WriteSourceFile(baseModulesFileName)

# build utility module
if sys.platform == "win32":
    libraries = ["imagehlp", "Shlwapi"]
else:
    libraries = []
utilModule = Extension("cx_Freeze.util", ["source/util.c"],
        libraries = libraries)

# build base executables
depends = ["source/bases/Common.c"]
fullDepends = depends + [baseModulesFileName]
includeDirs = [baseModulesDir]
console = Extension("cx_Freeze.bases.Console", ["source/bases/Console.c"],
        depends = fullDepends, include_dirs = includeDirs)
consoleKeepPath = Extension("cx_Freeze.bases.ConsoleKeepPath",
        ["source/bases/ConsoleKeepPath.c"], depends = depends)
extensions = [utilModule, console, consoleKeepPath]
if sys.platform == "win32":
    gui = Extension("cx_Freeze.bases.Win32GUI", ["source/bases/Win32GUI.c"],
            include_dirs = includeDirs, depends = fullDepends,
            libraries = ["user32"])
    extensions.append(gui)
    moduleInfo = find_cx_Logging()
    if moduleInfo is not None and sys.version_info[:2] < (3, 0):
        includeDir, libraryDir = moduleInfo
        includeDirs.append(includeDir)
        service = Extension("cx_Freeze.bases.Win32Service",
                ["source/bases/Win32Service.c"], depends = fullDepends,
                library_dirs = [libraryDir],
                libraries = ["advapi32", "cx_Logging"],
                include_dirs = includeDirs)
        extensions.append(service)

docFiles = "README.txt"

classifiers = [
        "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: Python Software Foundation License",
        "Natural Language :: English",
        "Operating System :: OS Independent",
        "Programming Language :: C",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 3",
        "Topic :: Software Development :: Build Tools",
        "Topic :: Software Development :: Libraries :: Python Modules",
        "Topic :: System :: Software Distribution",
        "Topic :: Utilities"
]

setup(name = "cx_Freeze",
        description = "create standalone executables from Python scripts",
        long_description = "create standalone executables from Python scripts",
        version = "4.2.3",
        cmdclass = commandClasses,
        options = dict(bdist_rpm = dict(doc_files = docFiles),
                install = dict(optimize = 1)),
        ext_modules = extensions,
        packages = ['cx_Freeze'],
        maintainer="Anthony Tuininga",
        maintainer_email="anthony.tuininga@gmail.com",
        url = "http://cx-freeze.sourceforge.net",
        scripts = ["cxfreeze", "cxfreeze-quickstart"],
        classifiers = classifiers,
        keywords = "freeze",
        license = "Python Software Foundation License")