Skip to content

Commit

Permalink
Extract sorting logic to its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
elopez committed Dec 30, 2024
1 parent 9e7e375 commit 6ce0bf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions solc_select/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
halt_old_architecture,
upgrade_architecture,
)
from .utils import sort_versions


# pylint: disable=too-many-branches
Expand Down Expand Up @@ -54,9 +55,7 @@ def solc_select() -> None:
versions = args.get(INSTALL_VERSIONS)
if not versions:
print("Available versions to install:")
for version in sorted(
get_installable_versions(), key=lambda v: [int(s) for s in v.split(".")]
):
for version in sort_versions(get_installable_versions()):
print(version)
else:
install_artifacts(args.get(INSTALL_VERSIONS))
Expand All @@ -70,7 +69,7 @@ def solc_select() -> None:
res = current_version()
if res:
(current_ver, source) = res
for version in sorted(versions_installed, key=lambda v: [int(s) for s in v.split(".")]):
for version in sort_versions(versions_installed):
if res and version == current_ver:
print(f"{version} (current, set by {source})")
else:
Expand Down
6 changes: 6 additions & 0 deletions solc_select/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import platform
import subprocess
import sys
from typing import List


def mac_can_run_intel_binaries() -> bool:
Expand All @@ -13,3 +14,8 @@ def mac_can_run_intel_binaries() -> bool:

# Intel Mac
return True


def sort_versions(versions: List[str]) -> List[str]:
"""Sorts a list of versions following the component order (major/minor/patch)"""
return sorted(versions, key=lambda v: [int(s) for s in v.split(".")])

0 comments on commit 6ce0bf5

Please sign in to comment.