diff --git a/soypak/deps/transaction.py b/soypak/deps/transaction.py new file mode 100644 index 0000000..6193b57 --- /dev/null +++ b/soypak/deps/transaction.py @@ -0,0 +1,53 @@ +import enum +import sys +import clog +import soypak.deps.bottler as bottler +import soypak.deps.operations as ops + + +_log = clog.Logger.get("runtime_logger") + + +class PkgGoal(enum.Enum): + PKG_INSTALL = 1 + + +class Transaction: + def __init__(self, goal: PkgGoal) -> None: + """Setup a new transaction.""" + if not isinstance(goal, PkgGoal): + _log.error(f"TypeError: {goal=}, expected PkgGoal.") + _log.printLog("There was an issue when operating on the transaction.", level=4) + sys.exit(1) + self.pkg_goal: PkgGoal = goal + + + def compute(self, pkgs: list[bottler._Soybottle]) -> tuple: + """Compute dependencies and conflicts of packages. Returns a list of total packages to install.""" + self._final_state = [] + sys_depends = [] + for pkg in pkgs: + ... + # :@TODO: compute the dependencies + + return tuple(sys_depends) + + + def apply(self): + if self.pkg_goal == PkgGoal.PKG_INSTALL: + ops.install_packages(self._final_state) + + + def problems(self) -> tuple: + """Provide a report of conflicts and packages which cannot be resolved (dependencies not installable).""" + return () + + + def commit(self): + """Commit the transaction to record for what happened.""" + pass + + + @property + def finalised(self): + return self._final_state