Beispiel #1
0
  def test_pants_binary_interpreter_selection_with_pexrc(self):
    py27_path, py3_path = python_interpreter_path(PY_27), python_interpreter_path(PY_3)
    with setup_pexrc_with_pex_python_path([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 = PexInfo.from_pex(py2_pex)
    py3_info = PexInfo.from_pex(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)
Beispiel #2
0
 def test_pants_test_interpreter_selection_with_pexrc(self):
   """Test the pants test goal with intepreters selected from a PEX_PYTHON_PATH
   defined in a pexrc file on disk.
   """
   py27_path, py3_path = python_interpreter_path(PY_27), python_interpreter_path(PY_3)
   with setup_pexrc_with_pex_python_path([py27_path, py3_path]):
     with temporary_dir() as interpreters_cache:
       pants_ini_config = {
         'python-setup': {
           'interpreter_cache_dir': interpreters_cache,
           'interpreter_search_paths': ['<PEXRC>'],
         }
       }
       pants_run_27 = self.run_pants(
         command=['test', '{}:test_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=['test', '{}:test_py3'.format(os.path.join(self.testproject,
                                                            'python_3_selection_testing'))],
         config=pants_ini_config
       )
       self.assert_success(pants_run_3)
Beispiel #3
0
 def test_interpereter_cache_setup_using_pex_python_paths(self):
     """Test cache setup using interpreters from a mocked PEX_PYTHON_PATH."""
     py27_path, py36_path = python_interpreter_path(
         PY_27), python_interpreter_path(PY_36)
     with setup_pexrc_with_pex_python_path([py27_path, py36_path]):
         with self._setup_cache(constraints=['CPython>=2.7,<3'],
                                search_paths=['<PEXRC>']) as (cache, _):
             self.assertIn(py27_path, {pi.binary for pi in cache.setup()})
         with self._setup_cache(constraints=['CPython>=3.6,<4'],
                                search_paths=['<PEXRC>']) as (cache, _):
             self.assertIn(py36_path, {pi.binary for pi in cache.setup()})
Beispiel #4
0
 def test_pants_run_interpreter_selection_with_pexrc(self):
   py27_path, py3_path = python_interpreter_path(PY_27), python_interpreter_path(PY_3)
   with setup_pexrc_with_pex_python_path([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=['run', '{}:main_py2'.format(os.path.join(self.testproject,
                                                           'python_3_selection_testing'))],
         config=pants_ini_config
       )
       self.assert_success(pants_run_27)
       self.assertIn('I am a python 2 library method.', pants_run_27.stdout_data)
       pants_run_3 = self.run_pants(
         command=['run', '{}:main_py3'.format(os.path.join(self.testproject,
                                                           'python_3_selection_testing'))],
         config=pants_ini_config
       )
       self.assert_success(pants_run_3)
       self.assertIn('I am a python 3 library method.', pants_run_3.stdout_data)
Beispiel #5
0
    def test_exact_requirements_interpreter_change(self, unused_test_name,
                                                   packager_cls):
        python36 = PythonInterpreter.from_binary(
            python_interpreter_path(PY_36))
        python37 = PythonInterpreter.from_binary(
            python_interpreter_path(PY_37))

        with self.plugin_resolution(interpreter=python36,
                                    plugins=[('jake', '1.2.3'),
                                             ('jane', '3.4.5')],
                                    packager_cls=packager_cls) as results:
            working_set, chroot, repo_dir, cache_dir = results

            self.assertEqual(2, len(working_set.entries))

            safe_rmtree(repo_dir)
            with self.assertRaises(Unsatisfiable):
                with self.plugin_resolution(interpreter=python37,
                                            chroot=chroot,
                                            plugins=[('jake', '1.2.3'),
                                                     ('jane', '3.4.5')]):
                    self.fail(
                        'Plugin re-resolution is expected for an incompatible interpreter and it is '
                        'expected to fail since we removed the dist `repo_dir` above.'
                    )

            # But for a compatible interpreter the exact resolve results should be re-used and load
            # directly from the still in-tact cache.
            with self.plugin_resolution(interpreter=python36,
                                        chroot=chroot,
                                        plugins=[('jake', '1.2.3'),
                                                 ('jane', '3.4.5')
                                                 ]) as results2:
                working_set2, _, _, _ = results2

                self.assertEqual(working_set.entries, working_set2.entries)