How to use the pybuilder.pip_utils function in pybuilder

To help you get started, we’ve selected a few pybuilder 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 pybuilder / pybuilder / src / unittest / python / pip_utils_tests.py View on Github external
def test_pip_install_environ_overwritten(self, execute_command):
        env_dict = dict()
        pip_utils.pip_install("blah", env=env_dict)
        execute_command.assert_called_once_with(ANY, cwd=None, env=env_dict, error_file_name=None, outfile_name=None,
                                                shell=False)
github pybuilder / pybuilder / src / unittest / python / plugins / python / install_dependencies_plugin_tests.py View on Github external
def test_should_not_reload_pip_utils(self):
        reload_pip_if_updated(self.logger, self.dependencies_to_install_without_pip)
        from pybuilder import pip_utils
        self.assertTrue(self.pip_utils_method == pip_utils.pip_install)
github pybuilder / pybuilder / src / unittest / python / pip_utils_tests.py View on Github external
def test_version_satisfies_spec(self):
        self.assertEqual(pip_utils.version_satisfies_spec(None, "blah"), True)
        self.assertEqual(pip_utils.version_satisfies_spec("blah", None), False)
        self.assertEqual(pip_utils.version_satisfies_spec(">=1.2.3", "1.2.4"), True)
        self.assertEqual(pip_utils.version_satisfies_spec(">=1.2.3", "1.2.4.dev987"), False)
        self.assertEqual(pip_utils.version_satisfies_spec(">=1.0", "1.1.dev1"), False)
        self.assertEqual(pip_utils.version_satisfies_spec(">=1.0,>=0.0.dev0", "1.1.dev1"), True)
github pybuilder / pybuilder / src / main / python / pybuilder / plugins / python / install_dependencies_plugin.py View on Github external
def install_dependency(logger, project, dependencies):
    dependencies_to_install, orig_installed_pkgs, dependency_constraints = _filter_dependencies(logger, project,
                                                                                                dependencies)
    batch_dependencies = []
    standalone_dependencies = []
    local_mapping = project.get_property("install_dependencies_local_mapping")

    constraints_file = project.expand_path("$dir_target", "install_dependencies_constraints")
    pip_utils.create_constraint_file(constraints_file, dependency_constraints)

    for dependency in dependencies_to_install:
        url = getattr(dependency, "url", None)

        if dependency.name in local_mapping or url:
            install_type = "standalone"
            logger.debug("Dependency '%s' has to be installed standalone" % dependency)
            standalone_dependencies.append(dependency)
        else:
            install_type = "batch"
            logger.debug("Dependency '%s' will be included in batch install" % dependency)
            batch_dependencies.append(dependency)

        logger.info("Processing %s dependency '%s%s'%s", install_type, dependency.name,
                    dependency.version if dependency.version else "",
                    " from %s" % url if url else "")
github pybuilder / pybuilder / src / main / python / pybuilder / plugins / python / install_dependencies_plugin.py View on Github external
def _filter_dependencies(logger, project, dependencies):
    dependencies = as_list(dependencies)
    installed_packages = pip_utils.get_package_version(dependencies)
    dependencies_to_install = []
    dependency_constraints = []

    for dependency in dependencies:
        logger.debug("Inspecting dependency '%s'" % dependency)
        if isinstance(dependency, RequirementsFile):
            # Always add requirement file-based dependencies
            logger.debug("Dependency '%s' is a requirement file and will be included" % dependency)
            dependencies_to_install.append(dependency)
            continue
        elif isinstance(dependency, Dependency):
            if dependency.version:
                dependency_constraints.append(dependency)
                logger.debug(
                    "Dependency '%s' is added to the list of installation constraints" % dependency)
github pybuilder / pybuilder / src / main / python / pybuilder / pluginloader.py View on Github external
def load_plugin(self, project, name, version=None, plugin_module_name=None):
        display_name = _plugin_display_name(name, version, plugin_module_name)

        update_plugin = False
        force_reinstall = False

        thirdparty_plugin = name
        # Maybe we already installed this plugin from PyPI before
        if thirdparty_plugin.startswith(PYPI_PLUGIN_PROTOCOL):
            thirdparty_plugin = thirdparty_plugin.replace(PYPI_PLUGIN_PROTOCOL, "")
            update_plugin = pip_utils.should_update_package(version)
        elif thirdparty_plugin.startswith(VCS_PLUGIN_PROTOCOL):
            if not plugin_module_name:
                raise UnspecifiedPluginNameException(name)
            thirdparty_plugin = plugin_module_name
            force_reinstall = True

        # This is done before we attempt to load a plugin regardless of whether it can be loaded or not
        if update_plugin or force_reinstall:
            self.logger.info("Downloading or updating plugin {0}".format(display_name))
            try:
                _install_external_plugin(project, name, version, self.logger, plugin_module_name, update_plugin,
                                         force_reinstall)
                self.logger.info("Installed or updated plugin {0}.".format(display_name))
            except MissingPluginException as e:
                self.logger.error("Could not install or upgrade plugin {0}: {1}.".format(display_name, e))
github pybuilder / pybuilder / src / main / python / pybuilder / plugins / python / install_dependencies_plugin.py View on Github external
# Always add requirement file-based dependencies
            logger.debug("Dependency '%s' is a requirement file and will be included" % dependency)
            dependencies_to_install.append(dependency)
            continue
        elif isinstance(dependency, Dependency):
            if dependency.version:
                dependency_constraints.append(dependency)
                logger.debug(
                    "Dependency '%s' is added to the list of installation constraints" % dependency)

            if dependency.url:
                # Always add dependency that is url-based
                logger.debug("Dependency '%s' is URL-based and will be included" % dependency)
                dependencies_to_install.append(dependency)
                continue
            if pip_utils.should_update_package(dependency.version) \
                    and not getattr(dependency, "version_not_a_spec", False):
                # Always add dependency that has a version specifier indicating desire to always update
                logger.debug("Dependency '%s' has a non-exact version specifier and will be included" % dependency)
                dependencies_to_install.append(dependency)
                continue

        dependency_name = dependency.name.lower()
        if dependency_name not in installed_packages:
            # If dependency not installed at all then install it
            logger.debug("Dependency '%s' is not installed and will be included" % dependency)
            dependencies_to_install.append(dependency)
            continue

        if dependency.version \
                and not pip_utils.version_satisfies_spec(dependency.version, installed_packages[dependency_name]):
            # If version is specified and version constraint is not satisfied
github pybuilder / pybuilder / src / main / python / pybuilder / plugins / python / install_dependencies_plugin.py View on Github external
def _do_install_dependency(logger, project, dependency, upgrade, eager_upgrade,
                           force_reinstall, constraint_file, target_dir, log_file):
    batch = isinstance(dependency, collections.Iterable)

    exit_code = pip_utils.pip_install(
        install_targets=dependency,
        index_url=project.get_property("install_dependencies_index_url"),
        extra_index_url=project.get_property("install_dependencies_extra_index_url"),
        upgrade=upgrade,
        insecure_installs=project.get_property("install_dependencies_insecure_installation"),
        force_reinstall=force_reinstall,
        target_dir=target_dir,
        verbose=project.get_property("verbose"),
        trusted_host=project.get_property("install_dependencies_trusted_host"),
        constraint_file=constraint_file,
        eager_upgrade=eager_upgrade,
        logger=logger,
        outfile_name=log_file)

    if exit_code != 0:
        if batch: