From 1e3a6e6e3bdfe4dabca4a8ebb8c1ca6bbd703831 Mon Sep 17 00:00:00 2001 From: Samuel Sloniker Date: Mon, 1 Jul 2024 10:29:53 -0700 Subject: [PATCH] Remove unnecessary functions and rename `unpack` --- unpack.py => circuitpack.py | 39 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 26 deletions(-) rename unpack.py => circuitpack.py (94%) diff --git a/unpack.py b/circuitpack.py similarity index 94% rename from unpack.py rename to circuitpack.py index 39f4bfd..f2c610e 100644 --- a/unpack.py +++ b/circuitpack.py @@ -207,28 +207,7 @@ def _vacuum(root: str, delete_this: bool = False) -> None: pass -def vacuum(target: str, paths: Iterable[str] = ("lib",)) -> None: - """ - Remove empty directories under `paths`, each relative to `target`. - """ - - for path in paths: - _vacuum(f"{target}/{path}") - - -def parse_spec(spec_text: str) -> dict[str, tuple[str, str]]: - spec = {} - - for full_line in spec_text.split("\n"): - line = full_line.strip() - if line: - name, version_hash, repo = line.split(",") - spec[name] = (version_hash, repo) - - return spec - - -def get_status(records: str) -> dict[str, str]: +def _get_status(records: str) -> dict[str, str]: status = {} for name in os.listdir(records): @@ -241,15 +220,23 @@ def get_status(records: str) -> dict[str, str]: def install_spec( spec_text: str, target: str, records: str, paths: Iterable[str] = ("lib",) ) -> None: - spec = parse_spec(spec_text) - status = get_status(records) + spec = {} + + for full_line in spec_text.split("\n"): + line = full_line.strip() + if line: + name, version_hash, repo = line.split(",") + spec[name] = (version_hash, repo) + + status = _get_status(records) for name, version in status.items(): if not name in spec or spec[name][0] != version: uninstall(name, target, records) - vacuum(target, paths) - status = get_status(records) + for path in paths: + _vacuum(f"{target}/{path}") + status = _get_status(records) for name, version_repo in spec.items(): version, repo = version_repo