-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(strict-deps): fail if venv is inconsistent
This runs `pip check` to ensure that all the packages in the charm virtualenv have all of their required dependencies, failing the build if they do not. Fixes #1781
- Loading branch information
Showing
3 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# For further info, check https://github.com/canonical/charmcraft | ||
"""Integration tests for CharmBuilder.""" | ||
|
||
|
||
import pathlib | ||
|
||
import pytest | ||
from charmcraft import charm_builder | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"requirements", | ||
[ | ||
["ops==2.15.0"], # Requires pyyaml and websocket-client | ||
] | ||
) | ||
def test_install_strict_dependencies_pip_check_error( | ||
new_path: pathlib.Path, requirements: list[str] | ||
): | ||
build_dir = new_path / "build" | ||
install_dir = new_path / "install" | ||
entrypoint = build_dir / "entrypoint.py" | ||
|
||
build_dir.mkdir() | ||
install_dir.mkdir() | ||
|
||
requirements_file = build_dir / "requirements.txt" | ||
requirements_file.write_text("\n".join(requirements)) | ||
|
||
builder = charm_builder.CharmBuilder( | ||
builddir=build_dir, | ||
installdir=install_dir, | ||
entrypoint=entrypoint, | ||
requirements=[requirements_file], | ||
strict_dependencies=True | ||
) | ||
|
||
with pytest.raises(RuntimeError, match="failed with retcode 1") as exc_info: | ||
builder.handle_dependencies() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"requirements", | ||
[ | ||
["craft-platforms==0.1.0"], # No dependencies | ||
] | ||
) | ||
def test_install_strict_dependencies_pip_check_success( | ||
new_path: pathlib.Path, requirements: list[str] | ||
): | ||
build_dir = new_path / "build" | ||
install_dir = new_path / "install" | ||
entrypoint = build_dir / "entrypoint.py" | ||
|
||
build_dir.mkdir() | ||
install_dir.mkdir() | ||
|
||
requirements_file = build_dir / "requirements.txt" | ||
requirements_file.write_text("\n".join(requirements)) | ||
|
||
builder = charm_builder.CharmBuilder( | ||
builddir=build_dir, | ||
installdir=install_dir, | ||
entrypoint=entrypoint, | ||
requirements=[requirements_file], | ||
strict_dependencies=True | ||
) | ||
|
||
with pytest.raises(RuntimeError, match="failed with retcode 1") as exc_info: | ||
builder.handle_dependencies() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters