Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code cleanup

  • Loading branch information...
commit 87313a0e5f125c0e4ed01658806065d56565baf0 1 parent 392668e
@lck lck authored
Showing with 92 additions and 99 deletions.
  1. +50 −50 setup.py
  2. +42 −49 utils.py
View
100 setup.py
@@ -309,7 +309,7 @@ def run(self):
nmake_path = find_executable("nmake")
if nmake_path is None or not os.path.exists(nmake_path):
log.info("nmake not found. Trying to initialize the MSVC env...")
- init_msvc_env(platform_arch, build_type, log)
+ init_msvc_env(platform_arch, build_type)
else:
log.info("nmake was found in %s" % nmake_path)
if OPTION_JOM:
@@ -430,7 +430,7 @@ def run(self):
sys.exit(1)
# Update the PATH environment variable
- update_env_path([py_scripts_dir, qt_dir], log)
+ update_env_path([py_scripts_dir, qt_dir])
build_name = "py%s-qt%s-%s-%s" % \
(py_version, qt_version, platform.architecture()[0], build_type.lower())
@@ -442,7 +442,7 @@ def run(self):
# Try to ensure that tools built by this script (such as shiboken)
# are found before any that may already be installed on the system.
- update_env_path([os.path.join(install_dir, 'bin')], log)
+ update_env_path([os.path.join(install_dir, 'bin')])
# Tell cmake to look here for *.cmake files
os.environ['CMAKE_PREFIX_PATH'] = install_dir
@@ -529,7 +529,7 @@ def build_patchelf(self):
"-o",
"patchelf",
]
- if run_process(build_cmd, log) != 0:
+ if run_process(build_cmd) != 0:
raise DistutilsSetupError("Error building patchelf")
def build_extension(self, extension):
@@ -596,23 +596,23 @@ def build_extension(self, extension):
cmake_cmd.append("-DCMAKE_OSX_ARCHITECTURES:STRING={}".format(OPTION_OSXARCH))
log.info("Configuring module %s (%s)..." % (extension, module_src_dir))
- if run_process(cmake_cmd, log) != 0:
+ if run_process(cmake_cmd) != 0:
raise DistutilsSetupError("Error configuring " + extension)
log.info("Compiling module %s..." % extension)
cmd_make = [self.make_path]
if OPTION_JOBS:
cmd_make.append(OPTION_JOBS)
- if run_process(cmd_make, log) != 0:
+ if run_process(cmd_make) != 0:
raise DistutilsSetupError("Error compiling " + extension)
if extension.lower() == "shiboken":
log.info("Generating Shiboken documentation %s..." % extension)
- if run_process([self.make_path, "doc"], log) != 0:
+ if run_process([self.make_path, "doc"]) != 0:
raise DistutilsSetupError("Error generating documentation " + extension)
log.info("Installing module %s..." % extension)
- if run_process([self.make_path, "install/fast"], log) != 0:
+ if run_process([self.make_path, "install/fast"]) != 0:
raise DistutilsSetupError("Error pseudo installing " + extension)
os.chdir(self.script_dir)
@@ -650,7 +650,7 @@ def prepare_packages_posix(self, vars):
copyfile(
"{script_dir}/patchelf",
"{dist_dir}/PySide/patchelf",
- logger=log, vars=vars)
+ vars=vars)
so_ext = '.so'
so_star = so_ext + '.*'
elif sys.platform == 'darwin':
@@ -660,30 +660,30 @@ def prepare_packages_posix(self, vars):
copydir(
"{build_dir}/shiboken/doc/html",
"{dist_dir}/PySide/docs/shiboken",
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# <install>/lib/site-packages/PySide/* -> <setup>/PySide
copydir(
"{site_packages_dir}/PySide",
"{dist_dir}/PySide",
- logger=log, vars=vars)
+ vars=vars)
# <install>/lib/site-packages/shiboken.so -> <setup>/PySide/shiboken.so
copyfile(
"{site_packages_dir}/shiboken.so",
"{dist_dir}/PySide/shiboken.so",
- logger=log, vars=vars)
+ vars=vars)
# <install>/lib/site-packages/pysideuic/* -> <setup>/pysideuic
copydir(
"{site_packages_dir}/pysideuic",
"{dist_dir}/pysideuic",
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# <install>/bin/pyside-uic -> PySide/scripts/uic.py
makefile(
"{dist_dir}/PySide/scripts/__init__.py",
- logger=log, vars=vars)
+ vars=vars)
copyfile(
"{install_dir}/bin/pyside-uic",
"{dist_dir}/PySide/scripts/uic.py",
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# <install>/bin/* -> PySide/
copydir(
"{install_dir}/bin/",
@@ -693,7 +693,7 @@ def prepare_packages_posix(self, vars):
"pyside-rcc",
"shiboken",
],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# <install>/lib/lib* -> PySide/
copydir(
"{install_dir}/lib/",
@@ -702,23 +702,23 @@ def prepare_packages_posix(self, vars):
"libpyside*" + so_star,
"libshiboken*" + so_star,
],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# <install>/share/PySide/typesystems/* -> <setup>/PySide/typesystems
copydir(
"{install_dir}/share/PySide/typesystems",
"{dist_dir}/PySide/typesystems",
- logger=log, vars=vars)
+ vars=vars)
# <install>/include/* -> <setup>/PySide/include
copydir(
"{install_dir}/include",
"{dist_dir}/PySide/include",
- logger=log, vars=vars)
+ vars=vars)
if not OPTION_NOEXAMPLES:
# <sources>/pyside-examples/examples/* -> <setup>/PySide/examples
copydir(
"{sources_dir}/pyside-examples/examples",
"{dist_dir}/PySide/examples",
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# Copy Qt libs to package
if OPTION_STANDALONE:
if sys.platform == 'darwin':
@@ -732,27 +732,27 @@ def prepare_packages_posix(self, vars):
"lupdate",
"lconvert",
],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# <qt>/lib/* -> <setup>/PySide
copydir("{qt_lib_dir}", "{dist_dir}/PySide",
filter=[
"libQt*.so.?",
"libphonon.so.?",
],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# <qt>/plugins/* -> <setup>/PySide/plugins
copydir("{qt_plugins_dir}", "{dist_dir}/PySide/plugins",
filter=["*.so"],
- logger=log, vars=vars)
+ vars=vars)
# <qt>/imports/* -> <setup>/PySide/imports
if float(vars["qt_version"][:3]) > 4.6:
copydir("{qt_imports_dir}", "{dist_dir}/PySide/imports",
filter=["qmldir", "*.so"],
- logger=log, vars=vars)
+ vars=vars)
# <qt>/translations/* -> <setup>/PySide/translations
copydir("{qt_translations_dir}", "{dist_dir}/PySide/translations",
filter=["*.qm"],
- logger=log, vars=vars)
+ vars=vars)
def prepare_packages_win32(self, vars):
pdbs = ['*.pdb'] if self.debug or self.build_type == 'RelWithDebInfo' else []
@@ -760,76 +760,76 @@ def prepare_packages_win32(self, vars):
copydir(
"{site_packages_dir}/PySide",
"{dist_dir}/PySide",
- logger=log, vars=vars)
+ vars=vars)
if self.debug or self.build_type == 'RelWithDebInfo':
# <build>/pyside/PySide/*.pdb -> <setup>/PySide
copydir(
"{build_dir}/pyside/PySide",
"{dist_dir}/PySide",
filter=pdbs,
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# <build>/shiboken/doc/html/* -> <setup>/PySide/docs/shiboken
copydir(
"{build_dir}/shiboken/doc/html",
"{dist_dir}/PySide/docs/shiboken",
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# <install>/lib/site-packages/shiboken.pyd -> <setup>/PySide/shiboken.pyd
copyfile(
"{site_packages_dir}/shiboken{dbgPostfix}.pyd",
"{dist_dir}/PySide/shiboken{dbgPostfix}.pyd",
- logger=log, vars=vars)
+ vars=vars)
if self.debug or self.build_type == 'RelWithDebInfo':
copyfile(
"{build_dir}/shiboken/shibokenmodule/shiboken{dbgPostfix}.pdb",
"{dist_dir}/PySide/shiboken{dbgPostfix}.pdb",
- logger=log, vars=vars)
+ vars=vars)
# <install>/lib/site-packages/pysideuic/* -> <setup>/pysideuic
copydir(
"{site_packages_dir}/pysideuic",
"{dist_dir}/pysideuic",
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# <install>/bin/pyside-uic -> PySide/scripts/uic.py
makefile(
"{dist_dir}/PySide/scripts/__init__.py",
- logger=log, vars=vars)
+ vars=vars)
copyfile(
"{install_dir}/bin/pyside-uic",
"{dist_dir}/PySide/scripts/uic.py",
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# <install>/bin/*.exe,*.dll,*.pdb -> PySide/
copydir(
"{install_dir}/bin/",
"{dist_dir}/PySide",
filter=["*.exe", "*.dll"] + pdbs,
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# <install>/lib/*.lib -> PySide/
copydir(
"{install_dir}/lib/",
"{dist_dir}/PySide",
filter=["*.lib"],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# <install>/share/PySide/typesystems/* -> <setup>/PySide/typesystems
copydir(
"{install_dir}/share/PySide/typesystems",
"{dist_dir}/PySide/typesystems",
- logger=log, vars=vars)
+ vars=vars)
# <install>/include/* -> <setup>/PySide/include
copydir(
"{install_dir}/include",
"{dist_dir}/PySide/include",
- logger=log, vars=vars)
+ vars=vars)
if not OPTION_NOEXAMPLES:
# <sources>/pyside-examples/examples/* -> <setup>/PySide/examples
copydir(
"{sources_dir}/pyside-examples/examples",
"{dist_dir}/PySide/examples",
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# <ssl_libs>/* -> <setup>/PySide/openssl
copydir("{ssl_libs_dir}", "{dist_dir}/PySide/openssl",
filter=[
"libeay32.dll",
"ssleay32.dll"],
- force=False, logger=log, vars=vars)
+ force=False, vars=vars)
# <qt>/bin/*.dll -> <setup>/PySide
copydir("{qt_bin_dir}", "{dist_dir}/PySide",
@@ -841,18 +841,18 @@ def prepare_packages_win32(self, vars):
"lupdate.exe",
"lconvert.exe"],
ignore=["*d4.dll"],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
if self.debug:
# <qt>/bin/*d4.dll -> <setup>/PySide
copydir("{qt_bin_dir}", "{dist_dir}/PySide",
filter=["*d4.dll"] + pdbs,
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
if self.debug or self.build_type == 'RelWithDebInfo':
# <qt>/lib/*.pdb -> <setup>/PySide
copydir("{qt_lib_dir}", "{dist_dir}/PySide",
filter=["*.pdb"],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# I think these are the qt-mobility DLLs, at least some are,
# so let's copy them too
@@ -860,41 +860,41 @@ def prepare_packages_win32(self, vars):
copydir("{qt_lib_dir}", "{dist_dir}/PySide",
filter=["*.dll"],
ignore=["*d?.dll"],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
if self.debug:
# <qt>/lib/*d4.dll -> <setup>/PySide
copydir("{qt_lib_dir}", "{dist_dir}/PySide",
filter=["*d?.dll"],
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
if self.debug or self.build_type == 'RelWithDebInfo':
# <qt>/lib/*pdb -> <setup>/PySide
copydir("{qt_lib_dir}", "{dist_dir}/PySide",
filter=pdbs,
- recursive=False, logger=log, vars=vars)
+ recursive=False, vars=vars)
# <qt>/plugins/* -> <setup>/PySide/plugins
copydir("{qt_plugins_dir}", "{dist_dir}/PySide/plugins",
filter=["*.dll"] + pdbs,
- logger=log, vars=vars)
+ vars=vars)
# <qt>/imports/* -> <setup>/PySide/imports
copydir("{qt_imports_dir}", "{dist_dir}/PySide/imports",
filter=["qmldir", "*.dll"] + pdbs,
- logger=log, vars=vars)
+ vars=vars)
# <qt>/translations/* -> <setup>/PySide/translations
copydir("{qt_translations_dir}", "{dist_dir}/PySide/translations",
filter=["*.qm"],
- logger=log, vars=vars)
+ vars=vars)
# pdb files for libshiboken and libpyside
if self.debug or self.build_type == 'RelWithDebInfo':
copyfile(
"{build_dir}/shiboken/libshiboken/shiboken-python{py_version}{dbgPostfix}.pdb",
"{dist_dir}/PySide/shiboken-python{py_version}{dbgPostfix}.pdb",
- logger=log, vars=vars)
+ vars=vars)
copyfile(
"{build_dir}/pyside/libpyside/pyside-python{py_version}{dbgPostfix}.pdb",
"{dist_dir}/PySide/pyside-python{py_version}{dbgPostfix}.pdb",
- logger=log, vars=vars)
+ vars=vars)
def read(fname):
View
91 utils.py
@@ -9,6 +9,7 @@
import itertools
import popenasync
+from distutils import log
from distutils.errors import DistutilsOptionError
from distutils.errors import DistutilsSetupError
from distutils.spawn import spawn
@@ -55,16 +56,16 @@ def filter_match(name, patterns):
return False
-def update_env_path(newpaths, logger):
+def update_env_path(newpaths):
paths = os.environ['PATH'].lower().split(os.pathsep)
for path in newpaths:
if not path.lower() in paths:
- logger.info("Inserting path \"%s\" to environment" % path)
+ log.info("Inserting path \"%s\" to environment" % path)
paths.insert(0, path)
os.environ['PATH'] = path + os.pathsep + os.environ['PATH']
-def winsdk_setenv(platform_arch, build_type, logger):
+def winsdk_setenv(platform_arch, build_type):
from distutils.msvc9compiler import VERSION as MSVC_VERSION
from distutils.msvc9compiler import Reg
from distutils.msvc9compiler import HKEYS
@@ -78,7 +79,7 @@ def winsdk_setenv(platform_arch, build_type, logger):
"v7.1": 10.0
}
- logger.info("Searching Windows SDK with MSVC compiler version %s" % MSVC_VERSION)
+ log.info("Searching Windows SDK with MSVC compiler version %s" % MSVC_VERSION)
setenv_paths = []
for base in HKEYS:
sdk_versions = Reg.read_keys(base, WINSDK_BASE)
@@ -102,11 +103,11 @@ def winsdk_setenv(platform_arch, build_type, logger):
"Failed to find the Windows SDK with MSVC compiler version %s"
% MSVC_VERSION)
for setenv_path in setenv_paths:
- logger.info("Found %s" % setenv_path)
+ log.info("Found %s" % setenv_path)
# Get SDK env (use latest SDK version installed on system)
setenv_path = setenv_paths[-1]
- logger.info("Using %s " % setenv_path)
+ log.info("Using %s " % setenv_path)
build_arch = "/x86" if platform_arch.startswith("32") else "/x64"
build_type = "/Debug" if build_type.lower() == "debug" else "/Release"
setenv_cmd = [setenv_path, build_arch, build_type]
@@ -115,13 +116,13 @@ def winsdk_setenv(platform_arch, build_type, logger):
setenv_env_without_paths = dict([(k, setenv_env[k]) for k in setenv_env if k.upper() != 'PATH'])
# Extend os.environ with SDK env
- logger.info("Initializing Windows SDK env...")
- update_env_path(setenv_env_paths, logger)
+ log.info("Initializing Windows SDK env...")
+ update_env_path(setenv_env_paths)
for k in sorted(setenv_env_without_paths):
v = setenv_env_without_paths[k]
- logger.info("Inserting \"%s = %s\" to environment" % (k, v))
+ log.info("Inserting \"%s = %s\" to environment" % (k, v))
os.environ[k] = v
- logger.info("Done initializing Windows SDK env")
+ log.info("Done initializing Windows SDK env")
def find_vcdir(version):
@@ -171,18 +172,18 @@ def find_vcdir(version):
return productdir
-def init_msvc_env(platform_arch, build_type, logger):
+def init_msvc_env(platform_arch, build_type):
from distutils.msvc9compiler import VERSION as MSVC_VERSION
- logger.info("Searching MSVC compiler version %s" % MSVC_VERSION)
+ log.info("Searching MSVC compiler version %s" % MSVC_VERSION)
vcdir_path = find_vcdir(MSVC_VERSION)
if not vcdir_path:
raise DistutilsSetupError(
"Failed to find the MSVC compiler version %s on your system." % MSVC_VERSION)
else:
- logger.info("Found %s" % vcdir_path)
+ log.info("Found %s" % vcdir_path)
- logger.info("Searching MSVC compiler %s environment init script" % MSVC_VERSION)
+ log.info("Searching MSVC compiler %s environment init script" % MSVC_VERSION)
if platform_arch.startswith("32"):
vcvars_path = os.path.join(vcdir_path, "bin", "vcvars32.bat")
else:
@@ -194,56 +195,53 @@ def init_msvc_env(platform_arch, build_type, logger):
if not os.path.exists(vcvars_path):
# MSVC init script not found, try to find and init Windows SDK env
- logger.error(
+ log.error(
"Failed to find the MSVC compiler environment init script (vcvars.bat) on your system.")
- winsdk_setenv(platform_arch, build_type, logger)
+ winsdk_setenv(platform_arch, build_type)
return
else:
- logger.info("Found %s" % vcvars_path)
+ log.info("Found %s" % vcvars_path)
# Get MSVC env
- logger.info("Using MSVC %s in %s" % (MSVC_VERSION, vcvars_path))
+ log.info("Using MSVC %s in %s" % (MSVC_VERSION, vcvars_path))
msvc_arch = "x86" if platform_arch.startswith("32") else "amd64"
- logger.info("Getting MSVC env for %s architecture" % msvc_arch)
+ log.info("Getting MSVC env for %s architecture" % msvc_arch)
vcvars_cmd = [vcvars_path, msvc_arch]
msvc_env = get_environment_from_batch_command(vcvars_cmd)
msvc_env_paths = os.pathsep.join([msvc_env[k] for k in msvc_env if k.upper() == 'PATH']).split(os.pathsep)
msvc_env_without_paths = dict([(k, msvc_env[k]) for k in msvc_env if k.upper() != 'PATH'])
# Extend os.environ with MSVC env
- logger.info("Initializing MSVC env...")
- update_env_path(msvc_env_paths, logger)
+ log.info("Initializing MSVC env...")
+ update_env_path(msvc_env_paths)
for k in sorted(msvc_env_without_paths):
v = msvc_env_without_paths[k]
- logger.info("Inserting \"%s = %s\" to environment" % (k, v))
+ log.info("Inserting \"%s = %s\" to environment" % (k, v))
os.environ[k] = v
- logger.info("Done initializing MSVC env")
+ log.info("Done initializing MSVC env")
-def copyfile(src, dst, logger=None, force=True, vars=None):
+def copyfile(src, dst, force=True, vars=None):
if vars is not None:
src = src.format(**vars)
dst = dst.format(**vars)
if not os.path.exists(src) and not force:
- if logger is not None:
- logger.info("**Skiping copy file %s to %s. Source does not exists." % (src, dst))
+ log.info("**Skiping copy file %s to %s. Source does not exists." % (src, dst))
return
- if logger is not None:
- logger.info("Copying file %s to %s." % (src, dst))
+ log.info("Copying file %s to %s." % (src, dst))
shutil.copy2(src, dst)
-def makefile(dst, content=None, logger=None, vars=None):
+def makefile(dst, content=None, vars=None):
if vars is not None:
if content is not None:
content = content.format(**vars)
dst = dst.format(**vars)
- if logger is not None:
- logger.info("Making file %s." % (dst))
+ log.info("Making file %s." % (dst))
dstdir = os.path.dirname(dst)
if not os.path.exists(dstdir):
@@ -255,7 +253,7 @@ def makefile(dst, content=None, logger=None, vars=None):
f.close()
-def copydir(src, dst, logger=None, filter=None, ignore=None, force=True,
+def copydir(src, dst, filter=None, ignore=None, force=True,
recursive=True, vars=None):
if vars is not None:
@@ -269,14 +267,12 @@ def copydir(src, dst, logger=None, filter=None, ignore=None, force=True,
ignore[i] = ignore[i].format(**vars)
if not os.path.exists(src) and not force:
- if logger is not None:
- logger.info("**Skiping copy tree %s to %s. Source does not exists. filter=%s. ignore=%s." % \
- (src, dst, filter, ignore))
+ log.info("**Skiping copy tree %s to %s. Source does not exists. filter=%s. ignore=%s." % \
+ (src, dst, filter, ignore))
return
- if logger is not None:
- logger.info("Copying tree %s to %s. filter=%s. ignore=%s." % \
- (src, dst, filter, ignore))
+ log.info("Copying tree %s to %s. filter=%s. ignore=%s." % \
+ (src, dst, filter, ignore))
names = os.listdir(src)
@@ -287,14 +283,14 @@ def copydir(src, dst, logger=None, filter=None, ignore=None, force=True,
try:
if os.path.isdir(srcname):
if recursive:
- copydir(srcname, dstname, logger, filter, ignore, force, recursive, vars)
+ copydir(srcname, dstname, filter, ignore, force, recursive, vars)
else:
if (filter is not None and not filter_match(name, filter)) or \
(ignore is not None and filter_match(name, ignore)):
continue
if not os.path.exists(dst):
os.makedirs(dst)
- copyfile(srcname, dstname, logger, True, vars)
+ copyfile(srcname, dstname, True, vars)
# catch the Error from the recursive copytree so that we can
# continue with other files
except shutil.Error as err:
@@ -324,8 +320,8 @@ def handleRemoveReadonly(func, path, exc):
shutil.rmtree(dirname, ignore_errors=False, onerror=handleRemoveReadonly)
-def run_process(args, logger=None, initial_env=None):
- def log(buffer, checkNewLine=False):
+def run_process(args, initial_env=None):
+ def _log(buffer, checkNewLine=False):
endsWithNewLine = False
if buffer.endswith('\n'):
endsWithNewLine = True
@@ -337,13 +333,10 @@ def log(buffer, checkNewLine=False):
buffer = lines[-1]
lines = lines[:-1]
for line in lines:
- if not logger is None:
- logger.info(line.rstrip('\r'))
- else:
- print(line.rstrip('\r'))
+ log.info(line.rstrip('\r'))
return buffer
- log("Running process: {0}".format(" ".join([(" " in x and '"{0}"'.format(x) or x) for x in args])))
+ _log("Running process: {0}".format(" ".join([(" " in x and '"{0}"'.format(x) or x) for x in args])))
if sys.platform != "win32":
try:
@@ -369,9 +362,9 @@ def log(buffer, checkNewLine=False):
log_buffer = None;
while proc.poll() is None:
- log_buffer = log(proc.read_async(wait=0.1, e=0))
+ log_buffer = _log(proc.read_async(wait=0.1, e=0))
if log_buffer:
- log(log_buffer)
+ _log(log_buffer)
proc.wait()
return proc.returncode
Please sign in to comment.
Something went wrong with that request. Please try again.