47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
"""
|
|
AutoDev - Dependency Tracker
|
|
Tracks and records all external dependencies.
|
|
"""
|
|
|
|
import os
|
|
from . import config
|
|
|
|
|
|
class DependencyTracker:
|
|
def __init__(self, workdir: str):
|
|
self.path = os.path.join(workdir, config.DEPENDENCY_FILE)
|
|
self.deps: set[str] = set()
|
|
self._load()
|
|
|
|
def _load(self):
|
|
if os.path.exists(self.path):
|
|
with open(self.path, "r") as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if line and not line.startswith("#"):
|
|
self.deps.add(line)
|
|
|
|
def _save(self):
|
|
with open(self.path, "w") as f:
|
|
f.write("# AutoDev - Project Dependencies\n")
|
|
f.write("# Auto-generated, do not edit manually\n\n")
|
|
for d in sorted(self.deps):
|
|
f.write(d + "\n")
|
|
|
|
def add(self, dep: str):
|
|
if dep not in self.deps:
|
|
self.deps.add(dep)
|
|
self._save()
|
|
|
|
def add_many(self, deps: list[str]):
|
|
changed = False
|
|
for d in deps:
|
|
if d not in self.deps:
|
|
self.deps.add(d)
|
|
changed = True
|
|
if changed:
|
|
self._save()
|
|
|
|
def get_all(self) -> list[str]:
|
|
return sorted(self.deps)
|