Skip to content

Commit

Permalink
Refactor mirror.install -> mirror.install_command.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoodsend committed Oct 19, 2023
1 parent 2bfda18 commit 462d2fa
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions polycotylus/_alpine.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def tag(_, cls):
def _package_manager_queries(cls):
with cls.mirror:
container = _docker.run(cls.base_image, f"""
{cls.mirror.install}
{cls.mirror.install_command}
apk update
apk search -q > /packages
apk info -q > /base-packages
Expand Down Expand Up @@ -175,7 +175,7 @@ def dockerfile(self):
return self._formatter(f"""
FROM {self.base_image} AS base
RUN {self.mirror.install}
RUN {self.mirror.install_command}
RUN echo -e {repr(public.read_text("utf8"))} > "/etc/apk/keys/{public.name}"
RUN apk add shadow sudo
Expand Down Expand Up @@ -226,7 +226,7 @@ def abuild_keys(self):

with self.mirror:
container = _docker.run(self.base_image, f"""
{self.mirror.install}
{self.mirror.install_command}
apk add -q abuild
echo 'PACKAGER="{self.project.maintainer_slug}"' >> /etc/abuild.conf
echo 'MAINTAINER="$PACKAGER"' >> /etc/abuild.conf
Expand Down
4 changes: 2 additions & 2 deletions polycotylus/_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Arch(BaseDistribution):
def _package_manager_queries(cls):
with cls.mirror:
container = _docker.run(cls.base_image, f"""
{cls.mirror.install}
{cls.mirror.install_command}
pacman -Sy
pacman -Ssq > /packages
pacman -Qq > /base-packages
Expand Down Expand Up @@ -144,7 +144,7 @@ def dockerfile(self):
return self._formatter(f"""
FROM {self.base_image} AS base
RUN {self.mirror.install}
RUN {self.mirror.install_command}
RUN pacman -Syu --noconfirm --needed sudo
{self._install_user()}
RUN mkdir /io && chown user /io
Expand Down
4 changes: 2 additions & 2 deletions polycotylus/_debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def distro_root(self):
def _package_manager_queries(cls):
with cls.mirror:
container = _docker.run(cls.base_image, f"""
{cls.mirror.install}
{cls.mirror.install_command}
apt-get update
apt list -qq > /available
apt list --installed -qq > /installed
Expand Down Expand Up @@ -148,7 +148,7 @@ def inject_source(self):
def dockerfile(self):
return self._formatter(f"""
FROM {self.base_image} AS build
RUN {self.mirror.install}
RUN {self.mirror.install_command}
ENV LANG=C.UTF-8 LC_ALL=C LANGUAGE=C DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends sudo
Expand Down
16 changes: 8 additions & 8 deletions polycotylus/_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CachedMirror:
"""

def __init__(self, base_url, base_dir, index_patterns, ignore_patterns,
port, install, last_sync_time, package_version_pattern="(.+)()()",
port, install_command, last_sync_time, package_version_pattern="(.+)()()",
handler=None):
"""
Args:
Expand All @@ -43,7 +43,7 @@ def __init__(self, base_url, base_dir, index_patterns, ignore_patterns,
404 errors. This can usually be left empty.
port:
An integer port number. Any number not already used will do.
install:
install_command:
A shell command which replaces the distribution's list of
mirrors with this mirror.
last_sync_time:
Expand All @@ -65,8 +65,8 @@ def __init__(self, base_url, base_dir, index_patterns, ignore_patterns,
if platform.system() in ("Darwin", "Windows"): # pragma: no cover
# Docker's --network=host option doesn't work on macOS or Windows.
# https://github.com/docker/for-mac/issues/1031
install = install.replace("localhost", "host.docker.internal")
self.install = install
install_command = install_command.replace("localhost", "host.docker.internal")
self.install_command = install_command
self._lock = threading.Lock()
self._listeners = 0
self.last_sync_time = last_sync_time
Expand All @@ -79,7 +79,7 @@ def with_(self, **kwargs):
base_url=self.base_url, base_dir=self.base_dir,
index_patterns=self.index_patterns,
ignore_patterns=self.ignore_patterns, port=self.port,
install=self.install, last_sync_time=self.last_sync_time,
install_command=self.install_command, last_sync_time=self.last_sync_time,
package_version_pattern=self.package_version_pattern,
handler=self.handler,
)
Expand All @@ -103,7 +103,7 @@ def serve(self):
"""Enable this mirror and block until killed (via Ctrl+C)."""
with self:
print(f"http://localhost:{self.port}", "=>", self.base_url)
print(f"Install via:\n{self.install}")
print(f"Install via:\n{self.install_command}")
self.verbose = True
with contextlib.suppress(KeyboardInterrupt):
while True:
Expand Down Expand Up @@ -452,7 +452,7 @@ def upstream_url(self):
base_url=_manjaro_preferred_mirror,
base_dir=cache_root / "manjaro",
port=8903,
install="if grep -q /arm-stable/ /etc/pacman.d/mirrorlist ; then echo 'Server = http://localhost:8903/arm-stable/$repo/$arch' > /etc/pacman.d/mirrorlist; else echo 'Server = http://localhost:8903/stable/$repo/$arch' > /etc/pacman.d/mirrorlist; fi; sed -i 's/#Color/Color/' /etc/pacman.conf",
install_command="if grep -q /arm-stable/ /etc/pacman.d/mirrorlist ; then echo 'Server = http://localhost:8903/arm-stable/$repo/$arch' > /etc/pacman.d/mirrorlist; else echo 'Server = http://localhost:8903/stable/$repo/$arch' > /etc/pacman.d/mirrorlist; fi; sed -i 's/#Color/Color/' /etc/pacman.conf",
)
mirrors["opensuse"] = CachedMirror(
"http://download.opensuse.org",
Expand All @@ -478,7 +478,7 @@ def upstream_url(self):
base_url="http://archive.ubuntu.com/ubuntu/",
base_dir=cache_root / "ubuntu2304",
port=8906,
install=r"sed -i -E 's|http://(.*).ubuntu.com/|http://localhost:8906/\1/|g' /etc/apt/sources.list",
install_command=r"sed -i -E 's|http://(.*).ubuntu.com/|http://localhost:8906/\1/|g' /etc/apt/sources.list",
handler=UbuntuRequestHandler,
)
mirrors["ubuntu2310"] = mirrors["ubuntu2304"].with_(
Expand Down
4 changes: 2 additions & 2 deletions polycotylus/_opensuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, project, architecture=None):
def _package_manager_queries(cls):
with cls.mirror:
container = _docker.run(cls.base_image, f"""
{cls.mirror.install}
{cls.mirror.install_command}
zypper refresh
zypper search > /packages
zypper info --requires osc > /osc-info
Expand Down Expand Up @@ -287,7 +287,7 @@ def dockerfile(self):

out = self._formatter(f"""
FROM {self.base_image} as base
RUN {self.mirror.install}
RUN {self.mirror.install_command}
RUN mkdir /io
WORKDIR /io
Expand Down
4 changes: 2 additions & 2 deletions polycotylus/_void.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def build_test_image(self):
def _package_manager_queries(cls):
with cls.mirror:
container = _docker.run(cls.base_image, f"""
{cls.mirror.install}
{cls.mirror.install_command}
xbps-install -ySu xbps
xbps-query -Rs '' > /all
xbps-query -Rx base-chroot > /base
Expand Down Expand Up @@ -100,7 +100,7 @@ def dockerfile(self):
return self._formatter(f"""
ARG tag
FROM ghcr.io/void-linux/void-linux:${{tag}} AS base
RUN {self.mirror.install}
RUN {self.mirror.install_command}
RUN rm -f /etc/xbps.d/noextract.conf
RUN xbps-install -ySu xbps bash shadow sudo
CMD ["/bin/bash"]
Expand Down
2 changes: 1 addition & 1 deletion tests/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_python_extras(self, monkeypatch):
for (packages, imports) in _group_python_extras(self.cls.python_extras):
mirror = self.cls.mirror
script = self.cls._formatter(f"""
{mirror.install}
{mirror.install_command}
{self.package_install} python3 {shlex.join(packages)}
python3 -c 'import {", ".join(imports)}'
""")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_alpine.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_abuild_lint():
self.generate()
with self.mirror:
_docker.run(Alpine.base_image, f"""
{self.mirror.install}
{self.mirror.install_command}
apk add -q atools
apkbuild-lint /io/APKBUILD
""", volumes=[(self.distro_root, "/io")], architecture=self.docker_architecture)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_manjaro.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_mirror_detection(monkeypatch):
with Manjaro.mirror:
for architecture in ["x86_64", "aarch64"]:
_docker.run("manjarolinux/base", f"""
{Manjaro.mirror.install}
{Manjaro.mirror.install_command}
pacman -Sy
""", architecture=architecture, tty=True)
assert requests, "Mirror is being ignored"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _alpine_mirror(tmp_path):
_alpine.index_patterns,
["*.penguin"],
9989,
_alpine.install.replace("8901", "9989"),
_alpine.install_command.replace("8901", "9989"),
(_alpine_sync_time,),
)

Expand Down Expand Up @@ -254,7 +254,7 @@ def test_tar_integrity(tmp_path):

for i in range(3):
with self:
_docker.run("alpine", f"{self.install} && apk add libbz2")
_docker.run("alpine", f"{self.install_command} && apk add libbz2")


@pytest.mark.filterwarnings("ignore", category=pytest.PytestUnhandledThreadExceptionWarning)
Expand Down

0 comments on commit 462d2fa

Please sign in to comment.