示例#1
0
  def run(self):
    if self._installed is not None:
      return self._installed

    with TRACER.timed('Installing %s' % self._install_tmp, V=2):
      env = self._interpreter.sanitized_environment()
      mixins = OrderedSet(['setuptools'] + self.mixins)
      env['PYTHONPATH'] = os.pathsep.join(third_party.expose(mixins))
      env['__PEX_UNVENDORED__'] = '1'

      command = [self._interpreter.binary, '-s', '-'] + self.setup_command()
      try:
        Executor.execute(command,
                         env=env,
                         cwd=self._source_dir,
                         stdin_payload=self.setup_py_wrapper.encode('ascii'))
        self._installed = True
      except Executor.NonZeroExit as e:
        self._installed = False
        name = os.path.basename(self._source_dir)
        print('**** Failed to install %s (caused by: %r\n):' % (name, e), file=sys.stderr)
        print('stdout:\n%s\nstderr:\n%s\n' % (e.stdout, e.stderr), file=sys.stderr)
        return self._installed

    return self._installed
示例#2
0
def test_executor_execute_nonzero(exit_code):
    # type: (int) -> None
    with pytest.raises(Executor.NonZeroExit) as exc:
        Executor.execute("exit %s" % exit_code, shell=True)

    if exit_code > 0:
        assert exc.value.exit_code == exit_code
示例#3
0
def test_executor_execute_dir():
  with temporary_dir() as temp_dir:
    test_dir = os.path.realpath(os.path.join(temp_dir, 'tmp'))
    safe_mkdir(test_dir)
    assert os.path.isdir(test_dir)
    with pytest.raises(Executor.ExecutionError) as e:
      Executor.execute(test_dir)
    assert test_dir in str(e)
示例#4
0
def test_executor_execute_dir():
  with temporary_dir() as temp_dir:
    test_dir = os.path.realpath(os.path.join(temp_dir, 'tmp'))
    safe_mkdir(test_dir)
    assert os.path.isdir(test_dir)
    with pytest.raises(Executor.ExecutionError) as e:
      Executor.execute(test_dir)
    assert test_dir in str(e)
示例#5
0
def test_executor_execute_stdio():
  with temporary_dir() as tmp:
    with open(os.path.join(tmp, 'stdout'), 'w+b') as fake_stdout:
      with open(os.path.join(tmp, 'stderr'), 'w+b') as fake_stderr:
        Executor.execute('/bin/echo -n TEST | tee /dev/stderr',
                         shell=True,
                         stdout=fake_stdout,
                         stderr=fake_stderr)
        fake_stdout.seek(0)
        fake_stderr.seek(0)
        assert fake_stdout.read().decode('utf-8') == 'TEST'
        assert fake_stderr.read().decode('utf-8') == 'TEST'
示例#6
0
def test_executor_execute_stdio():
  with temporary_dir() as tmp:
    with open(os.path.join(tmp, 'stdout'), 'w+b') as fake_stdout:
      with open(os.path.join(tmp, 'stderr'), 'w+b') as fake_stderr:
        Executor.execute('/bin/echo -n TEST | tee /dev/stderr',
                         shell=True,
                         stdout=fake_stdout,
                         stderr=fake_stderr)
        fake_stdout.seek(0)
        fake_stderr.seek(0)
        assert fake_stdout.read().decode('utf-8') == 'TEST'
        assert fake_stderr.read().decode('utf-8') == 'TEST'
示例#7
0
    def compile(self, root, relpaths):
        """Compiles the given python source files using this compiler's interpreter.

    :param string root: The root path all the source files are found under.
    :param list relpaths: The realtive paths from the `root` of the source files to compile.
    :returns: A list of relative paths of the compiled bytecode files.
    :raises: A :class:`Compiler.Error` if there was a problem bytecode compiling any of the files.
    """
        with named_temporary_file() as fp:
            fp.write(
                to_bytes(_COMPILER_MAIN % {
                    'root': root,
                    'relpaths': relpaths
                },
                         encoding='utf-8'))
            fp.flush()

            try:
                out, _ = Executor.execute(
                    [self._interpreter.binary, '-sE', fp.name])
            except Executor.NonZeroExit as e:
                raise self.CompilationFailure(
                    'encountered %r during bytecode compilation.\nstderr was:\n%s\n'
                    % (e, e.stderr))

            return out.splitlines()
示例#8
0
 def _from_binary_external(cls, binary):
   environ = cls.sanitized_environment()
   stdout, _ = Executor.execute([binary, '-sE'],
                                env=environ,
                                stdin_payload=_generate_identity_source())
   identity = stdout.strip()
   if not identity:
     raise cls.IdentificationError('Could not establish identity of %s' % binary)
   return cls(binary, PythonIdentity.from_id_string(identity))
示例#9
0
 def _from_binary_external(cls, binary):
   environ = cls.sanitized_environment()
   stdout, _ = Executor.execute([binary, '-sE'],
                                env=environ,
                                stdin_payload=_generate_identity_source())
   identity = stdout.strip()
   if not identity:
     raise cls.IdentificationError('Could not establish identity of %s' % binary)
   return cls(binary, PythonIdentity.from_id_string(identity))
