def setUp(self):
     self.logger = Mock(Logger)
     self.dependencies_to_install_with_pip = [
         Dependency('test'), Dependency('pip')
     ]
     self.dependencies_to_install_without_pip = [
         Dependency('test'), Dependency('test2')
     ]
     from pybuilder import pip_common, pip_utils
     self.pip_common_object = pip_common.Version("1.2.3")
     self.pip_utils_method = pip_utils.pip_install
Beispiel #2
0
    def test_index_in_dependency(self):
        print(self.tmp_directory)
        lock = self.two_deps_and_one_dev
        lock['_meta']['sources'].append({
            "name": "my-pi",
            "url": "https://my-pi/simple",
            "verify_ssl": True
        })
        lock['default']['humanize']['index'] = 'my-pi'

        p = self._build(lock).project  # type: Project
        deps = [Dependency("humanize", "==0.5.1", None),
                Dependency("tomlkit", "==0.5.2", None)]
        self.assertEqual("https://my-pi/simple", p.get_property("install_dependencies_extra_index_url"))
        self.assertListEqual(deps, p.dependencies)
Beispiel #3
0
    def test_should_install_dependency_with_version(self, exec_command, get_package_version, constraint_file):
        dependency = Dependency("spam", "0.1.2")

        install_dependency(self.logger, self.project, dependency)

        exec_command(
            PIP_EXEC_STANZA + ["install", 'spam>=0.1.2'], ANY, env=ANY, shell=False)
Beispiel #4
0
    def test_should_install_dependency_with_url(self, exec_command, get_package_version, constraint_file):
        dependency = Dependency("spam", url="some_url")

        install_dependency(self.logger, self.project, dependency)

        exec_command(
            PIP_EXEC_STANZA + ["install", "--force-reinstall", 'some_url'], ANY, env=ANY, shell=False)
    def test_should_install_dependency_securely_when_property_is_not_set_to_dependency(
            self, *_):
        dependency = Dependency("spam")
        self.project.set_property("install_dependencies_insecure_installation",
                                  ["some-other-dependency"])

        install_dependencies(self.logger,
                             self.project,
                             dependency,
                             self.pyb_env,
                             "install_batch",
                             constraints_file_name="constraint_file")

        self.pyb_env.execute_command.assert_called_with(
            self.pyb_env.executable + PIP_MODULE_STANZA + [
                "install", "-c", ANY, "--allow-unverified",
                "some-other-dependency", "--allow-external",
                "some-other-dependency", "spam"
            ],
            cwd=ANY,
            env=ANY,
            error_file_name=ANY,
            outfile_name=ANY,
            shell=False,
            no_path_search=True)
Beispiel #6
0
    def test_should_install_dependency_without_version(self):
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin
               ).execute_command("pip install 'spam'", any_value(), shell=True)
Beispiel #7
0
    def test_conversion_to_setup_py(self):
        p = self._build(self.two_deps_and_one_dev).project  # type: Project

        deps = [
            Dependency('humanize', '==0.5.1'),
            Dependency('tomlkit', '==0.5.2')]
        self.assertListEqual(deps, p.dependencies)
        setup_py = "target/dist/sample-1.0.dev0/setup.py"

        self.assert_file_exists(setup_py)
        with open(self.full_path(setup_py)) as f:
            content = f.read()
            assert "tailer" not in content  # no develop dependencies

            setup_file = re.sub(' +', ' ', content.replace(os.linesep, ""))
            assert "install_requires = [ 'humanize==0.5.1', 'tomlkit==0.5.2' ]" in setup_file
