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)
Пример #2
0
 def test_pants_test_interpreter_selection_with_pexrc(self):
     """Test the pants test goal with interpreters 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>"],
                 },
                 **self.pytest_setup_for_python_2_tests,
             }
             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)
 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>'],
                 },
                 **self.pytest_setup_for_python_2_tests,
             }
             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)
Пример #4
0
    def _do_test_exact_requirements_interpreter_change(self, sdist: bool) -> None:
        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")], sdist=sdist
        ) as results:

            working_set, chroot, repo_dir, cache_dir = results

            safe_rmtree(repo_dir)
            with pytest.raises(Unsatisfiable):
                with self.plugin_resolution(
                    interpreter=python37,
                    chroot=chroot,
                    plugins=[("jake", "1.2.3"), ("jane", "3.4.5")],
                ):
                    pytest.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
                assert list(working_set) == list(working_set2)
Пример #5
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)
 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)
Пример #7
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()})
Пример #8
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)
Пример #9
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(FileNotFoundError):
                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)