From 97d25d3685b310df125baddd3f4c7cf8320f350f Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Mon, 3 Jul 2023 16:25:02 +0000 Subject: [PATCH 1/4] Remove `--upgrade` from `pip install` Fixes #1135 --- charmcraft/charm_builder.py | 8 ++++---- tests/test_charm_builder.py | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/charmcraft/charm_builder.py b/charmcraft/charm_builder.py index 7189c7951..3428eb3a3 100644 --- a/charmcraft/charm_builder.py +++ b/charmcraft/charm_builder.py @@ -239,26 +239,26 @@ def _install_dependencies(self, staging_venv_dir): with instrum.Timer("Installing all dependencies"): if self.binary_python_packages: # install python packages, allowing binary packages - cmd = [pip_cmd, "install", "--upgrade"] # base command + cmd = [pip_cmd, "install"] # base command cmd.extend(self.binary_python_packages) # the python packages to install _process_run(cmd) if self.python_packages: # install python packages from source - cmd = [pip_cmd, "install", "--upgrade", "--no-binary", ":all:"] # base command + cmd = [pip_cmd, "install", "--no-binary", ":all:"] # base command cmd.extend(self.python_packages) # the python packages to install _process_run(cmd) if self.requirement_paths: # install dependencies from requirement files - cmd = [pip_cmd, "install", "--upgrade", "--no-binary", ":all:"] # base command + cmd = [pip_cmd, "install", "--no-binary", ":all:"] # base command for reqspath in self.requirement_paths: cmd.append("--requirement={}".format(reqspath)) # the dependencies file(s) _process_run(cmd) if self.charmlib_deps: # install charmlibs python dependencies - cmd = [pip_cmd, "install", "--upgrade", "--no-binary", ":all:"] # base command + cmd = [pip_cmd, "install", "--no-binary", ":all:"] # base command cmd.extend(self.charmlib_deps) # the python packages to install _process_run(cmd) diff --git a/tests/test_charm_builder.py b/tests/test_charm_builder.py index fa5749960..0a3315c80 100644 --- a/tests/test_charm_builder.py +++ b/tests/test_charm_builder.py @@ -614,7 +614,7 @@ def test_build_dependencies_virtualenv_simple(tmp_path, assert_output): call(["python3", "-m", "venv", str(tmp_path / STAGING_VENV_DIRNAME)]), call([pip_cmd, "--version"]), call( - [pip_cmd, "install", "--upgrade", "--no-binary", ":all:", f"--requirement={reqs_file}"] + [pip_cmd, "install", "--no-binary", ":all:", f"--requirement={reqs_file}"] ), ] @@ -654,7 +654,6 @@ def test_build_dependencies_virtualenv_multiple(tmp_path, assert_output): [ pip_cmd, "install", - "--upgrade", "--no-binary", ":all:", f"--requirement={reqs_file_1}", @@ -712,7 +711,7 @@ def test_build_dependencies_virtualenv_packages(tmp_path, assert_output): assert mock.mock_calls == [ call(["python3", "-m", "venv", str(tmp_path / STAGING_VENV_DIRNAME)]), call([pip_cmd, "--version"]), - call([pip_cmd, "install", "--upgrade", "--no-binary", ":all:", "pkg1", "pkg2"]), + call([pip_cmd, "install", "--no-binary", ":all:", "pkg1", "pkg2"]), ] site_packages_dir = charm_builder._find_venv_site_packages(pathlib.Path(STAGING_VENV_DIRNAME)) @@ -743,7 +742,7 @@ def test_build_dependencies_virtualenv_binary_packages(tmp_path, assert_output): assert mock.mock_calls == [ call(["python3", "-m", "venv", str(tmp_path / STAGING_VENV_DIRNAME)]), call([pip_cmd, "--version"]), - call([pip_cmd, "install", "--upgrade", "pkg1", "pkg2"]), + call([pip_cmd, "install", "pkg1", "pkg2"]), ] site_packages_dir = charm_builder._find_venv_site_packages(pathlib.Path(STAGING_VENV_DIRNAME)) @@ -780,20 +779,19 @@ def test_build_dependencies_virtualenv_all(tmp_path, assert_output): assert mock.mock_calls == [ call(["python3", "-m", "venv", str(tmp_path / STAGING_VENV_DIRNAME)]), call([pip_cmd, "--version"]), - call([pip_cmd, "install", "--upgrade", "pkg1", "pkg2"]), - call([pip_cmd, "install", "--upgrade", "--no-binary", ":all:", "pkg3", "pkg4"]), + call([pip_cmd, "install", "pkg1", "pkg2"]), + call([pip_cmd, "install", "--no-binary", ":all:", "pkg3", "pkg4"]), call( [ pip_cmd, "install", - "--upgrade", "--no-binary", ":all:", f"--requirement={reqs_file_1}", f"--requirement={reqs_file_2}", ] ), - call([pip_cmd, "install", "--upgrade", "--no-binary", ":all:", "pkg5", "pkg6"]), + call([pip_cmd, "install", "--no-binary", ":all:", "pkg5", "pkg6"]), ] site_packages_dir = charm_builder._find_venv_site_packages(pathlib.Path(STAGING_VENV_DIRNAME)) From 6373de6d83ddbf7c05cdf4eb5277696b7e2fb333 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Mon, 3 Jul 2023 16:32:56 +0000 Subject: [PATCH 2/4] format test --- tests/test_charm_builder.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_charm_builder.py b/tests/test_charm_builder.py index 0a3315c80..6d1b51461 100644 --- a/tests/test_charm_builder.py +++ b/tests/test_charm_builder.py @@ -613,9 +613,7 @@ def test_build_dependencies_virtualenv_simple(tmp_path, assert_output): assert mock.mock_calls == [ call(["python3", "-m", "venv", str(tmp_path / STAGING_VENV_DIRNAME)]), call([pip_cmd, "--version"]), - call( - [pip_cmd, "install", "--no-binary", ":all:", f"--requirement={reqs_file}"] - ), + call([pip_cmd, "install", "--no-binary", ":all:", f"--requirement={reqs_file}"]), ] site_packages_dir = charm_builder._find_venv_site_packages(pathlib.Path(STAGING_VENV_DIRNAME)) From a4812c66b16ab4c93737f4db1d42fd2de8b9712f Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Wed, 5 Jul 2023 19:28:02 +0000 Subject: [PATCH 3/4] Add spread test --- .../smoketests/pinned-dependencies/task.yaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/spread/smoketests/pinned-dependencies/task.yaml diff --git a/tests/spread/smoketests/pinned-dependencies/task.yaml b/tests/spread/smoketests/pinned-dependencies/task.yaml new file mode 100644 index 000000000..66157a942 --- /dev/null +++ b/tests/spread/smoketests/pinned-dependencies/task.yaml @@ -0,0 +1,37 @@ +summary: pack a charm with a specific (old) dependency version + +include: + - tests/ + +prepare: | + tests.pkgs install unzip + charmcraft init --project-dir=charm + cd charm + echo "ops==2.0.0" > requirements.txt + + cat <<- EOF >> charmcraft.yaml + parts: + charm: + charm-requirements: [requirements.txt] + EOF + + cat <<- EOF > lib/charms/charm/v0/my_lib.py + PYDEPS = ["ops"] + LIBID = "my_lib" + LIBAPI = 0 + LIBPATCH = 1 + EOF + + +restore: | + pushd charm + charmcraft clean + popd + + rm -rf charm + +execute: | + cd charm + charmcraft pack --verbose + test -f charm*.charm + unzip -p charm_*.charm venv/ops/version.py | MATCH "version = '2.0.0'" From de9060b8d85fe30b34a65ecb2878dd84083ad383 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Wed, 5 Jul 2023 19:59:48 +0000 Subject: [PATCH 4/4] Update task.yaml --- tests/spread/smoketests/pinned-dependencies/task.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/spread/smoketests/pinned-dependencies/task.yaml b/tests/spread/smoketests/pinned-dependencies/task.yaml index 66157a942..0a04c55aa 100644 --- a/tests/spread/smoketests/pinned-dependencies/task.yaml +++ b/tests/spread/smoketests/pinned-dependencies/task.yaml @@ -15,6 +15,7 @@ prepare: | charm-requirements: [requirements.txt] EOF + mkdir -p lib/charms/charm/v0/ cat <<- EOF > lib/charms/charm/v0/my_lib.py PYDEPS = ["ops"] LIBID = "my_lib"