Beispiel #8
0
    def test_should_install_dependency_without_version_on_windows_derivate(self, exec_command, get_package_version,
                                                                           constraint_file):
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        exec_command(
            PIP_EXEC_STANZA + ["install", "spam"], ANY, env=ANY, shell=False)
    def test_should_install_dependency_without_version_on_windows_derivate(self, platform):
        platform.return_value = "win32"
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin).execute_command(
            "pip install spam", any_value(), shell=True)
    def test_should_install_dependency_with_url_even_if_version_is_given(self):
        dependency = Dependency("spam", version="0.1.2", url="some_url")

        install_dependency(self.logger, self.project, dependency)

        verify(
            pybuilder.plugins.python.install_dependencies_plugin).execute_command("pip install 'some_url'",
                                                                                  any_value(), shell=True)
    def test_should_upgrade_dependencies(self):
        self.project.set_property("install_dependencies_upgrade", True)
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin).execute_command(
            "pip install --upgrade 'spam'", any_value(), shell=True)
Beispiel #12
0
    def test_should_upgrade_dependencies(self, exec_command, get_package_version, constraint_file):
        self.project.set_property("install_dependencies_upgrade", True)
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        exec_command(
            PIP_EXEC_STANZA + ["install", "--upgrade", 'spam'], ANY, env=ANY, shell=False)
    def test_should_install_dependency_insecurely_when_property_is_set(self):
        dependency = Dependency("spam")
        self.project.set_property("install_dependencies_insecure_installation", ["spam"])
        when(pybuilder.plugins.python.install_dependencies_plugin)._pip_disallows_insecure_packages_by_default().thenReturn(True)

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin).execute_command(
            "pip install --allow-unverified spam --allow-external spam 'spam'", any_value(), shell=True)
    def test_should_install_dependency_using_custom_index_url(self):
        self.project.set_property(
            "install_dependencies_index_url", "some_index_url")
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin).execute_command(
            "pip install --index-url some_index_url 'spam'", any_value(), shell=True)
    def test_should_not_use_insecure_flags_when_pip_version_is_too_low(self):
        dependency = Dependency("spam")
        self.project.set_property("install_dependencies_insecure_installation", ["spam"])
        when(pybuilder.plugins.python.install_dependencies_plugin)._pip_disallows_insecure_packages_by_default().thenReturn(False)

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin).execute_command(
            "pip install 'spam'", any_value(), shell=True)
Beispiel #16
0
    def test_should_not_use_insecure_flags_when_pip_version_is_too_low(self, exec_command, _, get_package_version,
                                                                       constraint_file):
        dependency = Dependency("spam")
        self.project.set_property("install_dependencies_insecure_installation", ["spam"])

        install_dependency(self.logger, self.project, dependency)

        exec_command(
            PIP_EXEC_STANZA + ["install", 'spam'], ANY, env=ANY, shell=False)
Beispiel #17
0
    def test_should_not_use_extra_index_url_when_index_url_is_not_set(self):
        self.project.set_property("install_dependencies_extra_index_url",
                                  "some_index_url")
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin
               ).execute_command("pip install 'spam'", any_value(), shell=True)
    def test_should_install_dependency_with_version_and_operator(
            self, exec_command, get_package_version):
        dependency = Dependency("spam", "==0.1.2")

        install_dependency(self.logger, self.project, dependency)

        exec_command(PIP_EXEC_STANZA + ["install", 'spam==0.1.2'],
                     ANY,
                     env=ANY,
                     shell=False)
    def test_should_install_dependency_without_version(self):
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin
               ).execute_command([PIP_EXECUTABLE, "install", 'spam'],
                                 any_value(),
                                 env=any_value(),
                                 shell=False)
    def test_should_install_dependency_with_version_and_operator(self):
        dependency = Dependency("spam", "==0.1.2")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin
               ).execute_command(PIP_EXEC_STANZA + ["install", 'spam==0.1.2'],
                                 any_value(),
                                 env=any_value(),
                                 shell=False)