示例#10
0
  def run(self):
    if self._installed is not None:
      return self._installed

    with TRACER.timed('Installing %s' % self._install_tmp, V=2):
      command = [self._interpreter.binary, '-sE', '-'] + self._setup_command()
      try:
        Executor.execute(command,
                         env=self._interpreter.sanitized_environment(),
                         cwd=self._source_dir,
                         stdin_payload=self.bootstrap_script.encode('ascii'))
        self._installed = True
      except Executor.NonZeroExit as e:
        self._installed = False
        name = os.path.basename(self._source_dir)
        print('**** Failed to install %s (caused by: %r\n):' % (name, e), file=sys.stderr)
        print('stdout:\n%s\nstderr:\n%s\n' % (e.stdout, e.stderr), file=sys.stderr)
        return self._installed

    return self._installed
示例#11
0
def test_executor_execute():
  assert Executor.execute('/bin/echo -n stdout >&1', shell=True) == ('stdout', '')
  assert Executor.execute('/bin/echo -n stderr >&2', shell=True) == ('', 'stderr')
  assert Executor.execute('/bin/echo -n TEST | tee /dev/stderr', shell=True) == ('TEST', 'TEST')
  assert Executor.execute(['/bin/echo', 'hello']) == ('hello\n', '')
  assert Executor.execute(['/bin/echo', '-n', 'hello']) == ('hello', '')
  assert Executor.execute('/bin/echo -n $HELLO', env={'HELLO': 'hey'}, shell=True) == ('hey', '')
示例#12
0
def test_executor_execute():
  assert Executor.execute('/bin/echo -n stdout >&1', shell=True) == ('stdout', '')
  assert Executor.execute('/bin/echo -n stderr >&2', shell=True) == ('', 'stderr')
  assert Executor.execute('/bin/echo -n TEST | tee /dev/stderr', shell=True) == ('TEST', 'TEST')
  assert Executor.execute(['/bin/echo', 'hello']) == ('hello\n', '')
  assert Executor.execute(['/bin/echo', '-n', 'hello']) == ('hello', '')
  assert Executor.execute('/bin/echo -n $HELLO', env={'HELLO': 'hey'}, shell=True) == ('hey', '')
示例#13
0
def test_executor_execute():
    # type: () -> None
    assert Executor.execute("/bin/echo -n stdout >&1", shell=True) == ("stdout", "")
    assert Executor.execute("/bin/echo -n stderr >&2", shell=True) == ("", "stderr")
    assert Executor.execute("/bin/echo -n TEST | tee /dev/stderr", shell=True) == ("TEST", "TEST")
    assert Executor.execute(["/bin/echo", "hello"]) == ("hello\n", "")
    assert Executor.execute(["/bin/echo", "-n", "hello"]) == ("hello", "")
    assert Executor.execute("/bin/echo -n $HELLO", env={"HELLO": "hey"}, shell=True) == ("hey", "")
示例#14
0
 def _execute(cls,
              binary,
              args=None,
              pythonpath=None,
              env=None,
              stdin_payload=None,
              **kwargs):
     cmd, env = cls._create_isolated_cmd(binary,
                                         args=args,
                                         pythonpath=pythonpath,
                                         env=env)
     stdout, stderr = Executor.execute(cmd,
                                       stdin_payload=stdin_payload,
                                       env=env,
                                       **kwargs)
     return cmd, stdout, stderr
示例#15
0
 def execute(
         self,
         args=None,  # type: Optional[Iterable[str]]
         stdin_payload=None,  # type: Optional[AnyStr]
         pythonpath=None,  # type: Optional[Iterable[str]]
         env=None,  # type: Optional[Mapping[str, str]]
         **kwargs  # type: Any
 ):
     # type: (...) -> Tuple[Iterable[str], str, str]
     cmd, env = self.create_isolated_cmd(args=args,
                                         pythonpath=pythonpath,
                                         env=env)
     stdout, stderr = Executor.execute(cmd,
                                       stdin_payload=stdin_payload,
                                       env=env,
                                       **kwargs)
     return cmd, stdout, stderr
示例#16
0
文件: compiler.py 项目: jsirois/pex
  def compile(self, root, relpaths):
    """Compiles the given python source files using this compiler's interpreter.

    :param string root: The root path all the source files are found under.
    :param list relpaths: The realtive paths from the `root` of the source files to compile.
    :returns: A list of relative paths of the compiled bytecode files.
    :raises: A :class:`Compiler.Error` if there was a problem bytecode compiling any of the files.
    """
    with named_temporary_file() as fp:
      fp.write(to_bytes(_COMPILER_MAIN % {'root': root, 'relpaths': relpaths}, encoding='utf-8'))
      fp.flush()

      try:
        out, _ = Executor.execute([self._interpreter.binary, '-sE', fp.name])
      except Executor.NonZeroExit as e:
        raise self.CompilationFailure(
          'encountered %r during bytecode compilation.\nstderr was:\n%s\n' % (e, e.stderr)
        )

      return out.splitlines()
示例#17
0
def test_executor_execute_zero():
    # type: () -> None
    Executor.execute("exit 0", shell=True)
示例#18
0
def test_executor_execute_nonzero(exit_code):
  with pytest.raises(Executor.NonZeroExit) as exc:
    Executor.execute('exit %s' % exit_code, shell=True)

  if exit_code > 0:
    assert exc.value.exit_code == exit_code
示例#19
0
def test_executor_execute_zero():
  Executor.execute('exit 0', shell=True)
示例#20
0
def test_executor_execute_zero():
  Executor.execute('exit 0', shell=True)
示例#21
0
def test_executor_execute_nonzero(exit_code):
  with pytest.raises(Executor.NonZeroExit) as exc:
    Executor.execute('exit %s' % exit_code, shell=True)

  if exit_code > 0:
    assert exc.value.exit_code == exit_code
示例#22
0
def test_executor_execute_zero():
    Executor.execute("exit 0", shell=True)