Skip to content
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

Legacy _deb: Add option to specify packages to unmark #4026

Merged
merged 3 commits into from
Mar 1, 2023
Merged
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
3 changes: 3 additions & 0 deletions snapcraft_legacy/internal/repo/_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ def fetch_stage_packages(
base: str,
stage_packages_path: pathlib.Path,
target_arch: str,
packages_filters: Set[str] = set(),
) -> List[str]:
logger.debug(f"Requested stage-packages: {sorted(package_names)!r}")

Expand All @@ -486,6 +487,8 @@ def fetch_stage_packages(
base=base, package_list=package_list
)

filtered_names.update(packages_filters)

stage_packages_path.mkdir(exist_ok=True)
with AptCache(
stage_cache=_STAGE_CACHE_DIR, stage_cache_arch=target_arch
Expand Down
41 changes: 41 additions & 0 deletions tests/legacy/unit/repo/test_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,47 @@ def test_fetch_stage_package_with_deps(self):
Equals(sorted(["fake-package=1.0", "fake-package-dep=2.0"])),
)

@mock.patch(
"snapcraft_legacy.internal.repo._deb._DEFAULT_FILTERED_STAGE_PACKAGES", {}
)
def test_fetch_stage_package_with_deps_with_package_filters(self):
fake_package = self.debs_path / "fake-package_1.0_all.deb"
fake_package.touch()
fake_package_dep = self.debs_path / "fake-package-dep_2.0_all.deb"
fake_package_dep.touch()
other_fake_package = self.debs_path / "other-fake-package_1.0_all.deb"
other_fake_package.touch()
self.fake_apt_cache.return_value.__enter__.return_value.fetch_archives.return_value = [
("fake-package", "1.0", fake_package)
]

package_names = ["fake-package", "other-fake-package"]

fetched_packages = repo.Ubuntu.fetch_stage_packages(
package_names=package_names,
stage_packages_path=self.stage_packages_path,
base="core18",
target_arch="amd64",
packages_filters={"fake-package-dep", "other-fake-package"},
)

self.fake_apt_cache.assert_has_calls(
[
call(stage_cache=self.stage_cache_path, stage_cache_arch="amd64"),
call().__enter__(),
call().__enter__().mark_packages(set(package_names)),
call()
.__enter__()
.unmark_packages({"fake-package-dep", "other-fake-package"}),
call().__enter__().fetch_archives(self.debs_path),
]
)

self.assertThat(
fetched_packages,
Equals(sorted(["fake-package=1.0"])),
)

def test_get_package_fetch_error(self):
self.fake_apt_cache.return_value.__enter__.return_value.fetch_archives.side_effect = errors.PackageFetchError(
"foo"
Expand Down