diff options
Diffstat (limited to 'distutils2/compiler')
| -rw-r--r-- | distutils2/compiler/__init__.py | 4 | ||||
| -rw-r--r-- | distutils2/compiler/bcppcompiler.py | 12 | ||||
| -rw-r--r-- | distutils2/compiler/ccompiler.py | 21 | ||||
| -rw-r--r-- | distutils2/compiler/cygwinccompiler.py | 11 | ||||
| -rw-r--r-- | distutils2/compiler/extension.py | 6 | ||||
| -rw-r--r-- | distutils2/compiler/msvc9compiler.py | 16 | ||||
| -rw-r--r-- | distutils2/compiler/msvccompiler.py | 12 | ||||
| -rw-r--r-- | distutils2/compiler/unixccompiler.py | 8 |
8 files changed, 42 insertions, 48 deletions
diff --git a/distutils2/compiler/__init__.py b/distutils2/compiler/__init__.py index 2f95319..c69a57b 100644 --- a/distutils2/compiler/__init__.py +++ b/distutils2/compiler/__init__.py @@ -142,7 +142,7 @@ def show_compilers(): compilers = [] for name, cls in _COMPILERS.items(): - if isinstance(cls, basestring): + if isinstance(cls, str): cls = resolve_name(cls) _COMPILERS[name] = cls @@ -179,7 +179,7 @@ def new_compiler(plat=None, compiler=None, verbose=0, dry_run=False, msg = msg + " with '%s' compiler" % compiler raise PackagingPlatformError(msg) - if isinstance(cls, basestring): + if isinstance(cls, str): cls = resolve_name(cls) _COMPILERS[compiler] = cls diff --git a/distutils2/compiler/bcppcompiler.py b/distutils2/compiler/bcppcompiler.py index b7d5bb3..972c0f4 100644 --- a/distutils2/compiler/bcppcompiler.py +++ b/distutils2/compiler/bcppcompiler.py @@ -104,7 +104,7 @@ class BCPPCompiler(CCompiler) : # This needs to be compiled to a .res file -- do it now. try: self.spawn(["brcc32", "-fo", obj, src]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) continue # the 'for' loop @@ -128,7 +128,7 @@ class BCPPCompiler(CCompiler) : self.spawn([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs + [src]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) return objects @@ -146,7 +146,7 @@ class BCPPCompiler(CCompiler) : pass # XXX what goes here? try: self.spawn([self.lib] + lib_args) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LibError(msg) else: logger.debug("skipping %s (up-to-date)", output_filename) @@ -268,7 +268,7 @@ class BCPPCompiler(CCompiler) : self.mkpath(os.path.dirname(output_filename)) try: self.spawn([self.linker] + ld_args) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LinkError(msg) else: @@ -351,5 +351,5 @@ class BCPPCompiler(CCompiler) : self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) - except PackagingExecError, exc: - raise CompileError(exc) + except PackagingExecError as msg: + raise CompileError(msg) diff --git a/distutils2/compiler/ccompiler.py b/distutils2/compiler/ccompiler.py index 8ea2e50..009ba46 100644 --- a/distutils2/compiler/ccompiler.py +++ b/distutils2/compiler/ccompiler.py @@ -12,7 +12,7 @@ from distutils2.errors import CompileError, LinkError, UnknownFileError from distutils2.compiler import gen_preprocess_options -class CCompiler(object): +class CCompiler: """Abstract base class to define the interface that must be implemented by real compiler classes. Also has some utility methods used by several compiler classes. @@ -148,7 +148,7 @@ class CCompiler(object): self.set_executable(key, value) def set_executable(self, key, value): - if isinstance(value, basestring): + if isinstance(value, str): setattr(self, key, split_quoted(value)) else: setattr(self, key, value) @@ -170,8 +170,8 @@ class CCompiler(object): if not (isinstance(defn, tuple) and (len(defn) == 1 or (len(defn) == 2 and - (isinstance(defn[1], basestring) or defn[1] is None))) and - isinstance(defn[0], basestring)): + (isinstance(defn[1], str) or defn[1] is None))) and + isinstance(defn[0], str)): raise TypeError(("invalid macro definition '%s': " % defn) + \ "must be tuple (string,), (string, string), or " + \ "(string, None)") @@ -311,7 +311,7 @@ class CCompiler(object): """Process arguments and decide which source files to compile.""" if outdir is None: outdir = self.output_dir - elif not isinstance(outdir, basestring): + elif not isinstance(outdir, str): raise TypeError("'output_dir' must be a string or None") if macros is None: @@ -371,7 +371,7 @@ class CCompiler(object): """ if output_dir is None: output_dir = self.output_dir - elif not isinstance(output_dir, basestring): + elif not isinstance(output_dir, str): raise TypeError("'output_dir' must be a string or None") if macros is None: @@ -403,7 +403,7 @@ class CCompiler(object): if output_dir is None: output_dir = self.output_dir - elif not isinstance(output_dir, basestring): + elif not isinstance(output_dir, str): raise TypeError("'output_dir' must be a string or None") return objects, output_dir @@ -727,8 +727,7 @@ class CCompiler(object): if library_dirs is None: library_dirs = [] fd, fname = tempfile.mkstemp(".c", funcname, text=True) - f = os.fdopen(fd, "w") - try: + with os.fdopen(fd, "w") as f: for incl in includes: f.write("""#include "%s"\n""" % incl) f.write("""\ @@ -736,8 +735,6 @@ main (int argc, char **argv) { %s(); } """ % funcname) - finally: - f.close() try: objects = self.compile([fname], include_dirs=include_dirs) except CompileError: @@ -854,7 +851,7 @@ main (int argc, char **argv) { return return move(src, dst) - def mkpath(self, name, mode=0777): + def mkpath(self, name, mode=0o777): name = os.path.normpath(name) if os.path.isdir(name) or name == '': return diff --git a/distutils2/compiler/cygwinccompiler.py b/distutils2/compiler/cygwinccompiler.py index 2b1c59a..4b0b786 100644 --- a/distutils2/compiler/cygwinccompiler.py +++ b/distutils2/compiler/cygwinccompiler.py @@ -156,13 +156,13 @@ class CygwinCCompiler(UnixCCompiler): # gcc needs '.res' and '.rc' compiled to object files !!! try: self.spawn(["windres", "-i", src, "-o", obj]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) else: # for other files use the C-compiler try: self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) def link(self, target_desc, objects, output_filename, output_dir=None, @@ -344,14 +344,11 @@ def check_config_h(): # let's see if __GNUC__ is mentioned in python.h fn = sysconfig.get_config_h_filename() try: - config_h = open(fn) - try: + with open(fn) as config_h: if "__GNUC__" in config_h.read(): return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn else: return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn - finally: - config_h.close() - except IOError, exc: + except IOError as exc: return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror)) diff --git a/distutils2/compiler/extension.py b/distutils2/compiler/extension.py index 1ccf30c..f5fc0c0 100644 --- a/distutils2/compiler/extension.py +++ b/distutils2/compiler/extension.py @@ -13,7 +13,7 @@ from distutils2 import logger # order to do anything. -class Extension(object): +class Extension: """Just a collection of attributes that describes an extension module and everything needed to build it (hopefully in a portable way, but there are hooks that let you be as unportable as you need). @@ -86,14 +86,14 @@ class Extension(object): extra_compile_args=None, extra_link_args=None, export_symbols=None, swig_opts=None, depends=None, language=None, optional=None, **kw): - if not isinstance(name, basestring): + if not isinstance(name, str): raise AssertionError("'name' must be a string") if not isinstance(sources, list): raise AssertionError("'sources' must be a list of strings") for v in sources: - if not isinstance(v, basestring): + if not isinstance(v, str): raise AssertionError("'sources' must be a list of strings") self.name = name diff --git a/distutils2/compiler/msvc9compiler.py b/distutils2/compiler/msvc9compiler.py index a7a524e..fb53d7d 100644 --- a/distutils2/compiler/msvc9compiler.py +++ b/distutils2/compiler/msvc9compiler.py @@ -46,7 +46,7 @@ PLAT_TO_VCVARS = { } -class Reg(object): +class Reg: """Helper class to read values from the registry """ @@ -108,7 +108,7 @@ class Reg(object): return s convert_mbcs = staticmethod(convert_mbcs) -class MacroExpander(object): +class MacroExpander: def __init__(self, version): self.macros = {} @@ -477,7 +477,7 @@ class MSVCCompiler(CCompiler) : try: self.spawn([self.rc] + pp_opts + [output_opt] + [input_opt]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) continue elif ext in self._mc_extensions: @@ -504,7 +504,7 @@ class MSVCCompiler(CCompiler) : self.spawn([self.rc] + ["/fo" + obj] + [rc_file]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) continue else: @@ -517,7 +517,7 @@ class MSVCCompiler(CCompiler) : self.spawn([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) return objects @@ -542,7 +542,7 @@ class MSVCCompiler(CCompiler) : pass # XXX what goes here? try: self.spawn([self.lib] + lib_args) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LibError(msg) else: logger.debug("skipping %s (up-to-date)", output_filename) @@ -620,7 +620,7 @@ class MSVCCompiler(CCompiler) : self.mkpath(os.path.dirname(output_filename)) try: self.spawn([self.linker] + ld_args) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LinkError(msg) # embed the manifest @@ -637,7 +637,7 @@ class MSVCCompiler(CCompiler) : try: self.spawn(['mt.exe', '-nologo', '-manifest', temp_manifest, out_arg]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LinkError(msg) else: logger.debug("skipping %s (up-to-date)", output_filename) diff --git a/distutils2/compiler/msvccompiler.py b/distutils2/compiler/msvccompiler.py index fb4d521..7a0d313 100644 --- a/distutils2/compiler/msvccompiler.py +++ b/distutils2/compiler/msvccompiler.py @@ -105,7 +105,7 @@ def convert_mbcs(s): return s -class MacroExpander(object): +class MacroExpander: def __init__(self, version): self.macros = {} @@ -386,7 +386,7 @@ class MSVCCompiler(CCompiler): try: self.spawn([self.rc] + pp_opts + [output_opt] + [input_opt]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) continue elif ext in self._mc_extensions: @@ -415,7 +415,7 @@ class MSVCCompiler(CCompiler): self.spawn([self.rc] + ["/fo" + obj] + [rc_file]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) continue else: @@ -429,7 +429,7 @@ class MSVCCompiler(CCompiler): self.spawn([self.cc] + compile_opts + pp_opts + [input_opt, output_opt] + extra_postargs) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) return objects @@ -448,7 +448,7 @@ class MSVCCompiler(CCompiler): pass # XXX what goes here? try: self.spawn([self.lib] + lib_args) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LibError(msg) else: @@ -515,7 +515,7 @@ class MSVCCompiler(CCompiler): self.mkpath(os.path.dirname(output_filename)) try: self.spawn([self.linker] + ld_args) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LinkError(msg) else: diff --git a/distutils2/compiler/unixccompiler.py b/distutils2/compiler/unixccompiler.py index 02af746..95bcd79 100644 --- a/distutils2/compiler/unixccompiler.py +++ b/distutils2/compiler/unixccompiler.py @@ -165,7 +165,7 @@ class UnixCCompiler(CCompiler): self.mkpath(os.path.dirname(output_file)) try: self.spawn(pp_args) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): @@ -175,7 +175,7 @@ class UnixCCompiler(CCompiler): try: self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs) - except PackagingExecError, msg: + except PackagingExecError as msg: raise CompileError(msg) def create_static_lib(self, objects, output_libname, @@ -199,7 +199,7 @@ class UnixCCompiler(CCompiler): if self.ranlib: try: self.spawn(self.ranlib + [output_filename]) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LibError(msg) else: logger.debug("skipping %s (up-to-date)", output_filename) @@ -253,7 +253,7 @@ class UnixCCompiler(CCompiler): linker = _darwin_compiler_fixup(linker, ld_args) self.spawn(linker + ld_args) - except PackagingExecError, msg: + except PackagingExecError as msg: raise LinkError(msg) else: logger.debug("skipping %s (up-to-date)", output_filename) |
