def test_pants_binary_interpreter_selection_with_pexrc(self):
    py27 = '2.7'
    py3 = '3'
    if self.skip_if_no_python(py27) or self.skip_if_no_python(py3):
      return

    py27_path, py3_path = self.python_interpreter_path(py27), self.python_interpreter_path(py3)
    with setup_pexrc_with_pex_python_path(os.path.join(os.path.dirname(sys.argv[0]), '.pexrc')  , [py27_path, py3_path]):
      with temporary_dir() as interpreters_cache:
        pants_ini_config = {'python-setup': {'interpreter_cache_dir': interpreters_cache}}
        pants_run_27 = self.run_pants(
          command=['binary', '{}:main_py2'.format(os.path.join(self.testproject, 'python_3_selection_testing'))],
          config=pants_ini_config
        )
        self.assert_success(pants_run_27)
        pants_run_3 = self.run_pants(
          command=['binary', '{}:main_py3'.format(os.path.join(self.testproject, 'python_3_selection_testing'))],
          config=pants_ini_config
        )
        self.assert_success(pants_run_3)

    # Ensure proper interpreter constraints were passed to built pexes.
    py2_pex = os.path.join(os.getcwd(), 'dist', 'main_py2.pex')
    py3_pex = os.path.join(os.getcwd(), 'dist', 'main_py3.pex')
    py2_info = get_pex_info(py2_pex)
    py3_info = get_pex_info(py3_pex)
    self.assertIn('CPython>2.7.6,<3', py2_info.interpreter_constraints)
    self.assertIn('CPython>3', py3_info.interpreter_constraints)

    # Cleanup created pexes.
    os.remove(py2_pex)
    os.remove(py3_pex)
  def test_target_constraints_with_no_sources(self):
    with temporary_dir() as interpreters_cache:
      # Run task.
      py3 = '3'
      if not self.skip_if_no_python(py3):
        pants_ini_config = {'python-setup': {'interpreter_cache_dir': interpreters_cache}}
        pants_run_3 = self.run_pants(
          command=['run', '{}:test_bin'.format(os.path.join(self.testproject, 'test_target_with_no_sources'))],
          config=pants_ini_config
        )
        self.assert_success(pants_run_3)
        self.assertIn('python3', pants_run_3.stdout_data)

      # Binary task.
      pants_ini_config = {'python-setup': {'interpreter_cache_dir': interpreters_cache}}
      pants_run_27 = self.run_pants(
        command=['binary', '{}:test_bin'.format(os.path.join(self.testproject, 'test_target_with_no_sources'))],
        config=pants_ini_config
      )
      self.assert_success(pants_run_27)

    # Ensure proper interpreter constraints were passed to built pexes.
    py2_pex = os.path.join(os.getcwd(), 'dist', 'test_bin.pex')
    py2_info = get_pex_info(py2_pex)
    self.assertIn('CPython>3', py2_info.interpreter_constraints)
    # Cleanup.
    os.remove(py2_pex)
Ejemplo n.º 3
0
    def test_target_constraints_with_no_sources(self):
        with temporary_dir() as interpreters_cache:
            pants_ini_config = {
                'python-setup': {
                    'interpreter_cache_dir': interpreters_cache,
                    'interpreter_constraints': ['CPython>3'],
                }
            }
            # Run task.
            pants_run = self.run_pants(command=[
                'run', '{}:test_bin'.format(
                    os.path.join(self.testproject,
                                 'test_target_with_no_sources'))
            ],
                                       config=pants_ini_config)
            self.assert_success(pants_run)
            self.assertIn('python3', pants_run.stdout_data)

            # Binary task.
            pants_run = self.run_pants(command=[
                'binary', '{}:test_bin'.format(
                    os.path.join(self.testproject,
                                 'test_target_with_no_sources'))
            ],
                                       config=pants_ini_config)
            self.assert_success(pants_run)

        # Ensure proper interpreter constraints were passed to built pexes.
        py2_pex = os.path.join(os.getcwd(), 'dist', 'test_bin.pex')
        py2_info = get_pex_info(py2_pex)
        self.assertIn('CPython>3', py2_info.interpreter_constraints)
        # Cleanup.
        os.remove(py2_pex)
Ejemplo n.º 4
0
def test_get_pex_info():
  with temporary_dir() as td:
    pb = write_simple_pex(td, 'print("hello world!")')
    pex_path = os.path.join(td, 'hello_world.pex')
    pb.build(pex_path)

    # from zip
    pex_info = get_pex_info(pex_path)

    with temporary_dir() as pex_td:
      with closing(zipfile.ZipFile(pex_path, 'r')) as zf:
        zf.extractall(pex_td)

      # from dir
      pex_info_2 = get_pex_info(pex_td)

      # same when encoded
      assert pex_info.dump() == pex_info_2.dump()
Ejemplo n.º 5
0
def test_get_pex_info():
    with temporary_dir() as td:
        pb = write_simple_pex(td, 'print("hello world!")')
        pex_path = os.path.join(td, 'hello_world.pex')
        pb.build(pex_path)

        # from zip
        pex_info = get_pex_info(pex_path)

        with temporary_dir() as pex_td:
            with closing(zipfile.ZipFile(pex_path, 'r')) as zf:
                zf.extractall(pex_td)

            # from dir
            pex_info_2 = get_pex_info(pex_td)

            # same when encoded
            assert pex_info.dump() == pex_info_2.dump()
