Skip to content

Commit 89ca48f

Browse files
Kasper JungeRalphify
authored andcommitted
refactor: flatten nested conditionals in _build_lockfile_from_results for clarity
Replace nested if/elif/else with flat early-continue branches so each case (local, freshly installed, carry-forward, error, minimal entry) is handled independently and reads top-to-bottom without tracking nesting. Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent 6c24eec commit 89ca48f

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

agr/commands/sync.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -772,19 +772,18 @@ def _build_lockfile_from_results(
772772
result = results[index]
773773
is_ralph = dep.is_ralph
774774

775+
# Local deps: record path only (no commit to pin).
775776
if dep.is_local:
776777
if result.status == SyncStatus.ERROR:
777778
continue
778779
handle = dep.to_parsed_handle(config.default_owner)
779780
lockfile.update_entry(
780-
LockedEntry(
781-
path=dep.path,
782-
installed_name=handle.name,
783-
),
781+
LockedEntry(path=dep.path, installed_name=handle.name),
784782
ralph=is_ralph,
785783
)
786784
continue
787785

786+
# Remote: freshly installed with commit — record new metadata.
788787
if result.status == SyncStatus.INSTALLED and result.commit:
789788
handle = dep.to_parsed_handle(config.default_owner)
790789
lockfile.update_entry(
@@ -797,25 +796,32 @@ def _build_lockfile_from_results(
797796
),
798797
ralph=is_ralph,
799798
)
800-
else:
801-
existing = (
802-
existing_lockfile.find_entry(dep)
803-
if existing_lockfile is not None
804-
else None
805-
)
806-
if existing is not None:
807-
lockfile.update_entry(existing, ralph=is_ralph)
808-
elif result.status == SyncStatus.ERROR:
809-
pass
810-
else:
811-
handle = dep.to_parsed_handle(config.default_owner)
812-
lockfile.update_entry(
813-
LockedEntry(
814-
handle=dep.handle,
815-
source=dep.resolve_source_name(config.default_source),
816-
installed_name=handle.name,
817-
),
818-
ralph=is_ralph,
819-
)
799+
continue
800+
801+
# Remote, not freshly installed: carry forward existing lockfile entry.
802+
existing = (
803+
existing_lockfile.find_entry(dep)
804+
if existing_lockfile is not None
805+
else None
806+
)
807+
if existing is not None:
808+
lockfile.update_entry(existing, ralph=is_ralph)
809+
continue
810+
811+
# No existing entry for a failed dep — nothing to record.
812+
if result.status == SyncStatus.ERROR:
813+
continue
814+
815+
# Up-to-date with no prior lockfile entry (e.g. first sync after
816+
# adding to agr.toml) — record a minimal entry without commit.
817+
handle = dep.to_parsed_handle(config.default_owner)
818+
lockfile.update_entry(
819+
LockedEntry(
820+
handle=dep.handle,
821+
source=dep.resolve_source_name(config.default_source),
822+
installed_name=handle.name,
823+
),
824+
ralph=is_ralph,
825+
)
820826

821827
return lockfile

0 commit comments

Comments
 (0)