Example #1
0
 def setUp(self):
     self.tdir = tempfile.mkdtemp()
     scriptfile = os.path.join(self.tdir,"script.py")
     self.distdir = distdir = os.path.join(self.tdir,"dist")
     with open(scriptfile,"w") as f:
         f.write("import signedimp.crypto.rsa\n")
     dist_setup(name="testapp",version="0.1",scripts=[scriptfile],
                options={"bdist":{"dist_dir":distdir}},
                console=[scriptfile],
                script_args=["py2exe"])
Example #2
0
def web_py2exe():
    webdir = os.path.join(wingufile_srcdir, 'web')
    dist_dir = os.path.join(webdir, 'dist')
    build_dir = os.path.join(webdir, 'build')

    rmtree(dist_dir)
    rmtree(build_dir)

    os.chdir(webdir)

    original_argv = sys.argv
    sys.argv = [sys.argv[0], 'py2exe']
    sys.path.insert(0, webdir)

    targetname = 'wingufile-web'
    targetfile = targetname + '.py'
    must_copy('main.py', targetfile)

    packages = ["mako.cache", "utils"]
    ex_files = []
    option = {
        "py2exe": {
            "includes": [targetname],
            "packages": packages,
            "bundle_files": 3
        }
    }

    try:
        dist_setup(name=targetname,
                   options=option,
                   windows=[{
                       "script": targetfile
                   }],
                   data_files=ex_files)
    except Exception as e:
        error('Error when calling py2exe: %s' % e)

    for name in glob.glob('dist/*'):
        must_copy(name, bin_dir)

    must_copytree('i18n', os.path.join(bin_dir, 'i18n'))
    must_copytree('static', os.path.join(bin_dir, 'static'))
    must_copytree('templates', os.path.join(bin_dir, 'templates'))

    rmtree(dist_dir)
    rmtree(build_dir)

    sys.path.pop(0)
    sys.argv = original_argv
    os.chdir(wingufile_srcdir)
Example #3
0
 def setUp(self):
     self.tdir = tempfile.mkdtemp()
     scriptfile = os.path.join(self.tdir, "script.py")
     self.distdir = distdir = os.path.join(self.tdir, "dist")
     with open(scriptfile, "w") as f:
         f.write("import signedimp.crypto.rsa\n")
     dist_setup(name="testapp",
                version="0.1",
                scripts=[scriptfile],
                options={"bdist": {
                    "dist_dir": distdir
                }},
                console=[scriptfile],
                script_args=["py2exe"])
Example #4
0
def web_py2exe():
    webdir = os.path.join(Seafile().projdir, 'web')
    os.chdir(webdir)

    original_argv = sys.argv
    sys.argv = [sys.argv[0], 'py2exe']
    sys.path.insert(0, webdir)

    targetname = 'seafile-web'
    targetfile = targetname + '.py'
    must_copy('main.py', targetfile)

    packages = ["mako.cache", "utils"]
    ex_files = []
    option = {
        "py2exe": {
            "includes": [targetname],
            "packages": packages,
            "bundle_files": 3
        }
    }

    prepend_env_value('PATH',
                      os.path.join(Seafile().prefix, 'bin'),
                      seperator=';')
    try:
        dist_setup(name=targetname,
                   options=option,
                   windows=[{
                       "script": targetfile
                   }],
                   data_files=ex_files)
    except Exception as e:
        error('Error when calling py2exe: %s' % e)

    pack_bin_dir = os.path.join(conf[CONF_BUILDDIR], 'pack', 'bin')

    for name in glob.glob('dist/*'):
        must_copy(name, pack_bin_dir)

    must_copytree('i18n', os.path.join(pack_bin_dir, 'i18n'))
    must_copytree('static', os.path.join(pack_bin_dir, 'static'))
    must_copytree('templates', os.path.join(pack_bin_dir, 'templates'))

    sys.path.pop(0)
    sys.argv = original_argv
    os.chdir(conf[CONF_BUILDDIR])