Ejemplo n.º 6
0
    def test_pants_binary_interpreter_selection_with_pexrc(self):
        py27 = '2.7'
        py3 = '3'
        if self.skip_if_no_python(py27) or self.skip_if_no_python(py3):
            return

        py27_path, py3_path = self.python_interpreter_path(
            py27), self.python_interpreter_path(py3)
        with setup_pexrc_with_pex_python_path(
                os.path.join(os.path.dirname(sys.argv[0]), '.pexrc'),
            [py27_path, py3_path]):
            with temporary_dir() as interpreters_cache:
                pants_ini_config = {
                    'python-setup': {
                        'interpreter_cache_dir': interpreters_cache
                    }
                }
                pants_run_27 = self.run_pants(command=[
                    'binary', '{}:main_py2'.format(
                        os.path.join(self.testproject,
                                     'python_3_selection_testing'))
                ],
                                              config=pants_ini_config)
                self.assert_success(pants_run_27)
                pants_run_3 = self.run_pants(command=[
                    'binary', '{}:main_py3'.format(
                        os.path.join(self.testproject,
                                     'python_3_selection_testing'))
                ],
                                             config=pants_ini_config)
                self.assert_success(pants_run_3)

        # Ensure proper interpreter constraints were passed to built pexes.
        py2_pex = os.path.join(os.getcwd(), 'dist', 'main_py2.pex')
        py3_pex = os.path.join(os.getcwd(), 'dist', 'main_py3.pex')
        py2_info = get_pex_info(py2_pex)
        py3_info = get_pex_info(py3_pex)
        self.assertIn('CPython>2.7.6,<3', py2_info.interpreter_constraints)
        self.assertIn('CPython>3', py3_info.interpreter_constraints)

        # Cleanup created pexes.
        os.remove(py2_pex)
        os.remove(py3_pex)
Ejemplo n.º 7
0
def test_interpreter_constraints_to_pex_info_py3():
  py3_interpreter = ensure_python_interpreter(PY36)
  with temporary_dir() as output_dir:
    # target python 3
    pex_out_path = os.path.join(output_dir, 'pex_py3.pex')
    res = run_pex_command(['--disable-cache', '--interpreter-constraint=>3', '-o', pex_out_path],
                          env=make_env(PATH=os.path.dirname(py3_interpreter)))
    res.assert_success()
    pex_info = get_pex_info(pex_out_path)
    assert ['>3'] == pex_info.interpreter_constraints
Ejemplo n.º 8
0
def test_interpreter_resolution_with_constraint_option():
    with temporary_dir() as output_dir:
        pex_out_path = os.path.join(output_dir, 'pex1.pex')
        res = run_pex_command([
            '--disable-cache', '--interpreter-constraint=>=2.7',
            '--interpreter-constraint=<3', '-o', pex_out_path
        ])
        res.assert_success()
        pex_info = get_pex_info(pex_out_path)
        assert set(['>=2.7', '<3']) == set(pex_info.interpreter_constraints)
        assert pex_info.build_properties['version'][0] < 3
Ejemplo n.º 9
0
def test_interpreter_constraints_to_pex_info_py2():
    with temporary_dir() as output_dir:
        # target python 2
        pex_out_path = os.path.join(output_dir, 'pex_py2.pex')
        res = run_pex_command([
            '--disable-cache', '--interpreter-constraint=>=2.7',
            '--interpreter-constraint=<3', '-o', pex_out_path
        ])
        res.assert_success()
        pex_info = get_pex_info(pex_out_path)
        assert set(['>=2.7', '<3']) == set(pex_info.interpreter_constraints)
Ejemplo n.º 10
0
def test_interpreter_resolution_with_constraint_option():
  with temporary_dir() as output_dir:
    pex_out_path = os.path.join(output_dir, 'pex1.pex')
    res = run_pex_command(['--disable-cache',
      '--interpreter-constraint=>=2.7',
      '--interpreter-constraint=<3',
      '-o', pex_out_path])
    res.assert_success()
    pex_info = get_pex_info(pex_out_path)
    assert set(['>=2.7', '<3']) == set(pex_info.interpreter_constraints)
    assert pex_info.build_properties['version'][0] < 3
Ejemplo n.º 11
0
def test_interpreter_constraints_to_pex_info():
  with temporary_dir() as output_dir:
    # target python 2
    pex_out_path = os.path.join(output_dir, 'pex1.pex')
    res = run_pex_command(['--disable-cache',
      '--interpreter-constraint=>=2.7',
      '--interpreter-constraint=<3',
      '-o', pex_out_path])
    res.assert_success()
    pex_info = get_pex_info(pex_out_path)
    assert set(['>=2.7', '<3']) == set(pex_info.interpreter_constraints)

    # target python 3
    pex_out_path = os.path.join(output_dir, 'pex1.pex')
    res = run_pex_command(['--disable-cache',
      '--interpreter-constraint=>3',
      '-o', pex_out_path])
    res.assert_success()
    pex_info = get_pex_info(pex_out_path)
    assert ['>3'] == pex_info.interpreter_constraints