我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用distutils.sysconfig()。
def test_sitepackagesdir(monkeypatch): import distutils.sysconfig as sysconfig test_envdir = "holy grail" test_dir = "Now go away or I will taunt you a second time." def dummy_get_python_lib(prefix): assert prefix is test_envdir return test_dir monkeypatch.setattr(sysconfig, "get_python_lib", dummy_get_python_lib) assert sitepackagesdir(test_envdir) == {"dir": test_dir}
def _add_env_libs_and_src(self): LOGGER.info('Add sources and libraries from current environment') Repo(path=self.repository).clone(path=self.workspace) shutil.rmtree(os.path.join(self.workspace, '.git')) package_path = distutils.sysconfig.get_python_lib() self.__add_package_from_path(package_path) for package in self.ignored_packages: try: shutil.rmtree(os.path.join(self.workspace, package)) except OSError: pass
def get_exe_bytes(self): from distutils.msvccompiler import get_build_version # If a target-version other than the current version has been # specified, then using the MSVC version from *this* build is no good. # Without actually finding and executing the target version and parsing # its sys.version, we just hard-code our knowledge of old versions. # NOTE: Possible alternative is to allow "--target-version" to # specify a Python executable rather than a simple version string. # We can then execute this program to obtain any info we need, such # as the real sys.version string for the build. cur_version = get_python_version() if self.target_version and self.target_version != cur_version: # If the target version is *later* than us, then we assume they # use what we use # string compares seem wrong, but are what sysconfig.py itself uses if self.target_version > cur_version: bv = get_build_version() else: if self.target_version < "2.4": bv = 6.0 else: bv = 7.1 else: # for current version - use authoritative check. bv = get_build_version() # wininst-x.y.exe is in the same directory as this file directory = os.path.dirname(__file__) # we must use a wininst-x.y.exe built with the same C compiler # used for python. XXX What about mingw, borland, and so on? # if plat_name starts with "win" but is not "win32" # we want to strip "win" and leave the rest (e.g. -amd64) # for all other cases, we don't want any suffix if self.plat_name != 'win32' and self.plat_name[:3] == 'win': sfix = self.plat_name[3:] else: sfix = '' filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) f = open(filename, "rb") try: return f.read() finally: f.close()