Skip to content

Commit

Permalink
Rename some variables to make code easier to understand
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Oct 25, 2023
1 parent 30343c3 commit 1f4e08e
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions nix_alien/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,42 @@ def find_libs(
if not dep.soname or dep.found:
continue

candidates = find_lib_candidates(dep.soname)
selected_candidate = None
dep_candidates = find_lib_candidates(dep.soname)
selected_dep = None

if len(candidates) == 0:
if len(dep_candidates) == 0:
_print(f"No candidate found for '{dep.soname}'", file=sys.stderr)
elif len(candidates) == 1:
selected_candidate = candidates[0]
elif len(dep_candidates) == 1:
selected_dep = dep_candidates[0]
else:
if select_candidates:
# Prioritise user selected candidates
maybe_selected_candidates = (
c for c in candidates if re.search(select_candidates, c)
selected_dep = next(
(c for c in dep_candidates if re.search(select_candidates, c)), None
)
selected_candidate = next(maybe_selected_candidates, None)

# Try to find an dependency that is already solved
if not selected_candidate:
intersection = (d for d in resolved_deps.values() if d in candidates)
selected_candidate = next(intersection, None)
if not selected_dep:
selected_dep = next(
(d for d in resolved_deps.values() if d in dep_candidates), None
)

# Show FZF to allow user to select the best dependency
if not selected_candidate:
if not selected_dep:
fzf_options = join(
[
"--cycle",
"--prompt",
f"Select candidate for '{dep.soname}'> ",
]
)
selected_candidate = fzf.prompt(candidates, fzf_options)[0]
selected_dep = fzf.prompt(dep_candidates, fzf_options)[0]

_print(
f"Selected candidate for '{dep.soname}': {selected_candidate}",
f"Selected candidate for '{dep.soname}': {selected_dep}",
file=sys.stderr,
)
resolved_deps[dep.soname] = selected_candidate
resolved_deps[dep.soname] = selected_dep

return resolved_deps

Expand Down

0 comments on commit 1f4e08e

Please sign in to comment.