Example #5
0
def web_py2exe():
    webdir = os.path.join(seafile_srcdir, 'web')
    dist_dir = os.path.join(webdir, 'dist')
    build_dir = os.path.join(webdir, 'build')

    rmtree(dist_dir)
    rmtree(build_dir)
    
    os.chdir(webdir)

    original_argv = sys.argv
    sys.argv = [sys.argv[0], 'py2exe']
    sys.path.insert(0, webdir)

    targetname = 'seafile-web'
    targetfile = targetname + '.py'
    must_copy('main.py', targetfile)

    packages=["mako.cache", "utils"]
    ex_files=[]
    option = {"py2exe":
              {"includes" :[targetname],
               "packages" : packages,
               "bundle_files" : 3}}

    try:
        dist_setup(name=targetname,
                   options = option,
                   windows=[{"script":targetfile}],
                   data_files=ex_files)
    except Exception as e:
        error('Error when calling py2exe: %s' % e)

    for name in glob.glob('dist/*'):
        must_copy(name, bin_dir)

    must_copytree('i18n', os.path.join(bin_dir, 'i18n'))
    must_copytree('static', os.path.join(bin_dir, 'static'))
    must_copytree('templates', os.path.join(bin_dir, 'templates'))

    rmtree(dist_dir)
    rmtree(build_dir)

    sys.path.pop(0)
    sys.argv = original_argv
    os.chdir(seafile_srcdir)
Example #6
0
def web_py2exe():
    webdir = os.path.join(Seafile().projdir, 'web')
    os.chdir(webdir)

    original_argv = sys.argv
    sys.argv = [sys.argv[0], 'py2exe']
    sys.path.insert(0, webdir)

    targetname = 'seafile-web'
    targetfile = targetname + '.py'
    must_copy('main.py', targetfile)

    packages=["mako.cache", "utils"]
    ex_files=[]
    option = {"py2exe":
              {"includes" :[targetname],
               "packages" : packages,
               "bundle_files" : 3}}

    prepend_env_value('PATH',
                      os.path.join(Seafile().prefix, 'bin'),
                      seperator=';')
    try:
        dist_setup(name=targetname,
                   options = option,
                   windows=[{"script":targetfile}],
                   data_files=ex_files)
    except Exception as e:
        error('Error when calling py2exe: %s' % e)

    pack_bin_dir = os.path.join(conf[CONF_BUILDDIR], 'pack', 'bin')

    for name in glob.glob('dist/*'):
        must_copy(name, pack_bin_dir)

    must_copytree('i18n', os.path.join(pack_bin_dir, 'i18n'))
    must_copytree('static', os.path.join(pack_bin_dir, 'static'))
    must_copytree('templates', os.path.join(pack_bin_dir, 'templates'))

    sys.path.pop(0)
    sys.argv = original_argv
    os.chdir(conf[CONF_BUILDDIR])
