Skip to content

Commit

Permalink
feat: added package dependency search in index
Browse files Browse the repository at this point in the history
  • Loading branch information
RonTamG committed Jan 8, 2024
1 parent 78e70cc commit 4b16bff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,29 @@ def set_packages_apt_source(self, source):
for package_versions in self.packages.values():
for package in package_versions.values():
package.apt_source = source

def get_package_dependecies(self, name, packages=None):
current = self.search(name)

if current is None:
raise KeyError(name)

if packages is None:
packages = []

if current.priority in ["required", "important"]:
return None

if current in packages:
return None
else:
packages.append(current)

[
self.get_package_dependecies(dep, packages)
for dep in current.pre_dependencies
]

[self.get_package_dependecies(dep, packages) for dep in current.dependencies]

return packages
15 changes: 15 additions & 0 deletions tests/test_index.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ruff: noqa: E501

from pathlib import Path

from src.index import Index
from src.version import Version

Expand Down Expand Up @@ -126,6 +128,14 @@ def test_should_check_if_package_is_contained_in_list():
assert "ca-certificates" not in index


def test_should_get_package_dependencies():
index = valid_full_index_of_package()

packages = index.get_package_dependecies("python3")

assert len(packages) == 33


def valid_index_file():
return """Package: python3
Source: python3-defaults (3.11.4-5)
Expand Down Expand Up @@ -253,3 +263,8 @@ def valid_index_with_other_package():
Filename: ./ca-certificates_20230311_all.deb"""

return Index(data)


def valid_full_index_of_package():
data = Path("tests", "resources", "python_Packages").read_text()
return Index(data)

0 comments on commit 4b16bff

Please sign in to comment.