Exemple #1
0
    def _get_dependency_version(dependency: str, is_dev: bool) -> str:
        """Get version of the given dependency from Pipfile.lock."""
        try:
            with open("Pipfile.lock") as pipfile_lock:
                pipfile_lock_content = json.load(pipfile_lock)
        except Exception as exc:
            # TODO: open a PR to fix this
            raise DependencyManagementError(
                f"Failed to load Pipfile.lock file: {str(exc)}"
            ) from exc

        # We look for normalized dependency in Pipfile.lock.
        normalized_dependency = re.sub(r"[-_.]+", "-", dependency).lower()
        version = (
            pipfile_lock_content["develop" if is_dev else "default"]
            .get(normalized_dependency, {})
            .get("version")
        )
        # if not kept as normaized depedency in Pipfile.lock.
        version = (
            pipfile_lock_content["develop" if is_dev else "default"]
            .get(dependency, {})
            .get("version")
        )
        if not version:
            raise InternalError(
                f"Failed to retrieve version information for dependency {dependency}, (dev: {is_dev})"
            )

        return version[len("==") :]
Exemple #2
0
    def _should_update(self, package_name, new_package_version) -> tuple:
        """Check whether the given update was already proposed as a pull request."""
        branch_name = self._construct_branch_name(package_name, new_package_version)
        response = {mr for mr in self._cached_merge_requests
                    if mr.head_branch_name == branch_name and mr.state in ('opened', 'open')}

        if len(response) == 0:
            _LOGGER.debug(f"No pull request was found for update of {package_name} to version {new_package_version}")
            return None, True
        elif len(response) == 1:
            response = list(response)[0]
            commits = response.commits
            if len(commits) != 1:
                _LOGGER.info("Update of package {package_name} to version {new_package_version} will not be issued,"
                             "the pull request as additional commits (by a maintaner?)")
                return response, False

            pr_number = response.number
            if self.sha != commits[0].parent.sha:
                _LOGGER.debug(f"Found already existing  pull request #{pr_number} for old master "
                              f"branch {commits[0].parent.sha[:7]!r} updating pull request based on "
                              f"branch {branch_name!r} for the current master branch {self.sha[:7]!r}")
                return response, True
            else:
                _LOGGER.debug(f"Found already existing  pull request #{pr_number} for the current master "
                              f"branch {self.sha[:7]!r}, not updating pull request")
                return response, False
        else:
            raise InternalError(f"Multiple ({len(response)}) pull requests with same "
                                f"branch name {branch_name!r} opened.")
Exemple #3
0
    def _get_dependency_version(dependency: str, is_dev: bool) -> str:
        """Get version of the given dependency from Pipfile.lock."""
        try:
            with open('Pipfile.lock') as pipfile_lock:
                pipfile_lock_content = json.load(pipfile_lock)
        except Exception as exc:
            # TODO: open a PR to fix this
            raise DependencyManagementError(f"Failed to load Pipfile.lock file: {str(exc)}") from exc

        version = pipfile_lock_content['develop' if is_dev else 'default'].get(
            dependency, {}).get('version')
        if not version:
            raise InternalError(
                f"Failed to retrieve version information for dependency {dependency}, (dev: {is_dev})")

        return version[len('=='):]
    def _get_dependency_version(dependency: str, is_dev: bool) -> str:
        """Get version of the given dependency from Pipfile.lock."""
        try:
            with open("Pipfile.lock") as pipfile_lock:
                pipfile_lock_content = json.load(pipfile_lock)
        except Exception as exc:
            # TODO: open a PR to fix this
            raise DependencyManagementError(
                f"Failed to load Pipfile.lock file: {str(exc)}") from exc

        # We look for normalized dependency in Pipfile.lock.
        normalized_dependency = canonicalize_name(dependency)

        if (normalized_dependency in PACKAGES_TO_IGNORE
                or dependency in PACKAGES_TO_IGNORE):
            _LOGGER.debug("Skipping... dependency is locked by pipenv.")
            return ""

        package_info = pipfile_lock_content[
            "develop" if is_dev else "default"].get(normalized_dependency, {})
        if not package_info:
            # if not kept as normalized depedency in Pipfile.lock.
            package_info = pipfile_lock_content[
                "develop" if is_dev else "default"].get(dependency, {})

        version = package_info.get("version")
        if version is None and package_info.get("git"):
            # package is referencing a git VCS for package installation so no version is present
            _LOGGER.debug(
                "Skipping... package installation references a version control system."
            )
            return ""
        elif version is None and package_info.get("path"):
            _LOGGER.debug(
                "Skipping... package installation references a local path.")

        if not version:
            raise InternalError(
                f"Failed to retrieve version information for dependency {dependency}, (dev: {is_dev})"
            )

        return version[len("=="):]
Exemple #5
0
    def _should_update(self) -> tuple:
        """Check whether the given update was already proposed as a pull request."""
        branch_name = _UPDATE_BRANCH_NAME
        response = {
            mr
            for mr in self._cached_merge_requests
            if mr.source_branch == branch_name and mr.status == PRStatus.open
        }

        if len(response) == 0:
            _LOGGER.debug(f"No pull request was found for automatic update.")
            return None, True
        elif len(response) == 1:
            response = list(response)[0]
            commits = response.get_all_commits()  # type: ignore
            if len(commits) != 1:
                _LOGGER.info(
                    "Automatic update will not be issued,"
                    "the pull request as additional commits (by a maintaner?)"
                )
                return response, False

            pr_number = response.id  # type: ignore
            if self.sha != commits[0]:
                _LOGGER.debug(
                    f"Found already existing  pull request #{pr_number} for old master "
                    f"branch {commits[0][:7]!r} updating pull request based on "
                    f"branch {branch_name!r} for the current master branch {self.sha[:7]!r}"
                )
                return response, True
            else:
                _LOGGER.debug(
                    f"Found already existing  pull request #{pr_number} for the current master "
                    f"branch {self.sha[:7]!r}, not updating pull request"
                )
                return response, False
        else:
            raise InternalError(
                f"Multiple ({len(response)}) pull requests with same "
                f"branch name {branch_name!r} opened."
            )