Example #7
0
    def _run_eskytester(self, options):
        """Build and run the eskytester app using the given distutils options.

    The "eskytester" application can be found next to this file, and the
    sequence of tests performed range across "script1.py" to "script3.py".
    """
        olddir = os.path.abspath(os.curdir)
        #    tdir = os.path.join(os.path.dirname(__file__),"DIST")
        #    if os.path.exists(tdir):
        #        really_rmtree(tdir)
        #    os.mkdir(tdir)
        tdir = tempfile.mkdtemp()
        server = None
        script2 = None
        try:
            options.setdefault("build", {})["build_base"] = os.path.join(tdir, "build")
            options.setdefault("bdist", {})["dist_dir"] = os.path.join(tdir, "dist")
            #  Set some callbacks to test that they work correctly
            options.setdefault("bdist_esky", {}).setdefault(
                "pre_freeze_callback", "esky.tests.test_esky.assert_freezedir_exists"
            )
            options.setdefault("bdist_esky", {}).setdefault("pre_zip_callback", assert_freezedir_exists)
            platform = get_platform()
            deploydir = "deploy.%s" % (platform,)
            esky_root = dirname(dirname(dirname(__file__)))
            os.chdir(tdir)
            shutil.copytree(os.path.join(esky_root, "esky", "tests", "eskytester"), "eskytester")
            dir_util._path_created.clear()
            #  Build three increasing versions of the test package.
            #  Version 0.2 will include a bundled MSVCRT on win32.
            #  Version 0.3 will be distributed as a patch.
            metadata = dict(
                name="eskytester",
                packages=["eskytester"],
                author="rfk",
                description="the esky test package",
                data_files=[("data", ["eskytester/datafile.txt"])],
                package_data={"eskytester": ["pkgdata.txt"]},
            )
            options2 = options.copy()
            options2["bdist_esky"] = options["bdist_esky"].copy()
            options2["bdist_esky"]["bundle_msvcrt"] = True
            script1 = "eskytester/script1.py"
            script2 = Executable([None, open("eskytester/script2.py")], name="script2")
            script3 = "eskytester/script3.py"
            dist_setup(version="0.1", scripts=[script1], options=options, script_args=["bdist_esky"], **metadata)
            dist_setup(
                version="0.2", scripts=[script1, script2], options=options2, script_args=["bdist_esky"], **metadata
            )
            dist_setup(
                version="0.3", scripts=[script2, script3], options=options, script_args=["bdist_esky_patch"], **metadata
            )
            os.unlink(os.path.join(tdir, "dist", "eskytester-0.3.%s.zip" % (platform,)))
            #  Check that the patches apply cleanly
            uzdir = os.path.join(tdir, "unzip")
            deep_extract_zipfile(os.path.join(tdir, "dist", "eskytester-0.1.%s.zip" % (platform,)), uzdir)
            with open(os.path.join(tdir, "dist", "eskytester-0.3.%s.from-0.1.patch" % (platform,)), "rb") as f:
                esky.patch.apply_patch(uzdir, f)
            shutil.rmtree(uzdir)
            deep_extract_zipfile(os.path.join(tdir, "dist", "eskytester-0.2.%s.zip" % (platform,)), uzdir)
            with open(os.path.join(tdir, "dist", "eskytester-0.3.%s.from-0.2.patch" % (platform,)), "rb") as f:
                esky.patch.apply_patch(uzdir, f)
            shutil.rmtree(uzdir)
            #  Serve the updates at http://localhost:8000/dist/
            print "running local update server"
            server = HTTPServer(("localhost", 8000), SimpleHTTPRequestHandler)
            server_thread = threading.Thread(target=server.serve_forever)
            server_thread.daemon = True
            server_thread.start()
            #  Set up the deployed esky environment for the initial version
            zfname = os.path.join(tdir, "dist", "eskytester-0.1.%s.zip" % (platform,))
            os.mkdir(deploydir)
            extract_zipfile(zfname, deploydir)
            #  Run the scripts in order.
            if options["bdist_esky"]["freezer_module"] == "py2app":
                appdir = os.path.join(deploydir, os.listdir(deploydir)[0])
                cmd1 = os.path.join(appdir, "Contents", "MacOS", "script1")
                cmd2 = os.path.join(appdir, "Contents", "MacOS", "script2")
                cmd3 = os.path.join(appdir, "Contents", "MacOS", "script3")
            else:
                appdir = deploydir
                if sys.platform == "win32":
                    cmd1 = os.path.join(deploydir, "script1.exe")
                    cmd2 = os.path.join(deploydir, "script2.exe")
                    cmd3 = os.path.join(deploydir, "script3.exe")
                else:
                    cmd1 = os.path.join(deploydir, "script1")
                    cmd2 = os.path.join(deploydir, "script2")
                    cmd3 = os.path.join(deploydir, "script3")
            print "spawning eskytester script1", options["bdist_esky"]["freezer_module"]
            os.unlink(os.path.join(tdir, "dist", "eskytester-0.1.%s.zip" % (platform,)))
            p = subprocess.Popen(cmd1)
            assert p.wait() == 0
            os.unlink(os.path.join(appdir, "tests-completed"))
            print "spawning eskytester script2"
            os.unlink(os.path.join(tdir, "dist", "eskytester-0.2.%s.zip" % (platform,)))
            p = subprocess.Popen(cmd2)
            assert p.wait() == 0
            os.unlink(os.path.join(appdir, "tests-completed"))
            print "spawning eskytester script3"
            p = subprocess.Popen(cmd3)
            assert p.wait() == 0
            os.unlink(os.path.join(appdir, "tests-completed"))
        finally:
            if script2:
                script2.script[1].close()
            os.chdir(olddir)
            if sys.platform == "win32":
                # wait for the cleanup-at-exit pocess to finish
                time.sleep(4)
            really_rmtree(tdir)
            if server:
                server.shutdown()
Example #8
0
    def _run_eskytester(self, options):
        """Build and run the eskytester app using the given distutils options.

    The "eskytester" application can be found next to this file, and the
    sequence of tests performed range across "script1.py" to "script3.py".
    """
        olddir = os.path.abspath(os.curdir)
        #    tdir = os.path.join(os.path.dirname(__file__),"DIST")
        #    if os.path.exists(tdir):
        #        really_rmtree(tdir)
        #    os.mkdir(tdir)
        tdir = tempfile.mkdtemp()
        server = None
        script2 = None
        try:
            options.setdefault("build",
                               {})["build_base"] = os.path.join(tdir, "build")
            options.setdefault("bdist",
                               {})["dist_dir"] = os.path.join(tdir, "dist")
            #  Set some callbacks to test that they work correctly
            options.setdefault("bdist_esky", {}).setdefault(
                "pre_freeze_callback",
                "esky.tests.test_esky.assert_freezedir_exists")
            options.setdefault("bdist_esky",
                               {}).setdefault("pre_zip_callback",
                                              assert_freezedir_exists)
            options["bdist_esky"].setdefault("excludes",
                                             []).extend(["Tkinter", "tkinter"])
            platform = get_platform()
            deploydir = "deploy.%s" % (platform, )
            esky_root = dirname(dirname(dirname(__file__)))
            os.chdir(tdir)
            shutil.copytree(
                os.path.join(esky_root, "esky", "tests", "eskytester"),
                "eskytester")
            dir_util._path_created.clear()
            #  Build three increasing versions of the test package.
            #  Version 0.2 will include a bundled MSVCRT on win32.
            #  Version 0.3 will be distributed as a patch.
            metadata = dict(
                name="eskytester",
                packages=["eskytester"],
                author="rfk",
                description="the esky test package",
                data_files=[("data", ["eskytester/datafile.txt"])],
                package_data={"eskytester": ["pkgdata.txt"]},
            )
            options2 = options.copy()
            options2["bdist_esky"] = options["bdist_esky"].copy()
            options2["bdist_esky"]["bundle_msvcrt"] = True
            script1 = "eskytester/script1.py"
            script2 = Executable([None, open("eskytester/script2.py")],
                                 name="script2")
            script3 = "eskytester/script3.py"
            dist_setup(version="0.1",
                       scripts=[script1],
                       options=options,
                       script_args=["bdist_esky"],
                       **metadata)
            dist_setup(version="0.2",
                       scripts=[script1, script2],
                       options=options2,
                       script_args=["bdist_esky"],
                       **metadata)
            dist_setup(version="0.3",
                       scripts=[script2, script3],
                       options=options,
                       script_args=["bdist_esky_patch"],
                       **metadata)
            os.unlink(
                os.path.join(tdir, "dist",
                             "eskytester-0.3.%s.zip" % (platform, )))
            #  Check that the patches apply cleanly
            uzdir = os.path.join(tdir, "unzip")
            deep_extract_zipfile(
                os.path.join(tdir, "dist",
                             "eskytester-0.1.%s.zip" % (platform, )), uzdir)
            with open(
                    os.path.join(
                        tdir, "dist",
                        "eskytester-0.3.%s.from-0.1.patch" % (platform, )),
                    "rb") as f:
                esky.patch.apply_patch(uzdir, f)
            really_rmtree(uzdir)
            deep_extract_zipfile(
                os.path.join(tdir, "dist",
                             "eskytester-0.2.%s.zip" % (platform, )), uzdir)
            with open(
                    os.path.join(
                        tdir, "dist",
                        "eskytester-0.3.%s.from-0.2.patch" % (platform, )),
                    "rb") as f:
                esky.patch.apply_patch(uzdir, f)
            really_rmtree(uzdir)
            #  Serve the updates at LOCAL_HTTP_PORT set in esky.util
            print "running local update server"
            try:
                server = HTTPServer(("localhost", LOCAL_HTTP_PORT),
                                    SimpleHTTPRequestHandler)
            except Exception:
                # in travis ci we start our own server
                pass
            else:
                server_thread = threading.Thread(target=server.serve_forever)
                server_thread.daemon = True
                server_thread.start()
            #  Set up the deployed esky environment for the initial version
            zfname = os.path.join(tdir, "dist",
                                  "eskytester-0.1.%s.zip" % (platform, ))
            os.mkdir(deploydir)
            extract_zipfile(zfname, deploydir)
            #  Run the scripts in order.
            if options["bdist_esky"]["freezer_module"] == "py2app":
                appdir = os.path.join(deploydir, os.listdir(deploydir)[0])
                cmd1 = os.path.join(appdir, "Contents", "MacOS", "script1")
                cmd2 = os.path.join(appdir, "Contents", "MacOS", "script2")
                cmd3 = os.path.join(appdir, "Contents", "MacOS", "script3")
            else:
                appdir = deploydir
                if sys.platform == "win32":
                    cmd1 = os.path.join(deploydir, "script1.exe")
                    cmd2 = os.path.join(deploydir, "script2.exe")
                    cmd3 = os.path.join(deploydir, "script3.exe")
                else:
                    cmd1 = os.path.join(deploydir, "script1")
                    cmd2 = os.path.join(deploydir, "script2")
                    cmd3 = os.path.join(deploydir, "script3")
            print "spawning eskytester script1", options["bdist_esky"][
                "freezer_module"]
            os.unlink(
                os.path.join(tdir, "dist",
                             "eskytester-0.1.%s.zip" % (platform, )))
            p = subprocess.Popen(cmd1)
            assert p.wait() == 0
            os.unlink(os.path.join(appdir, "tests-completed"))
            print "spawning eskytester script2"
            os.unlink(
                os.path.join(tdir, "dist",
                             "eskytester-0.2.%s.zip" % (platform, )))
            p = subprocess.Popen(cmd2)
            assert p.wait() == 0
            os.unlink(os.path.join(appdir, "tests-completed"))
            print "spawning eskytester script3"
            p = subprocess.Popen(cmd3)
            assert p.wait() == 0
            os.unlink(os.path.join(appdir, "tests-completed"))
        finally:
            if script2:
                script2.script[1].close()
            os.chdir(olddir)
            if sys.platform == "win32":
                # wait for the cleanup-at-exit pocess to finish
                time.sleep(4)
            really_rmtree(tdir)
            if server:
                server.shutdown()
