From 1c4f956eea98adb13350160662f5b41cf494dcad Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Fri, 23 Feb 2024 11:52:37 +0100 Subject: [PATCH] Remove unused extract_dep_graph --- docs/komodo.rst | 7 -- komodo/extract_dep_graph.py | 111 ------------------------ tests/test_extract_dep_graph.py | 146 -------------------------------- 3 files changed, 264 deletions(-) delete mode 100644 komodo/extract_dep_graph.py delete mode 100644 tests/test_extract_dep_graph.py diff --git a/docs/komodo.rst b/docs/komodo.rst index 56100eabb..9ec8d87fd 100644 --- a/docs/komodo.rst +++ b/docs/komodo.rst @@ -53,13 +53,6 @@ komodo.deployed module :undoc-members: :show-inheritance: -komodo.extract\_dep\_graph module ---------------------------------- - -.. automodule:: komodo.extract_dep_graph - :members: - :undoc-members: - :show-inheritance: komodo.fetch module ------------------- diff --git a/komodo/extract_dep_graph.py b/komodo/extract_dep_graph.py deleted file mode 100644 index 29befa2be..000000000 --- a/komodo/extract_dep_graph.py +++ /dev/null @@ -1,111 +0,0 @@ -import argparse -import os - -from ruamel.yaml import YAML - -from komodo.yaml_file_types import RepositoryFile - - -def run(pkgfile, base_pkgfile, repofile, outfile=None): - with open(pkgfile, encoding="utf-8") as package_file_stream, open( - base_pkgfile, encoding="utf-8" - ) as base_package_file_stream, open( - repofile, encoding="utf-8" - ) as repository_file_stream: - yaml = YAML() - pkgs, base_pkgs, repo = ( - yaml.load(package_file_stream), - yaml.load(base_package_file_stream), - yaml.load(repository_file_stream), - ) - - result = _iterate_packages(pkgs, base_pkgs, repo) - - if outfile: - with open(outfile, "w", encoding="utf-8") as out: - yaml.dump(result, out) - else: - print(yaml.dump(result)) - - -def _iterate_packages(pkgs, base_pkgs, repo): - dependencies = {} - for package, version in pkgs.items(): - _extract_dependencies(package, version, base_pkgs, repo, dependencies) - return dependencies - - -def _extract_dependencies(package, version, base_pkgs, repofile, dependencies): - if package not in repofile: - msg = f"'{package}' not found in 'repo'. This needs to be resolved." - raise SystemExit(msg) - if version not in repofile[package]: - available_versions = list(repofile[package].keys()) - msg = f"Version '{version}' for package '{package}' not found in 'repo'. Available version(s) is: {available_versions}." - raise SystemExit( - msg, - ) - if package not in dependencies: - dependencies[package] = version - - if "depends" in repofile[package][version]: - for dependency in repofile[package][version]["depends"]: - if dependency not in base_pkgs: - msg = f"'{dependency}' not found in 'base_pkgs'. This needs to be in place in order to pick correct version." - raise SystemExit( - msg, - ) - version = base_pkgs[dependency] - _extract_dependencies( - dependency, - version, - base_pkgs, - repofile, - dependencies, - ) - - return dependencies - - -def main(): - parser = argparse.ArgumentParser( - description=( - "Extracts dependencies from a given set of packages where " - "versions will be resolved from a complete release file. " - ), - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - ) - parser.add_argument( - "pkgs", - type=lambda arg: ( - arg if os.path.isfile(arg) else parser.error(f"{arg} is not a file") - ), - help="File with packages you want to resolve dependencies for.", - ) - parser.add_argument( - "base_pkgs", - type=lambda arg: ( - arg if os.path.isfile(arg) else parser.error(f"{arg} is not a file") - ), - help="Base file where all packages are listed with wanted versions specified.", - ) - parser.add_argument( - "repo", - type=RepositoryFile(), - help="Repository file with all packages listed with dependencies.", - ) - parser.add_argument( - "--out", - "-o", - help=( - "File to be written with resolved dependencies. " - "If not specified dump to stdout." - ), - ) - - args = parser.parse_args() - run(args.pkgs, args.base_pkgs, args.repo, args.out) - - -if __name__ == "__main__": - main() diff --git a/tests/test_extract_dep_graph.py b/tests/test_extract_dep_graph.py deleted file mode 100644 index 57b459bad..000000000 --- a/tests/test_extract_dep_graph.py +++ /dev/null @@ -1,146 +0,0 @@ -import pytest - -from komodo import extract_dep_graph - -REPO = { - "package_a": { - "1.2.3": { - "depends": ["package_b", "package_c", "package_e", "package_f"], - "maintainer": "a@b.c", - "make": "pip", - "source": "pypi", - }, - }, - "package_b": { - "2.3.4": {"maintainer": "a@b.c", "make": "pip", "source": "pypi"}, - "1.0.0": {"maintainer": "a@b.c", "make": "pip", "source": "pypi"}, - }, - "package_c": { - "0.0.1": { - "depends": ["package_d", "package_e"], - "maintainer": "a@b.c", - "make": "pip", - "source": "pypi", - }, - }, - "package_d": { - "10.2.1": { - "depends": ["package_e"], - "maintainer": "a@b.c", - "make": "pip", - "source": "pypi", - }, - }, - "package_e": {"4.1.2": {"maintainer": "a@b.c", "make": "pip", "source": "pypi"}}, - "package_f": { - "0.1.2": {"maintainer": "a@b.c", "make": "pip", "source": "pypi"}, - "1.0.2": {"maintainer": "a@b.c", "make": "pip", "source": "pypi"}, - }, -} - -BASE_RELEASE = { - "package_a": "1.2.3", - "package_b": "2.3.4", - "package_c": "0.0.1", - "package_d": "10.2.1", - "package_e": "4.1.2", - "package_f": "1.0.2", - "package_g": "0.5.3", - "package_h": "1.2.7", - "package_i": "1.2.14", - "package_j": "1.22.3", - "package_k": "6.2.3", - "package_l": "3.0.2", -} - -RELEASE = { - "package_a": "1.2.3", - "package_f": "1.0.2", -} - - -def test_extract_dep_graph(): - dependencies = extract_dep_graph._iterate_packages(RELEASE, BASE_RELEASE, REPO) - assert len(dependencies.keys()) == 6 - assert "package_a" in dependencies - assert "package_b" in dependencies - assert "package_c" in dependencies - assert "package_d" in dependencies - assert "package_e" in dependencies - assert "package_f" in dependencies - assert dependencies["package_a"] == "1.2.3" - assert dependencies["package_b"] == "2.3.4" - assert dependencies["package_c"] == "0.0.1" - assert dependencies["package_d"] == "10.2.1" - assert dependencies["package_e"] == "4.1.2" - assert dependencies["package_f"] == "1.0.2" - - -REPO_MISSING_PKG = { - "package_a": { - "1.2.3": { - "depends": ["package_b"], - "maintainer": "a@b.c", - "make": "pip", - "source": "pypi", - }, - }, -} - - -def test_extract_dep_graph_repo_missing_pkg(): - with pytest.raises(SystemExit) as exit_info: - extract_dep_graph._iterate_packages(RELEASE, BASE_RELEASE, REPO_MISSING_PKG) - assert "'package_b' not found in 'repo'. This needs to be resolved." in str( - exit_info.value, - ) - - -BASE_RELEASE_MISSINGS_PKGS = { - "package_a": "1.2.3", -} - - -def test_extract_dep_graph_base_file_missing_pkg(): - with pytest.raises(SystemExit) as exit_info: - extract_dep_graph._iterate_packages(RELEASE, BASE_RELEASE_MISSINGS_PKGS, REPO) - assert ( - "'package_b' not found in 'base_pkgs'. " - "This needs to be in place in order to pick correct version." - in str(exit_info.value) - ) - - -BASE_RELEASE_DEFINES_VERSION_NOT_EXISTING = { - "package_a": "1.2.3", - "package_b": "2.4.3", -} - - -def test_extract_dep_graph_base_file_faulty_version(): - with pytest.raises(SystemExit) as exit_info: - extract_dep_graph._iterate_packages( - RELEASE, - BASE_RELEASE_DEFINES_VERSION_NOT_EXISTING, - REPO, - ) - assert ( - "Version '2.4.3' for package 'package_b' not found in 'repo'. " - "Available version(s) is: ['2.3.4', '1.0.0']." in str(exit_info.value) - ) - - -RELEASE_DEFINES_VERSION_NOT_EXISTING = {"package_a": "11.2.3"} - - -def test_extract_dep_graph_pkgs_file_faulty_version(): - with pytest.raises(SystemExit) as exit_info: - extract_dep_graph._iterate_packages( - RELEASE_DEFINES_VERSION_NOT_EXISTING, - BASE_RELEASE, - REPO, - ) - assert ( - "Version '11.2.3' for package 'package_a' not found in 'repo'. " - "Available version(s) is: ['1.2.3']." in str(exit_info.value) - )