chore: exclude packages sections using tools/packages.py (#1499)

* feat: exclude packages sections using tools/packages.py

* chore: group apache deps packages in a section

This allow one to exlude the entire section and install nginx for example.
This commit is contained in:
Jonas L 2022-01-10 07:23:37 +01:00 committed by GitHub
parent 1b601e2ac1
commit 19986cf1b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View File

@ -1,14 +1,18 @@
# This file contains a list of package dependencies.
[common]
apache2 = buster, bullseye, bionic, focal
# The php-pear package depends on php-(cli|common|xml), be sure to
# install the dependencies with the right php version.
php-pear = buster, bullseye, bionic, focal
php-amqplib = buster, bullseye, bionic, focal
[apache]
apache2 = buster, bullseye, bionic, focal
libapache2-mod-php7.2 = bionic
libapache2-mod-php7.3 = buster
libapache2-mod-php7.4 = bullseye, focal
# Bionic
[php7.2]
libapache2-mod-php7.2 = bionic
php7.2 = bionic
php7.2-apcu = bionic
# Bionic does not have php7.2-apcu-bc, use php-apcu-bc instead
@ -25,7 +29,6 @@ php7.2-xml = bionic
# Buster
[php7.3]
libapache2-mod-php7.3 = buster
php7.3 = buster
php7.3-apcu = buster
php7.3-apcu-bc = buster
@ -41,7 +44,6 @@ php7.3-xml = buster
# Bullseye, Focal
[php7.4]
libapache2-mod-php7.4 = bullseye, focal
php7.4 = bullseye, focal
php7.4-apcu = bullseye, focal
php7.4-apcu-bc = bullseye, focal

View File

@ -4,7 +4,7 @@ from argparse import ArgumentParser
from configparser import ConfigParser
from os import PathLike
from pathlib import Path
from typing import Iterator, List, Set
from typing import Iterator, List, Optional, Set
DEFAULT_PACKAGES_FILENAME = "packages.ini"
FORMATS = ("list", "line")
@ -18,6 +18,7 @@ def load_packages(
raw: str,
distribution: str,
development: bool = False,
exclude: Optional[List[str]] = None,
) -> Set[str]:
if distribution not in DISTRIBUTIONS:
raise ValueError(f"Invalid distribution '{distribution}'")
@ -26,8 +27,9 @@ def load_packages(
manager.read_string(raw)
packages = set()
exclude = set(exclude or [])
for section, entries in manager.items():
if not development and section == DEVELOPMENT_SECTION:
if not development and section == DEVELOPMENT_SECTION or section in exclude:
continue
for package, distributions in entries.items():
@ -56,11 +58,12 @@ def list_packages(
paths: List[PathLike],
distribution: str,
development: bool = False,
exclude: Optional[List[str]] = None,
) -> Set[str]:
packages = set()
for package_file in list_packages_files(paths):
raw = package_file.read_text()
packages.update(load_packages(raw, distribution, development))
packages.update(load_packages(raw, distribution, development, exclude))
return set(sorted(packages))
@ -80,6 +83,12 @@ def run():
help="include development packages.",
action="store_true",
)
parser.add_argument(
"-e",
"--exclude",
nargs="+",
help="exclude packages sections.",
)
parser.add_argument(
"distribution",
choices=DISTRIBUTIONS,
@ -92,7 +101,7 @@ def run():
)
args = parser.parse_args()
packages = list_packages(args.path, args.distribution, args.dev)
packages = list_packages(args.path, args.distribution, args.dev, args.exclude)
if args.format == "list":
print("\n".join(packages))

View File

@ -18,12 +18,14 @@ ffmpeg = buster, bionic, focal
result_buster = {"curl", "postgresql"}
result_bionic = {"apache2", "curl", "ffmpeg"}
result_focal = {"postgresql", "apache2", "ffmpeg"}
result_exclude = {"postgresql", "ffmpeg"}
def test_load_packages():
assert load_packages(PACKAGE_INI, "buster", False) == result_buster
assert load_packages(PACKAGE_INI, "bionic", True) == result_bionic
assert load_packages(PACKAGE_INI, "focal", True) == result_focal
assert load_packages(PACKAGE_INI, "focal", True, ["legacy"]) == result_exclude
def test_list_packages(tmp_path: Path):