def runBuildExt(opttree):
    """
    Sets up and runs the python build_ext setup configuration.
    """

    if opttree.no_compile:
        return

    ct = opttree.cython

    extra_include_dirs = ct.extra_include_dirs
    extra_library_dirs = ct.extra_library_dirs
    libraries          = ct.libraries
    library_map        = ct.library_map
    extra_source_map   = ct.extra_source_map
    compiler_args      = ct.compiler_args
    link_args          = ct.link_args

    quiet = not opttree.verbose
    
    from distutils.core import setup as dist_setup
    from distutils.extension import Extension
    
    if ct.numpy_needed:
	import numpy 
	extra_include_dirs += [numpy.get_include()]

    ######################################################
    # First have to see if we're authorized to use cython files, or if we
    # should instead compile the included files

    # Get all the cython files in the sub directories and in this directory
    cython_files = opttree.cython_files

    # Set the compiler arguments -- Add in the environment path stuff
    ld_library_path = os.getenv("LD_LIBRARY_PATH")

    if ld_library_path is not None:
	extra_library_dirs += [p.strip() for p in ld_library_path.split(":") if len(p.strip()) > 0]

    include_path = os.getenv("INCLUDE_PATH")
    if include_path is not None:
	extra_include_dirs += [p.strip() for p in include_path.split(":") if len(p.strip()) > 0]

    # The rest is also shared with the setup.py file, in addition to
    # this one, so 

    def strip_empty(l):
        return [e.strip() for e in l if len(e.strip()) != 0]

    def get_include_dirs(m):
        return strip_empty(extra_include_dirs)

    def get_libnode_library(t):
	if "library_name" not in t:
	    raise ValueError("Expected library_name in %s." % t.treeName())

	if type(t.library_name) is not str:
	    raise ValueError("%s.library_name must be string." % t.treeName())
	
        return t.library_name

    def get_libnode_directory(t):
	if "directory" not in t:
	    raise ValueError("Expected directory in %s." % t.treeName())

	if type(t.directory) is not str:
	    raise ValueError("%s.directory must be a string." % t.treeName())

        return t.directory

    def get_library_dirs(m):
        l = strip_empty(extra_library_dirs)

        if m in library_map:
            for lib in library_map[m]:
                if type(lib) is TreeDict:
                    l.append(get_libnode_directory(lib))

        l = [abspath(ld) for ld in l]
        return l

    def get_libraries(m):
        def process_lib(lib):
            if type(lib) is TreeDict:
                return get_libnode_library(lib)
            else:
                return lib

        liblist = libraries + (library_map[m] if m in library_map else [])
        
        return strip_empty(process_lib(lib) for lib in liblist)

    def get_extra_source_files(m):
        return extra_source_map.get(m, [])

    def get_extra_compile_args(m):
        return strip_empty(compiler_args + (['-g'] if opttree.debug_mode else ["-DNDEBUG"]))

    def get_extra_link_args(m):
        return strip_empty(link_args + (['-g'] if opttree.debug_mode else ["-DNDEBUG"]))

    ############################################################
    # Cython extension lists
    ext_modules = []
    
    for f in cython_files:
        # extract the module names 
        rel_f = relpath(f, opttree.project_directory)
        assert rel_f.endswith('.pyx')
        modname = rel_f[:-4].replace('/', '.')

        ext_modules.append(Extension(
            modname,
            [f] + get_extra_source_files(modname), 
            include_dirs = get_include_dirs(modname),
            library_dirs = get_library_dirs(modname),
            libraries = get_libraries(modname),
            extra_compile_args = get_extra_compile_args(modname),
            extra_link_args = get_extra_link_args(modname),
            language = "c++" if ct.use_cpp else "c",
            ))

    ############################################################
    # Now get all these ready to go

    from Cython.Distutils import build_ext

    cmdclass = {'build_ext' : build_ext}

    old_argv = copy(sys.argv)
    sys.argv = (old_argv[0], "build_ext", "--inplace")

    if not quiet:
        print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "
        print "Compiling cython extension modules.\n"

        
    old_stdout = sys.stdout
    old_stderr = sys.stderr
    
    try:
        if quiet:
            output = sys.stderr = sys.stdout = StringIO()
        
        dist_setup(
            cmdclass = cmdclass,
            ext_modules = ext_modules)
        
    finally:
        sys.stdout = old_stdout
        sys.stderr = old_stderr

        if quiet:
            output_string = output.getvalue()

            # Check for output
            if not all(output_line_okay.match(le) is not None for le in output_string.split('\n')):
                if quiet:
                    print "++++++++++++++++++++"
                    print "Compiling cython extension modules.\n"

                print output_string

    if not quiet:
        print "\nCython extension modules successfully compiled."
        print "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"

    sys.argv = old_argv