Beispiel #21
0
    def test_should_install_dependency_insecurely_when_property_is_set(self, exec_command, _, get_package_version,
                                                                       constraint_file):
        dependency = Dependency("spam")
        self.project.set_property("install_dependencies_insecure_installation", ["spam"])

        install_dependency(self.logger, self.project, dependency)

        exec_command(
            PIP_EXEC_STANZA + ["install", "--allow-unverified", "spam", "--allow-external", "spam", 'spam'],
            ANY, env=ANY, shell=False)
Beispiel #22
0
    def test_should_use_extra_index_url_when_index_url_is_not_set(self, exec_command, get_package_version,
                                                                  constraint_file):
        self.project.set_property("install_dependencies_extra_index_url", "some_extra_index_url")
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        exec_command(
            PIP_EXEC_STANZA + ["install", "--extra-index-url", "some_extra_index_url", 'spam'], ANY,
            env=ANY, shell=False)
    def test_should_install_dependency_without_version(self, exec_command,
                                                       get_package_version):
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        exec_command.assert_called_with(PIP_EXEC_STANZA +
                                        ["install", '--upgrade', 'spam'],
                                        ANY,
                                        env=ANY,
                                        shell=False)
    def test_should_install_dependency_with_url_even_if_version_is_given(self):
        dependency = Dependency("spam", version="0.1.2", url="some_url")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin
               ).execute_command(PIP_EXEC_STANZA +
                                 ["install", "--force-reinstall", 'some_url'],
                                 any_value(),
                                 env=any_value(),
                                 shell=False)
    def test_should_install_dependency_without_version_on_windows_derivate(
            self):
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin
               ).execute_command(PIP_EXEC_STANZA + ["install", "spam"],
                                 any_value(),
                                 env=any_value(),
                                 shell=False)
    def test_should_install_dependency_with_url_even_if_version_is_given(
            self, exec_command, get_package_version):
        dependency = Dependency("spam", version="0.1.2", url="some_url")

        install_dependency(self.logger, self.project, dependency)

        exec_command(PIP_EXEC_STANZA +
                     ["install", "--force-reinstall", 'some_url'],
                     ANY,
                     env=ANY,
                     shell=False)
    def test_should_install_dependency_with_url(self):
        dependency = Dependency("spam", url="some_url")

        install_dependency(self.logger, self.project, dependency)

        verify(
            pybuilder.plugins.python.install_dependencies_plugin
        ).execute_command(
            [PIP_EXECUTABLE, "install", "--force-reinstall", 'some_url'],
            any_value(),
            env=any_value(),
            shell=False)
    def test_should_upgrade_dependencies(self):
        self.project.set_property("install_dependencies_upgrade", True)
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        verify(pybuilder.plugins.python.install_dependencies_plugin
               ).execute_command(
                   [PIP_EXECUTABLE, "install", "--upgrade", 'spam'],
                   any_value(),
                   env=any_value(),
                   shell=False)
    def test_should_download_module_from_pypi(self, load):
        logger = Mock()
        reactor = Mock()
        pyb_env = Mock()
        reactor.python_env_registry = {"pybuilder": pyb_env}
        reactor.pybuilder_venv = pyb_env

        pd = PluginDef("pypi:external_plugin")
        pl = DownloadingPluginLoader(logger)
        pl.install_plugin(reactor, pd)

        pyb_env.install_dependencies.assert_called_with(
            [Dependency("external_plugin")], package_type="plugin")
Beispiel #30
0
    def test_should_install_dependency_without_version(self, exec_command, get_package_version, constraint_file):
        dependency = Dependency("spam")

        install_dependency(self.logger, self.project, dependency)

        exec_command.assert_called_with(PIP_EXEC_STANZA +
                                        ["install"] +
                                        (["--upgrade"] if pip_utils.pip_version < "9.0" else
                                         ["--upgrade", "--upgrade-strategy", "only-if-needed"]) +
                                        ['-c',
                                         'unittest/any_target_directory/install_dependencies_constraints',
                                         'spam'],
                                        ANY, env=ANY, shell=False)