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

View File

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

View File

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