From d145146b46ded24548e884bf6543e261885886e9 Mon Sep 17 00:00:00 2001 From: Jonathan Karlsen Date: Tue, 16 Apr 2024 13:05:26 +0200 Subject: [PATCH] Remove unused komodo transpiler combine mode --- komodo/release_transpiler.py | 104 +------- tests/test_release_transpiler.py | 36 --- .../test_release_transpiler_argument_types.py | 248 ------------------ 3 files changed, 2 insertions(+), 386 deletions(-) diff --git a/komodo/release_transpiler.py b/komodo/release_transpiler.py index e0f9bb06e..0e4bc7f90 100755 --- a/komodo/release_transpiler.py +++ b/komodo/release_transpiler.py @@ -1,53 +1,15 @@ #!/usr/bin/env python import argparse -import itertools import os -from typing import Dict, List, Optional, Sequence, Union +from typing import Dict, Sequence, Union import yaml -from packaging import version as version_parser from komodo.matrix import format_release, get_matrix from komodo.prettier import load_yaml, write_to_file -def build_matrix_file( - release_base: str, - release_folder: str, - builtins: dict, - py_coords: Optional[Sequence[str]], -) -> None: - """Combine release files from the release_folder into one single matrix_file.""" - files: Dict[str, Dict] = {} - if py_coords is None: - py_keys = get_py_coords(release_base, release_folder) - else: - py_keys = [f"py{py_version.replace('.', '')}" for py_version in py_coords] - - for key in py_keys: - files[key] = load_yaml(f"{release_folder}/{release_base}-{key}.yml") - - all_packages = set( - itertools.chain.from_iterable( - release_file_content.keys() for release_file_content in files.values() - ), - ) - compiled = {} - - for package in all_packages: - if package in builtins: - compiled[package] = builtins[package] - continue - - if len({release_file.get(package) for release_file in files.values()}) == 1: - compiled[package] = next(iter(files.values()))[package] - else: - compiled[package] = {key: files[key].get(package) for key in py_keys} - - write_to_file(compiled, f"{release_base}.yml", False) - - def get_py_coords(release_base: str, release_folder: str) -> Sequence[str]: """Get python versions of release files inside a given release_folder.""" filenames_with_prefix = sorted( @@ -201,15 +163,6 @@ def transpile_releases_for_pip( filehandler.write("\n".join(pip_packages)) -def combine(args): - build_matrix_file( - args.release_base, - args.release_folder, - load_yaml(args.override_mapping), - args.py_coords, - ) - - def transpile(args): transpile_releases(args.matrix_file, args.output_folder, args.matrix_coordinates) @@ -231,65 +184,12 @@ def main(): subparsers = parser.add_subparsers( title="Commands", - description="Combine - build matrix file\nTranspile - generate release files", + description="Transpile - generate release files", help="Available sub commands", dest="mode", ) subparsers.required = True - matrix_parser = subparsers.add_parser( - "combine", - description=""" -Combine release files into a matrix file. Output format: - - example-package: - rhel7: - py36 : # package not included in release - py38 : 5.11.13 - rhel8: - py36 : # package not included in release - py38 : 5.11.13+builtin""", - formatter_class=argparse.RawTextHelpFormatter, - ) - matrix_parser.set_defaults(func=combine) - matrix_parser.add_argument( - "--release-base", - required=True, - help="Name of the release to handle (default: None)", - ) - matrix_parser.add_argument( - "--release-folder", - required=True, - type=dir_path, - help="Folder with existing release file (default: None)", - ) - matrix_parser.add_argument( - "--override-mapping", - required=True, - type=valid_file, - help="File containing explicit matrix packages (default: None)", - ) - - def comma_delimited_python_versions(python_versions: str) -> List[str]: - output_list: List[str] = [] - for python_version in python_versions.split(","): - parsed_python_version = version_parser.parse(python_version).base_version - if parsed_python_version >= "4.0.0": - raise version_parser.InvalidVersion(python_version) - output_list.append(parsed_python_version) - return output_list - - matrix_parser.add_argument( - "--py_coords", - help="""Comma delimited list of python versions to be combined, - for example, "3.6,3.8" (without spaces). - If None, the release files in release-folder will be used to imply - the versions to combine.""", - type=comma_delimited_python_versions, - required=False, - default=None, - ) - transpile_parser = subparsers.add_parser( "transpile", description="Transpile a matrix file into separate release files.", diff --git a/tests/test_release_transpiler.py b/tests/test_release_transpiler.py index 5d01f6270..183ba936a 100644 --- a/tests/test_release_transpiler.py +++ b/tests/test_release_transpiler.py @@ -1,10 +1,8 @@ import os import pytest -import yaml from komodo.release_transpiler import ( - build_matrix_file, get_py_coords, transpile_releases, transpile_releases_for_pip, @@ -23,40 +21,6 @@ } -@pytest.mark.parametrize( - ("py_coords_input", "packages_lib2", "py_coords_not_in_lib3"), - [ - (["3.6", "3.8"], "2.3.4", "py27"), - (None, {"py27": "1.2.3", "py36": "2.3.4", "py38": "2.3.4"}, [""]), - ], -) -def test_build_release_matrix_py_coords( - tmpdir, - py_coords_input, - packages_lib2, - py_coords_not_in_lib3, -): - """lib1 tests packages with builtins, - lib2 tests packages with same version for two py coordinates, - lib3 tests packages with different versions for each py coordinate. - """ - release_base = "2020.01.a1" - release_folder = os.path.join(_get_test_root(), "data/test_releases/") - with tmpdir.as_cwd(): - build_matrix_file(release_base, release_folder, builtins, py_coords_input) - new_release_file = f"{release_base}.yml" - assert os.path.isfile(new_release_file) - with open(new_release_file, encoding="utf-8") as new_release_file_stream: - release_matrix = yaml.safe_load(new_release_file_stream) - - assert release_matrix["lib1"] == builtins["lib1"] - assert release_matrix["lib2"] == packages_lib2 - assert all( - py_coordinate not in list(release_matrix["lib3"].keys()) - for py_coordinate in py_coords_not_in_lib3 - ) - - @pytest.mark.parametrize( "matrix", [({"py": ["3.8"], "rhel": ["7"]}), ({"py": ["3.8", "3.11"], "rhel": ["7", "8"]})], diff --git a/tests/test_release_transpiler_argument_types.py b/tests/test_release_transpiler_argument_types.py index 7e711758f..e9f312824 100644 --- a/tests/test_release_transpiler_argument_types.py +++ b/tests/test_release_transpiler_argument_types.py @@ -1,4 +1,3 @@ -import argparse import sys from contextlib import contextmanager from os.path import abspath, dirname @@ -24,253 +23,6 @@ def does_not_raise(): yield -@pytest.mark.parametrize( - ("args", "expectation"), - [ - ( - [ - "--py_coords", - "3.8,3.6", - ], - does_not_raise(), - ), - ( - [], - does_not_raise(), - ), - ( - [ - "--py_coords", - "py3.8", - ], - pytest.raises(SystemExit), - ), - ( - [ - "--py_coords", - "test", - ], - pytest.raises(SystemExit), - ), - ( - [ - "--py_coords", - "'3.8, 3.6'", - ], - pytest.raises(SystemExit), - ), - ( - [ - "--py_coords", - "4.2", - ], - pytest.raises(SystemExit), - ), - ( - [ - "--py_coords", - "true", - ], - pytest.raises(SystemExit), - ), - ], -) -def test_combine_py_coords_type(args: List[str], expectation, monkeypatch): - monkeypatch.setattr( - sys, - "argv", - [ - "", - "combine", - "--release-folder", - VALID_RELEASE_FOLDER, - "--release-base", - VALID_RELEASE_BASE, - "--override-mapping", - VALID_OVERRIDE_MAPPING_FILE, - *args, - ], - ) - with expectation: - release_transpiler_main() - - -@pytest.mark.parametrize( - ("args", "expectation"), - [ - ( - [ - "--release-folder", - VALID_RELEASE_FOLDER, - "--py_coords", - "3.8,3.6", - ], - does_not_raise(), - ), - ( - [ - "--release-folder", - VALID_RELEASE_FOLDER, - ], - does_not_raise(), - ), - ( - [ - "--release-folder", - "FOLDER/DOES/NOT/EXIST", - ], - pytest.raises(NotADirectoryError), - ), - ( - [ - "--release-folder", - "true", - ], - pytest.raises(NotADirectoryError), - ), - ( - [ - "--release-folder", - "null", - ], - pytest.raises(NotADirectoryError), - ), - ( - [ - "--release-folder", - "random", - "--override-mapping", - VALID_OVERRIDE_MAPPING_FILE, - ], - pytest.raises(NotADirectoryError), - ), - ], -) -def test_combine_py_release_folder_type(args: List[str], expectation, monkeypatch): - monkeypatch.setattr( - sys, - "argv", - [ - "", - "combine", - "--release-base", - VALID_RELEASE_BASE, - "--override-mapping", - VALID_OVERRIDE_MAPPING_FILE, - *args, - ], - ) - with expectation: - release_transpiler_main() - - -@pytest.mark.parametrize( - ("args", "expectation"), - [ - ( - [ - "--override-mapping", - VALID_OVERRIDE_MAPPING_FILE, - "--py_coords", - "3.8,3.6", - ], - does_not_raise(), - ), - ( - [ - "--override-mapping", - VALID_OVERRIDE_MAPPING_FILE, - ], - does_not_raise(), - ), - ( - [ - "--override-mapping", - "FAKE/PATH/mapping.yml", - ], - pytest.raises(FileNotFoundError), - ), - ( - [ - "--override-mapping", - "fake_mapping.yml", - ], - pytest.raises(FileNotFoundError), - ), - ( - [ - "--override-mapping", - "random", - ], - pytest.raises(FileNotFoundError), - ), - ( - [ - "--override-mapping", - "0", - ], - pytest.raises(FileNotFoundError), - ), - ], -) -def test_combine_py_override_mapping_type(args: List[str], expectation, monkeypatch): - monkeypatch.setattr( - sys, - "argv", - [ - "", - "combine", - "--release-base", - VALID_RELEASE_BASE, - "--release-folder", - VALID_RELEASE_FOLDER, - *args, - ], - ) - - with expectation: - release_transpiler_main() - - -@pytest.mark.parametrize( - ("args", "expectation"), - [ - ( - [ - "--release-base", - VALID_RELEASE_BASE, - ], - does_not_raise(), - ), - ( - [ - "--release-base", - "INVALID_RELEASE_BASE", - ], - pytest.raises(argparse.ArgumentTypeError), - ), - ], -) -def test_combine_py_release_base_type(args: List[str], expectation, monkeypatch): - monkeypatch.setattr( - sys, - "argv", - [ - "", - "combine", - "--release-folder", - VALID_RELEASE_FOLDER, - "--override-mapping", - VALID_OVERRIDE_MAPPING_FILE, - "--py_coords", - "3.8,3.6", - *args, - ], - ) - with expectation: - release_transpiler_main() - - @pytest.mark.parametrize( ("args", "expectation"), [