我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用distutils.errors.DistutilsInternalError()。
def get_cmd(cmdname, _cache={}): if cmdname not in _cache: import distutils.core dist = distutils.core._setup_distribution if dist is None: from distutils.errors import DistutilsInternalError raise DistutilsInternalError( 'setup distribution instance not initialized') cmd = dist.get_command_obj(cmdname) _cache[cmdname] = cmd return _cache[cmdname]
def _install_dist_package(self): # Get the name of the package that we just built package_name = self.distribution.get_name() # Get the dist directory that bdist_wheel put the package in # Create the lambda build dir self._lambda_build_dir = os.path.join('build', 'ldist-'+package_name) try: if os.path.exists(self._lambda_build_dir): shutil.rmtree(self._lambda_build_dir) log.info('creating {}'.format(self._lambda_build_dir)) os.makedirs(self._lambda_build_dir) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(self._lambda_build_dir): pass else: raise DistutilsInternalError('{} already exists and is not a directory'.format(self._lambda_build_dir)) log.info('installing package {} from {} into {}'.format(package_name, self._dist_dir, self._lambda_build_dir)) pip = Popen(['pip', 'install', '-f', self._dist_dir, '-t', self._lambda_build_dir, package_name], stdout=PIPE, stderr=PIPE) stdout, stderr = pip.communicate() log.debug("pip stdout: {}".format(stdout)) log.debug("pip stderr: {}".format(stderr)) if pip.returncode is not 0: raise DistutilsPlatformError('pip returned unsuccessfully')