例如,我可以使用python setup.py build --compiler=msvc
或python setup.py build --compiler=mingw32
或仅使用python setup.py build
,在这种情况下,将使用默认编译器(例如bcpp
)。如何在setup.py中获取编译器名称(例如分别为msvc
,mingw32
和bcpp
)?
UPD .:我不需要默认的编译器,我需要将要使用的[[actually]],但不一定是默认的编译器。到目前为止,我没有找到比解析sys.argv
来查看是否存在--compiler...
字符串更好的方法。
import distutils.ccompiler
class BuildWithDLLs(build):
# On Windows, we install the git2.dll too.
def _get_dlls(self):
# return a list of of (FQ-in-name, relative-out-name) tuples.
ret = []
bld_ext = self.distribution.get_command_obj('build_ext')
compiler_type = bld_ext.compiler.compiler_type