Skip to content

Fix: ensure upgrade message shows actual installed version #13435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from pip._internal.build_env import BuildEnvironment, NoOpBuildEnvironment
from pip._internal.exceptions import InstallationError, PreviousBuildDirError
from pip._internal.metadata import get_default_environment
from pip._internal.locations import get_scheme
from pip._internal.metadata import (
BaseDistribution,
Expand Down Expand Up @@ -879,6 +880,18 @@ def install(
)
self.install_succeeded = True

installed_version = get_installed_version(self.req.name)
if installed_version:
logger.info("Successfully installed %s-%s", self.req.name, installed_version)
else:
logger.info("Successfully installed %s (version unknown)", self.req.name)

self.install_succeeded = True

def get_installed_version(package_name: str) -> str | None:
env = get_default_environment()
dist = env.get_distribution(package_name)
return dist.version if dist else None

def check_invalid_constraint_type(req: InstallRequirement) -> str:
# Check for unsupported forms
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_upgrade_shows_correct_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_upgrade_shows_correct_version(script):
script.pip_install('pip==25.0.1')
result = script.pip('install', '--upgrade', 'pip')
assert "Successfully installed pip-25.1.1" in result.stdout
Loading