Skip to content

Commit

Permalink
fix(charm_builder): force-install pip (#1892)
Browse files Browse the repository at this point in the history
The previous version wasn't installing pip if it was already in the
venv.

This is the hotfix for 3.x, while
#1891 is the hotfix for 2.x.

Fixes #1456
CRAFT-2538
  • Loading branch information
lengau authored Sep 12, 2024
1 parent d2fcbfd commit 358657b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions charmcraft/charm_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def _install_dependencies(self, staging_venv_dir: pathlib.Path):
[
pip_cmd,
"install",
"--force-reinstall",
f"pip@{KNOWN_GOOD_PIP_URL}",
]
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_charm_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def test_build_dependencies_virtualenv(

assert mock.mock_calls == [
call(["python3", "-m", "venv", str(tmp_path / const.STAGING_VENV_DIRNAME)]),
call([pip_cmd, "install", f"pip@{KNOWN_GOOD_PIP_URL}"]),
call([pip_cmd, "install", "--force-reinstall", f"pip@{KNOWN_GOOD_PIP_URL}"]),
*extra_pip_calls,
]

Expand Down Expand Up @@ -771,7 +771,7 @@ def test_build_dependencies_virtualenv_multiple(tmp_path, assert_output):
pip_cmd = str(charm_builder._find_venv_bin(tmp_path / const.STAGING_VENV_DIRNAME, "pip"))
assert mock.mock_calls == [
call(["python3", "-m", "venv", str(tmp_path / const.STAGING_VENV_DIRNAME)]),
call([pip_cmd, "install", f"pip@{KNOWN_GOOD_PIP_URL}"]),
call([pip_cmd, "install", "--force-reinstall", f"pip@{KNOWN_GOOD_PIP_URL}"]),
call(
[
pip_cmd,
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/utils/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ def test_get_pip_command(

@pytest.mark.parametrize(
("pip_cmd", "stdout", "expected"),
[("pip", "pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)\n", (22, 0, 2))],
[
("pip", "pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)\n", (22, 0, 2)),
(
"venv/bin/pip",
"pip 20.0.2 from /root/venv/lib/python3.8/site-packages/pip (python 3.8)",
(20, 0, 2),
),
],
)
def test_get_pip_version_success(
fake_process,
Expand Down

0 comments on commit 358657b

Please sign in to comment.