setup.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:solaris-ips 作者: oracle 项目源码 文件源码
def syntax_check(filename):
        """ Run python's compiler over the file, and discard the results.
            Arrange to generate an exception if the file does not compile.
            This is needed because distutil's own use of pycompile (in the
            distutils.utils module) is broken, and doesn't stop on error. """
        try:
                tmpfd, tmp_file = tempfile.mkstemp()
                py_compile.compile(filename, tmp_file, doraise=True)
        except py_compile.PyCompileError as e:
                res = ""
                for err in e.exc_value:
                        if isinstance(err, six.string_types):
                                res += err + "\n"
                                continue

                        # Assume it's a tuple of (filename, lineno, col, code)
                        fname, line, col, code = err
                        res += "line {0:d}, column {1}, in {2}:\n{3}".format(
                            line, col or "unknown", fname, code)

                raise DistutilsError(res)
        finally:
                os.remove(tmp_file)

# On Solaris, ld inserts the full argument to the -o option into the symbol
# table.  This means that the resulting object will be different depending on
# the path at which the workspace lives, and not just on the interesting content
# of the object.
#
# In order to work around that bug (7076871), we create a new compiler class
# that looks at the argument indicating the output file, chdirs to its
# directory, and runs the real link with the output file set to just the base
# name of the file.
#
# Unfortunately, distutils isn't too customizable in this regard, so we have to
# twiddle with a couple of the names in the distutils.ccompiler namespace: we
# have to add a new entry to the compiler_class dict, and we have to override
# the new_compiler() function to point to our own.  Luckily, our copy of
# new_compiler() gets to be very simple, since we always know what we want to
# return.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号