How to use the pex.compatibility.to_bytes function in pex

To help you get started, we’ve selected a few pex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pantsbuild / pex / tests / test_pex.py View on Github external
def test_pex_sys_exit_prints_objects():
  _test_sys_exit('Exception("derp")', to_bytes('derp\n'), 1)
github pantsbuild / pex / tests / test_compatibility.py View on Github external
def test_to_bytes():
  assert isinstance(to_bytes(''), bytes)
  assert isinstance(to_bytes('abc'), bytes)
  assert isinstance(to_bytes(b'abc'), bytes)
  assert isinstance(to_bytes(u'abc'), bytes)
  assert isinstance(to_bytes(b'abc'.decode('latin-1'), encoding='utf-8'), bytes)

  for bad_value in (123, None):
    with pytest.raises(ValueError):
      to_bytes(bad_value)
github pantsbuild / pex / tests / test_compiler.py View on Github external
def write_source(path, valid=True):
  with safe_open(path, 'wb') as fp:
    fp.write(to_bytes('basename = %r\n' % os.path.basename(path)))
    if not valid:
      fp.write(to_bytes('invalid!\n'))
github pantsbuild / pex / tests / test_integration.py View on Github external
'--python={}'.format(py27_interpreter),
                               '--python={}'.format(py36_interpreter),
                               '-o', pex])
    results.assert_success()

    pex_program = [pex, '-c']
    py2_only_program = pex_program + ['import functools32']
    both_program = pex_program + [
      'import jsonschema, os, sys; print(os.path.realpath(sys.executable))'
    ]

    py27_env = make_env(PATH=os.path.dirname(py27_interpreter))
    subprocess.check_call(py2_only_program, env=py27_env)

    stdout = subprocess.check_output(both_program, env=py27_env)
    assert to_bytes(os.path.realpath(py27_interpreter)) == stdout.strip()

    py36_env = make_env(PATH=os.path.dirname(py36_interpreter))
    with pytest.raises(subprocess.CalledProcessError):
      subprocess.check_call(py2_only_program, env=py36_env)

    stdout = subprocess.check_output(both_program, env=py36_env)
    assert to_bytes(os.path.realpath(py36_interpreter)) == stdout.strip()
github pantsbuild / pex / tests / test_pex_binary.py View on Github external
def test_clp_preamble_file():
  with NamedTemporaryFile() as tmpfile:
    tmpfile.write(to_bytes('print "foo!"'))
    tmpfile.flush()

    parser = configure_clp()
    options, reqs = parser.parse_args(args=['--preamble-file', tmpfile.name])
    assert options.preamble_file == tmpfile.name

    pex_builder = build_pex(reqs, options)
    assert pex_builder._preamble == 'print "foo!"'
github pantsbuild / pex / tests / test_compatibility.py View on Github external
def test_to_bytes():
  assert isinstance(to_bytes(''), bytes)
  assert isinstance(to_bytes('abc'), bytes)
  assert isinstance(to_bytes(b'abc'), bytes)
  assert isinstance(to_bytes(u'abc'), bytes)
  assert isinstance(to_bytes(b'abc'.decode('latin-1'), encoding='utf-8'), bytes)

  for bad_value in (123, None):
    with pytest.raises(ValueError):
      to_bytes(bad_value)
github pantsbuild / pants / src / python / pants / backend / python / commands / setup_py.py View on Github external
def convert(input):
      if isinstance(input, dict):
        out = dict()
        for key, value in input.items():
          out[convert(key)] = convert(value)
        return out
      elif isinstance(input, list):
        return [convert(element) for element in input]
      elif isinstance(input, string):
        return to_bytes(input)
      else:
        return input
github pantsbuild / pants / src / python / pants / backend / python / commands / setup_py.py View on Github external
def convert(input):
      if isinstance(input, dict):
        out = dict()
        for key, value in input.items():
          out[convert(key)] = convert(value)
        return out
      elif isinstance(input, list):
        return [convert(element) for element in input]
      elif isinstance(input, string):
        return to_bytes(input)
      else:
        return input
github pantsbuild / pants / src / python / pants / backend / python / tasks2 / setup_py.py View on Github external
def convert(input):
      if isinstance(input, dict):
        out = dict()
        for key, value in input.items():
          out[convert(key)] = convert(value)
        return out
      elif isinstance(input, list):
        return [convert(element) for element in input]
      elif isinstance(input, string):
        return to_bytes(input)
      else:
        return input